diff --git a/packages/components/src/analytics/PosthogClient.ts b/packages/components/src/analytics/PosthogClient.ts new file mode 100644 index 000000000..e883d19dc --- /dev/null +++ b/packages/components/src/analytics/PosthogClient.ts @@ -0,0 +1,50 @@ + +import posthog from 'posthog-js' + +/** + * Since Posthog costs a lot of money, we'll use this interface to mediate when to + * turn on Posthog calls. + */ +export class PosthogClient { + + private static POSTHOG_ENABLED : boolean = false; + + public static enablePosthog() { + if (PosthogClient.isEnabled()) { + return; + } + PosthogClient.POSTHOG_ENABLED = true; + posthog.init('phc_x6IRdmevMt4XAoJqx9tCmwDiaQkEkD48c0aLmuXMOvu', { + api_host: 'https://app.posthog.com' + }) + } + + public static isEnabled() : boolean { + return PosthogClient.POSTHOG_ENABLED; + } + + public static setUsername(username: string) { + if (PosthogClient.isEnabled()) { + posthog.identify(username, {}); + } + } + + // Disassociate any identity (eg. on logout) + public static reset() { + if (PosthogClient.isEnabled()) { + posthog.reset(); + } + } + + public static recordPageview() { + if (PosthogClient.isEnabled()) { + posthog.capture('$pageview'); + } + } + + public static recordAction(actionName: string) { + if (PosthogClient.isEnabled()) { + posthog.capture(actionName); + } + } +} diff --git a/packages/fakeyou.com/public/index.html b/packages/fakeyou.com/public/index.html index dab783eb7..357a0b2f2 100644 --- a/packages/fakeyou.com/public/index.html +++ b/packages/fakeyou.com/public/index.html @@ -81,20 +81,6 @@ - - @@ -117,12 +103,6 @@ rel="stylesheet" /> - - -