Skip to content

Commit

Permalink
FET-1721: Implement posthog (hosted)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Lysak committed Dec 13, 2024
1 parent d385c3a commit 82b9cea
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"markdown-to-jsx": "^7.1.7",
"next": "13.5.6",
"node-fetch": "^3.3.2",
"posthog-js": "^1.199.0",
"react": "*",
"react-confetti": "^6.1.0",
"react-dom": "*",
Expand Down
136 changes: 125 additions & 11 deletions pnpm-lock.yaml

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

15 changes: 15 additions & 0 deletions src/components/posthog/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/naming-convention */

import { PostHogConfig } from 'posthog-js'

export const posthogConfig: {
apiKey: string
options: Partial<PostHogConfig>
} = {
apiKey: process.env.NEXT_PUBLIC_POSTHOG_KEY!,
options: {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
autocapture: true,
},
}
13 changes: 13 additions & 0 deletions src/components/posthog/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use client'

import { PostHogProvider } from 'posthog-js/react'

import { posthogConfig } from './config'

export function Posthog({ children }: React.PropsWithChildren) {
return (
<PostHogProvider apiKey={posthogConfig.apiKey} options={posthogConfig.options}>
{children}
</PostHogProvider>
)
}
5 changes: 4 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createGlobalStyle, keyframes, ThemeProvider } from 'styled-components'
import { ThorinGlobalStyles, lightTheme as thorinLightTheme } from '@ensdomains/thorin'

import { Notifications } from '@app/components/Notifications'
import { Posthog } from '@app/components/posthog'
import { TestnetWarning } from '@app/components/TestnetWarning'
import { TransactionStoreProvider } from '@app/hooks/transactions/TransactionStoreContext'
import { Basic } from '@app/layouts/Basic'
Expand Down Expand Up @@ -157,7 +158,9 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
<SyncDroppedTransaction>
<Notifications />
<TestnetWarning />
<Basic>{getLayout(<Component {...pageProps} />)}</Basic>
<Posthog>
<Basic>{getLayout(<Component {...pageProps} />)}</Basic>
</Posthog>
</SyncDroppedTransaction>
</TransactionFlowProvider>
</SyncProvider>
Expand Down

0 comments on commit 82b9cea

Please sign in to comment.