Skip to content

Commit

Permalink
feat(tracking): add PostHog (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybacon authored Sep 29, 2024
1 parent fdd6094 commit 3e447e7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"mdast-util-find-and-replace": "3.0.1",
"next": "14.2.13",
"plaiceholder": "3.0.0",
"posthog-js": "1.165.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-intersection-observer": "9.13.1",
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { CssBaseline } from '@mui/material';
import { Analytics } from '@vercel/analytics/react';
import { type AppProps } from 'next/app';
import Head from 'next/head';
import postHog from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';

import { ThemeProvider } from '@/theme/ThemeContext';

export default function Application(props: AppProps) {
const { Component, pageProps } = props;
if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_POSTHOG_KEY) {
postHog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'always',
});
}

export default function Application({ Component, pageProps }: AppProps) {
return (
<>
<Head>
Expand All @@ -18,8 +26,9 @@ export default function Application(props: AppProps) {
</Head>
<ThemeProvider>
<CssBaseline />
{/* TODO Provide decklists and menu through a shared context */}
<Component {...pageProps} />
<PostHogProvider client={postHog}>
<Component {...pageProps} />
</PostHogProvider>
</ThemeProvider>
{process.env.NODE_ENV === 'production' && <Analytics />}
</>
Expand Down

0 comments on commit 3e447e7

Please sign in to comment.