-
Notifications
You must be signed in to change notification settings - Fork 814
Add Tracking + Consent Manager for Docs #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const { NODE_ENV = 'development' } = process.env | ||
|
|
||
| // eslint-disable-next-line import/prefer-default-export | ||
| export const onRouteUpdate = () => { | ||
| if (!window.analytics || typeof window.analytics.page !== 'function') { | ||
| if (NODE_ENV === 'development') { | ||
| console.warn('Unable to locate analytics.js') | ||
| } | ||
| return | ||
| } | ||
|
|
||
| window.analytics.page() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,50 @@ | ||
| /* eslint-disable react/no-danger */ | ||
| const React = require('react') | ||
| const { min: createSnippet } = require('@segment/snippet') | ||
| const { extractStyles } = require('../esm') | ||
| const segmentWriteKey = require('./segmentWriteKey') | ||
|
|
||
| const getSnippet = ({ writeKey }) => { | ||
| // In development, stub out all analytics.js methods | ||
| // this prevents "dirtying" your real analytics with local testing/traffic | ||
| const { NODE_ENV = 'development' } = process.env | ||
| if (NODE_ENV === 'development') { | ||
| return ` | ||
| (function () { | ||
| // analytics.js stub | ||
| const analytics = window.analytics = {} | ||
| const methods = [ | ||
| 'trackSubmit', 'trackClick', 'trackLink', 'trackForm', 'pageview', | ||
| 'identify', 'reset', 'group', 'track', 'ready', 'alias', 'debug', | ||
| 'page', 'once', 'off', 'on', 'load' | ||
| ] | ||
| methods.forEach(method => | ||
| analytics[method] = (...args) => console.log(\`analytics.\${method}\`, ...args) | ||
| ) | ||
| })() | ||
| ` | ||
| } | ||
|
|
||
| return createSnippet({ apiKey: writeKey, page: false }) | ||
| } | ||
|
|
||
| exports.onRenderBody = ({ setHeadComponents }) => { | ||
| // Get the css and hydration script from Evergreen. | ||
| const { css, hydrationScript } = extractStyles() | ||
|
|
||
| const snippet = getSnippet({ writeKey: segmentWriteKey }) | ||
|
|
||
| // Takes an array of components as its first argument which are added to | ||
| // the headComponents array which is passed to the html.js component. | ||
| setHeadComponents([ | ||
| // We need a key here for Gatsby to stop complaining. | ||
| <React.Fragment key="evergreen-ssr"> | ||
| <style id="evergreen-css" dangerouslySetInnerHTML={{ __html: css }} /> | ||
| {hydrationScript} | ||
| </React.Fragment> | ||
| </React.Fragment>, | ||
| <script | ||
| key="segment-snippet" | ||
| dangerouslySetInnerHTML={{ __html: snippet }} | ||
| /> | ||
| ]) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export default 'kfSgLPyTrQI1Ys3hW4Sm3B25NHs4UHZX' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React from 'react' | ||
| import { ConsentManager, openConsentManager } from '@segment/consent-manager' | ||
| import inEU from '@segment/in-eu' | ||
| import segmentWriteKey from '../../segmentWriteKey' | ||
|
|
||
| export default () => { | ||
| const bannerContent = ( | ||
| <span> | ||
| We use cookies (and other similar technologies) to collect data to improve | ||
| your experience on our site. By using our website, you’re agreeing to the | ||
| collection of data as described in our{' '} | ||
| <a | ||
| href="https://segment.com/docs/legal/website-data-collection-policy/" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| Website Data Collection Policy | ||
| </a>. | ||
| </span> | ||
| ) | ||
| const bannerSubContent = 'You can change your preferences at any time.' | ||
| const preferencesDialogTitle = 'Website Data Collection Preferences' | ||
| const preferencesDialogContent = | ||
| 'We use data collected by cookies and JavaScript libraries to improve your browsing experience, analyze site traffic, deliver personalized advertisements, and increase the overall performance of our site.' | ||
| const cancelDialogTitle = 'Are you sure you want to cancel?' | ||
| const cancelDialogContent = | ||
| 'Your preferences have not been saved. By continuing to use our website, you՚re agreeing to our Website Data Collection Policy.' | ||
|
|
||
| return ( | ||
| <div> | ||
| <ConsentManager | ||
| writeKey={segmentWriteKey} | ||
| shouldRequireConsent={inEU} | ||
| bannerContent={bannerContent} | ||
| bannerSubContent={bannerSubContent} | ||
| preferencesDialogTitle={preferencesDialogTitle} | ||
| preferencesDialogContent={preferencesDialogContent} | ||
| cancelDialogTitle={cancelDialogTitle} | ||
| cancelDialogContent={cancelDialogContent} | ||
| /> | ||
|
|
||
| <button type="button" onClick={openConsentManager}> | ||
| Website Data Collection Preferences | ||
| </button> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ body { | |
| } | ||
|
|
||
| .MainLayout { | ||
| height: 100vh; | ||
| min-height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| .Overview { | ||
| =margin: 0 auto 160px; | ||
| margin: 0 auto 160px; | ||
| min-height: 100vh; | ||
|
|
||
| & header { | ||
| margin-top: 40px; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need
dangerouslySetInnerHTML, this should work: