Skip to content

Commit

Permalink
hasUserGivenAnyCookieConsent and isUserOptedOutOfAnalytics are only a…
Browse files Browse the repository at this point in the history
…vailable on the browser, so we use DisplayOnBrowserMount component to defer the mount for the browser only (avoid mismatch browser vs server)
  • Loading branch information
Vadorequest committed Jul 27, 2020
1 parent 1ca3a37 commit 37e3f5c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/pages/[locale]/examples/built-in-features/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Alert, Button } from 'reactstrap';
import BuiltInFeaturesSidebar from '../../../../components/doc/BuiltInFeaturesSidebar';
import DocPage from '../../../../components/doc/DocPage';
import DefaultLayout from '../../../../components/pageLayouts/DefaultLayout';
import DisplayOnBrowserMount from '../../../../components/rehydration/DisplayOnBrowserMount';
import Code from '../../../../components/utils/Code';
import ExternalLink from '../../../../components/utils/ExternalLink';
import useUserConsent from '../../../../hooks/useUserConsent';
Expand Down Expand Up @@ -206,19 +207,21 @@ const ExampleAnalyticsPage: NextPage<Props> = (props): JSX.Element => {
Below is how we log events upon user interaction. (i.e: click)<br />
When you click on the below button an event <code>analytics-button-test-event</code> is sent to Amplitude.<br />
No data will be sent if you've opted-out of analytics tracking:
<b>
{
!hasUserGivenAnyCookieConsent ? `You haven't made any choice regarding your consent yet, and thus an event will be sent (because you're opt-in by default)` : (isUserOptedOutOfAnalytics ? `You've chosen to opt-out from analytics tracking, and thus no event will be sent` : `You've chosen to opt-in to analytics tracking, and thus an event will be sent`)
}
</b><br />
<DisplayOnBrowserMount>
<br />
<b>
{
!hasUserGivenAnyCookieConsent ? `You haven't made any choice regarding your consent yet, and thus an event will be sent (because you're opt-in by default).` : (isUserOptedOutOfAnalytics ? `You've chosen to opt-out from analytics tracking, and thus no event will be sent.` : `You've chosen to opt-in to analytics tracking, and thus an event will be sent.`)
}
</b>
</DisplayOnBrowserMount>
<br />
<br />
You can check the event details using <ExternalLink href={'https://chrome.google.com/webstore/detail/amplitude-instrumentation/acehfjhnmhbmgkedjmjlobpgdicnhkbp'}>Amplitude Instrumentation Explorer</ExternalLink> Chrome extension.
</p>

<Button
onClick={(): void => logEvent('analytics-button-test-event', {
file: fileLabel,
})}
onClick={(): void => logEvent('analytics-button-test-event')}
>
Click me
</Button>
Expand All @@ -230,9 +233,7 @@ const ExampleAnalyticsPage: NextPage<Props> = (props): JSX.Element => {
<Amplitude>
{({ logEvent }): JSX.Element => (
<Button
onClick={(): void => logEvent('analytics-button-test-event', {
file: fileLabel,
})}
onClick={(): void => logEvent('analytics-button-test-event')}
>
Click me
</Button>
Expand Down

1 comment on commit 37e3f5c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.