docs: setup PostHog (#13659)
This commit is contained in:
@@ -22,4 +22,6 @@ NEXT_PUBLIC_API_V1_URL=
|
||||
ALGOLIA_WRITE_API_KEY=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -19,6 +19,8 @@ const Providers = ({ children }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<PageLoadingProvider>
|
||||
|
||||
@@ -24,4 +24,6 @@ CLOUDINARY_CLOUD_NAME=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_MCP_SERVER_URL=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -26,6 +26,8 @@ const Providers = ({ children, aiAssistantProps = {} }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<LearningPathProvider>
|
||||
|
||||
@@ -21,4 +21,6 @@ ALGOLIA_WRITE_API_KEY=
|
||||
CLOUDINARY_CLOUD_NAME=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -27,6 +27,8 @@ const Providers = ({ children }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<MobileProvider>
|
||||
|
||||
@@ -25,4 +25,6 @@ NEXT_PUBLIC_AI_API_ASSISTANT_RECAPTCHA_SITE_KEY=
|
||||
CLOUDINARY_CLOUD_NAME=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -24,6 +24,8 @@ const Providers = ({ children }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<LearningPathProvider
|
||||
|
||||
@@ -21,4 +21,6 @@ ALGOLIA_WRITE_API_KEY=
|
||||
CLOUDINARY_CLOUD_NAME=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -28,6 +28,8 @@ const Providers = ({ children }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<MobileProvider>
|
||||
|
||||
@@ -21,4 +21,6 @@ ALGOLIA_WRITE_API_KEY=
|
||||
CLOUDINARY_CLOUD_NAME=
|
||||
NEXT_PUBLIC_GA_ID=
|
||||
NEXT_PUBLIC_INTEGRATION_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_REO_DEV_CLIENT_ID=
|
||||
NEXT_PUBLIC_POSTHOG_KEY=
|
||||
NEXT_PUBLIC_POSTHOG_HOST=
|
||||
@@ -27,6 +27,8 @@ const Providers = ({ children }: ProvidersProps) => {
|
||||
<AnalyticsProvider
|
||||
segmentWriteKey={process.env.NEXT_PUBLIC_SEGMENT_API_KEY}
|
||||
reoDevKey={process.env.NEXT_PUBLIC_REO_DEV_CLIENT_ID}
|
||||
postHogKey={process.env.NEXT_PUBLIC_POSTHOG_KEY}
|
||||
postHogApiHost={process.env.NEXT_PUBLIC_POSTHOG_HOST}
|
||||
>
|
||||
<SiteConfigProvider config={config}>
|
||||
<MobileProvider>
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"mermaid": "^10.9.0",
|
||||
"minisearch": "^7.1.1",
|
||||
"npm-to-yarn": "^2.1.0",
|
||||
"posthog-js": "^1.269.0",
|
||||
"prism-react-renderer": "2.4.0",
|
||||
"react": "rc",
|
||||
"react-dom": "rc",
|
||||
|
||||
@@ -8,6 +8,9 @@ import React, {
|
||||
useState,
|
||||
} from "react"
|
||||
import { Analytics, AnalyticsBrowser } from "@segment/analytics-next"
|
||||
import { PostHogProvider as PHProvider } from "posthog-js/react"
|
||||
import posthog from "posthog-js"
|
||||
|
||||
// @ts-expect-error Doesn't have a types package
|
||||
import { loadReoScript } from "reodotdev"
|
||||
|
||||
@@ -36,6 +39,8 @@ const AnalyticsContext = createContext<AnalyticsContextType | null>(null)
|
||||
export type AnalyticsProviderProps = {
|
||||
segmentWriteKey?: string
|
||||
reoDevKey?: string
|
||||
postHogKey?: string
|
||||
postHogApiHost?: string
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
@@ -45,6 +50,8 @@ export const AnalyticsProvider = ({
|
||||
segmentWriteKey = "temp",
|
||||
reoDevKey,
|
||||
children,
|
||||
postHogKey,
|
||||
postHogApiHost = "https://eu.i.posthog.com",
|
||||
}: AnalyticsProviderProps) => {
|
||||
// loaded is used to ensure that a connection has been made to segment
|
||||
// even if it failed. This is to ensure that the connection isn't
|
||||
@@ -113,8 +120,21 @@ export const AnalyticsProvider = ({
|
||||
[analytics, loaded]
|
||||
)
|
||||
|
||||
const initPostHog = useCallback(() => {
|
||||
if (!postHogKey) {
|
||||
return
|
||||
}
|
||||
|
||||
posthog.init(postHogKey, {
|
||||
api_host: postHogApiHost,
|
||||
person_profiles: "always",
|
||||
defaults: "2025-05-24",
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
initSegment()
|
||||
initPostHog()
|
||||
}, [initSegment])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -153,7 +173,11 @@ export const AnalyticsProvider = ({
|
||||
loaded,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
{postHogKey ? (
|
||||
<PHProvider client={posthog}>{children}</PHProvider>
|
||||
) : (
|
||||
children
|
||||
)}
|
||||
</AnalyticsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1667,6 +1667,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@posthog/core@npm:1.2.2":
|
||||
version: 1.2.2
|
||||
resolution: "@posthog/core@npm:1.2.2"
|
||||
checksum: 723dbb93605625ed0122569c929efe4d5c571b8c5c61d6a9e6768cc5ebca05887e39f48a9697d6c212b209215a504c48fc56dfa401576fbe3cd8828c5f440f2d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@radix-ui/number@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@radix-ui/number@npm:1.1.0"
|
||||
@@ -6361,6 +6368,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"core-js@npm:^3.38.1":
|
||||
version: 3.45.1
|
||||
resolution: "core-js@npm:3.45.1"
|
||||
checksum: c38e5fae5a05ee3a129c45e10056aafe61dbb15fd35d27e0c289f5490387541c89741185e0aeb61acb558559c6697e016c245cca738fa169a73f2b06cd30e6b6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cose-base@npm:^1.0.0":
|
||||
version: 1.0.3
|
||||
resolution: "cose-base@npm:1.0.3"
|
||||
@@ -7161,6 +7175,7 @@ __metadata:
|
||||
minisearch: ^7.1.1
|
||||
next: 15.3.5
|
||||
npm-to-yarn: ^2.1.0
|
||||
posthog-js: ^1.269.0
|
||||
prism-react-renderer: 2.4.0
|
||||
react: rc
|
||||
react-dom: rc
|
||||
@@ -8547,6 +8562,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"fflate@npm:^0.4.8":
|
||||
version: 0.4.8
|
||||
resolution: "fflate@npm:0.4.8"
|
||||
checksum: 29d1eddaaa5deab61b1c6b0d21282adacadbc4d2c01e94d8b1ee784398151673b9c563e53f97a801bc410a1ae55e8de5378114a743430e643e7a0644ba8e5a42
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"file-entry-cache@npm:^8.0.0":
|
||||
version: 8.0.0
|
||||
resolution: "file-entry-cache@npm:8.0.0"
|
||||
@@ -12406,6 +12428,27 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"posthog-js@npm:^1.269.0":
|
||||
version: 1.269.0
|
||||
resolution: "posthog-js@npm:1.269.0"
|
||||
dependencies:
|
||||
"@posthog/core": 1.2.2
|
||||
core-js: ^3.38.1
|
||||
fflate: ^0.4.8
|
||||
preact: ^10.19.3
|
||||
web-vitals: ^4.2.4
|
||||
peerDependencies:
|
||||
"@rrweb/types": 2.0.0-alpha.17
|
||||
rrweb-snapshot: 2.0.0-alpha.17
|
||||
peerDependenciesMeta:
|
||||
"@rrweb/types":
|
||||
optional: true
|
||||
rrweb-snapshot:
|
||||
optional: true
|
||||
checksum: e29de2d4e33b643bc7dc57902d45294879915129bf5eba97e9486a4094cbaf0fbfc3d1ed55959434d0ffc94b55a640020d8ef786cddb6d48dc9c608667cd1ac4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"preact@npm:^10.10.0":
|
||||
version: 10.19.6
|
||||
resolution: "preact@npm:10.19.6"
|
||||
@@ -12413,6 +12456,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"preact@npm:^10.19.3":
|
||||
version: 10.27.2
|
||||
resolution: "preact@npm:10.27.2"
|
||||
checksum: 951b708f7afa34391e054b0f1026430e8f5f6d5de24020beef70288e17067e473b9ee5503a994e0a80ced014826f56708fea5902f80346432c22dfcf3dff4be7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prelude-ls@npm:^1.2.1":
|
||||
version: 1.2.1
|
||||
resolution: "prelude-ls@npm:1.2.1"
|
||||
@@ -15566,6 +15616,13 @@ turbo@latest:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"web-vitals@npm:^4.2.4":
|
||||
version: 4.2.4
|
||||
resolution: "web-vitals@npm:4.2.4"
|
||||
checksum: 383c9281d5b556bcd190fde3c823aeb005bb8cf82e62c75b47beb411014a4ed13fa5c5e0489ed0f1b8d501cd66b0bebcb8624c1a75750bd5df13e2a3b1b2d194
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"web-worker@npm:^1.2.0":
|
||||
version: 1.3.0
|
||||
resolution: "web-worker@npm:1.3.0"
|
||||
|
||||
Reference in New Issue
Block a user