Skip to content

Commit 794591b

Browse files
authored
[Closes #34] Add Posthog cookieless analytics (#53)
* [Closes #34] Add Posthog cookieless analytics * Revert server modification for posthog- unnecessary
1 parent f72026b commit 794591b

5 files changed

Lines changed: 139 additions & 1053 deletions

File tree

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"i18next-http-backend": "^3.0.2",
2828
"inflection": "^3.0.2",
2929
"luxon": "^3.7.2",
30+
"posthog-js": "^1.270.1",
3031
"prop-types": "^15.8.1",
3132
"react": "^19.1.1",
3233
"react-dom": "^19.1.1",

client/src/StaticContext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const defaultValue = {
99
env: {
1010
VITE_SITE_TITLE: import.meta.env.VITE_SITE_TITLE,
1111
VITE_FEATURE_REGISTRATION: import.meta.env.VITE_FEATURE_REGISTRATION,
12+
VITE_PUBLIC_POSTHOG_KEY: import.meta.env.VITE_PUBLIC_POSTHOG_KEY,
13+
VITE_PUBLIC_POSTHOG_HOST: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
1214
},
1315
};
1416

client/src/entry-client.jsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@ import React from 'react';
22
import { createRoot, hydrateRoot } from 'react-dom/client';
33
import { BrowserRouter } from 'react-router';
44
import { createHead, UnheadProvider } from '@unhead/react/client';
5+
import { PostHogProvider } from 'posthog-js/react';
56

67
import App from './App';
78
import { defaultValue } from './StaticContext';
89
import StaticContextProvider from './StaticContextProvider';
910

11+
const staticContext = { ...defaultValue, ...window.STATIC_CONTEXT };
12+
13+
const posthogOptions = {
14+
cookieless_mode: 'always',
15+
api_host: staticContext.env.VITE_PUBLIC_POSTHOG_HOST,
16+
defaults: '2025-05-24',
17+
};
18+
1019
const head = createHead();
1120

1221
const container = document.getElementById('root');
1322
const app = (
14-
<StaticContextProvider value={{ ...defaultValue, ...window.STATIC_CONTEXT }}>
23+
<StaticContextProvider value={staticContext}>
1524
<UnheadProvider head={head}>
16-
<BrowserRouter>
17-
<App />
18-
</BrowserRouter>
25+
<PostHogProvider apiKey={staticContext.env.VITE_PUBLIC_POSTHOG_KEY} options={posthogOptions}>
26+
<BrowserRouter>
27+
<App />
28+
</BrowserRouter>
29+
</PostHogProvider>
1930
</UnheadProvider>
2031
</StaticContextProvider>
2132
);

0 commit comments

Comments
 (0)