-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from janbaykara/feature/analytics
Add Posthog analytics and cookie banner
- Loading branch information
Showing
9 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,87 @@ | ||
import posthog from 'posthog-js' | ||
import "vanilla-cookieconsent/dist/cookieconsent.css"; | ||
import * as CookieConsent from "vanilla-cookieconsent"; | ||
import { useEffect } from 'react'; | ||
|
||
export async function enablePosthog() { | ||
if (!process.env.REACT_APP_POSTHOG_API_KEY || !process.env.REACT_APP_POSTHOG_API_URL) { | ||
return | ||
} | ||
posthog.init(process.env.REACT_APP_POSTHOG_API_KEY!, { | ||
api_host: process.env.REACT_APP_POSTHOG_API_URL | ||
}) | ||
posthog.opt_in_capturing() | ||
} | ||
|
||
export async function disablePosthog() { | ||
posthog.opt_out_capturing() | ||
} | ||
|
||
export function showPrivacyPreferences () { | ||
CookieConsent.show(); | ||
} | ||
|
||
export function captureAnalyticsEvent (event: string, properties: any) { | ||
posthog.capture(event, properties) | ||
} | ||
|
||
export function captureAnalyticsPageView (page: string) { | ||
posthog.capture('change tab', { page }) | ||
} | ||
|
||
export function useAnalytics () { | ||
useEffect(() => { | ||
CookieConsent.run({ | ||
revision: 1, | ||
categories: { | ||
analytics: { | ||
enabled: true, | ||
readOnly: false, | ||
services: { | ||
posthog: { | ||
label: 'PostHog', | ||
onAccept: () => { | ||
enablePosthog() | ||
}, | ||
onReject: () => { | ||
disablePosthog() | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
language: { | ||
default: 'en', | ||
translations: { | ||
en: { | ||
consentModal: { | ||
title: 'Can we use cookies to track usage?', | ||
description: "You'll help us learn how to improve the tool for others", | ||
acceptAllBtn: 'Accept', | ||
acceptNecessaryBtn: 'Reject', | ||
showPreferencesBtn: 'Manage privacy preferences' | ||
}, | ||
preferencesModal: { | ||
title: 'Manage privacy preferences', | ||
acceptAllBtn: 'Accept', | ||
acceptNecessaryBtn: 'Reject', | ||
savePreferencesBtn: 'Save preferences', | ||
closeIconLabel: 'Close', | ||
sections: [ | ||
{ | ||
title: 'Usage analytics', | ||
description: 'Tracks how the tool is used to help us improve it', | ||
linkedCategory: 'analytics' | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}, []); | ||
} | ||
|
||
// TODO: | ||
// - enable PII filter | ||
// - show cookies CookieConsent.show(); |
This file contains 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 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 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 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 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 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