Skip to content

Commit 4451770

Browse files
committed
Adding a PostHog Provider
1 parent 1d9311b commit 4451770

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use client";
2+
3+
import { useEffect } from "react";
4+
import posthog from "posthog-js";
5+
import { PostHogProvider as PHProvider } from "posthog-js/react";
6+
7+
import { env } from "~/env";
8+
9+
export function PostHogProvider({ children }: { children: React.ReactNode }) {
10+
useEffect(() => {
11+
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
12+
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
13+
person_profiles: "identified_only", // or 'always' to create profiles for anonymous users as well
14+
defaults: "2025-05-24",
15+
});
16+
}, []);
17+
18+
return <PHProvider client={posthog}>{children}</PHProvider>;
19+
}

src/app/layout.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import "~/styles/globals.css";
2-
31
import { ClerkProvider } from "@clerk/nextjs";
42
import { type Metadata } from "next";
53
import { Geist } from "next/font/google";
64

5+
import { PostHogProvider } from "./_providers/posthog-provider";
6+
7+
import "~/styles/globals.css";
8+
79
export const metadata: Metadata = {
810
title: "Drive Tutorial",
911
description: "It's like Google Drive, but worse!",
@@ -20,9 +22,11 @@ export default function RootLayout({
2022
}: Readonly<{ children: React.ReactNode }>) {
2123
return (
2224
<ClerkProvider>
23-
<html lang="en" className={`${geist.variable}`}>
24-
<body>{children}</body>
25-
</html>
25+
<PostHogProvider>
26+
<html lang="en" className={`${geist.variable}`}>
27+
<body>{children}</body>
28+
</html>
29+
</PostHogProvider>
2630
</ClerkProvider>
2731
);
2832
}

0 commit comments

Comments
 (0)