From be05d4fe7f7bc8edc2aad18daecdb8e67f28b29f Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Tue, 6 Aug 2024 12:55:43 -0700 Subject: posthog --- apps/web/app/layout.tsx | 23 +++++++++++++---------- apps/web/app/providers.js | 14 ++++++++++++++ apps/web/cf-env.d.ts | 2 ++ apps/web/package.json | 1 + apps/web/tsconfig.json | 3 ++- 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 apps/web/app/providers.js (limited to 'apps/web') diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 94a538ed..b3a0b485 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -6,6 +6,7 @@ import { GeistSans } from "geist/font/sans"; import { GeistMono } from "geist/font/mono"; import { cn } from "@repo/ui/lib/utils"; import { Toaster } from "@repo/ui/shadcn/toaster"; +import { CSPostHogProvider } from "./providers"; const inter = Inter({ subsets: ["latin"] }); @@ -75,16 +76,18 @@ export default function RootLayout({ > {/* TODO: when lightmode support is added, remove the 'dark' class from the body tag */} - - {children} - - + + + {children} + + + ); } diff --git a/apps/web/app/providers.js b/apps/web/app/providers.js new file mode 100644 index 00000000..3715157f --- /dev/null +++ b/apps/web/app/providers.js @@ -0,0 +1,14 @@ +"use client"; +import posthog from "posthog-js"; +import { PostHogProvider } from "posthog-js/react"; + +if (typeof window !== "undefined") { + posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { + api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, + person_profiles: "identified_only", + }); +} + +const CSPostHogProvider = ({ children }) => { + return {children}; +}; diff --git a/apps/web/cf-env.d.ts b/apps/web/cf-env.d.ts index 09b0690b..10891f9b 100644 --- a/apps/web/cf-env.d.ts +++ b/apps/web/cf-env.d.ts @@ -26,6 +26,8 @@ declare global { RATELIMITER: { limit: ({ key: string }) => { success: boolean }; }; + NEXT_PUBLIC_POSTHOG_KEY: string; + NEXT_PUBLIC_POSTHOG_HOST: string; } } } diff --git a/apps/web/package.json b/apps/web/package.json index d3bf1f48..4c0d57cd 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -30,6 +30,7 @@ "next": "^14.1.1", "novel": "^0.4.2", "nuqs": "^1.17.4", + "posthog-js": "^1.154.5", "react": "^18.2.0", "react-dom": "^18.2.0", "react-resizable-panels": "^2.0.19", diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 7072be89..ac67adbb 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -19,7 +19,8 @@ ".next/types/**/*.ts", "../../packages/ui/", "../../packages/shared-types", - "./components" + "./components", + "app/providers.js" ], "exclude": ["node_modules/"] } -- cgit v1.2.3