Skip to content

Commit

Permalink
add posthog analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
SkidGod4444 committed Nov 13, 2024
1 parent 4abf68a commit e90daad
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AppSidebar } from "@/components/custom/sidebar/sidebar";
import { cookies } from "next/headers";
import Infobar from "@/components/custom/infobar/infobar";
import ProgressBar from "@/components/custom/progress.bar";
import { PosthogProvider } from "@/hooks/posthog";

export const metadata: Metadata = {
title: "Plura",
Expand All @@ -23,6 +24,7 @@ async function RootLayout({

return (
<html lang="en" suppressHydrationWarning>
<PosthogProvider>
<body
className={`min-h-screen bg-background font-sans ${GeistSans.variable} antialiased`}
>
Expand All @@ -42,6 +44,7 @@ async function RootLayout({
</SidebarProvider>
</ThemeProvider>
</body>
</PosthogProvider>
</html>
);
}
Expand Down
17 changes: 17 additions & 0 deletions apps/app/hooks/posthog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'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', // or 'always' to create profiles for anonymous users as well
})
}
export function PosthogProvider({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
}
3 changes: 3 additions & 0 deletions apps/www/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { GeistSans } from "geist/font/sans";
import "./globals.css";
import { ThemeProvider } from "@/hooks/theme-provider";
import { PosthogProvider } from "@/hooks/posthog";

export const metadata: Metadata = {
title: "Plura",
Expand All @@ -15,6 +16,7 @@ export default function RootLayout({
}>) {
return (
<html lang="en" suppressHydrationWarning>
<PosthogProvider>
<body
className={` bg-background font-sans min-h-screen ${GeistSans.variable} antialiased`}
>
Expand All @@ -29,6 +31,7 @@ export default function RootLayout({
</div>
</ThemeProvider>
</body>
</PosthogProvider>
</html>
);
}
17 changes: 17 additions & 0 deletions apps/www/hooks/posthog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'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', // or 'always' to create profiles for anonymous users as well
})
}
export function PosthogProvider({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"next": "15.0.2",
"next-auth": "5.0.0-beta.25",
"postcss": "^8",
"posthog-js": "^1.184.1",
"supertest": "^7.0.0",
"tailwindcss": "^3.4.1",
"typescript": "^5",
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit e90daad

Please sign in to comment.