From e90daad63602eaefec7d90a4b42815209b1201dc Mon Sep 17 00:00:00 2001 From: Saidev Dhal Date: Wed, 13 Nov 2024 19:24:53 +0530 Subject: [PATCH] add posthog analytics --- apps/app/app/layout.tsx | 3 +++ apps/app/hooks/posthog.tsx | 17 +++++++++++++++++ apps/www/app/layout.tsx | 3 +++ apps/www/hooks/posthog.tsx | 17 +++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 apps/app/hooks/posthog.tsx create mode 100644 apps/www/hooks/posthog.tsx diff --git a/apps/app/app/layout.tsx b/apps/app/app/layout.tsx index 3bbcb42..67ddbd4 100644 --- a/apps/app/app/layout.tsx +++ b/apps/app/app/layout.tsx @@ -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", @@ -23,6 +24,7 @@ async function RootLayout({ return ( + @@ -42,6 +44,7 @@ async function RootLayout({ + ); } diff --git a/apps/app/hooks/posthog.tsx b/apps/app/hooks/posthog.tsx new file mode 100644 index 0000000..2728dfe --- /dev/null +++ b/apps/app/hooks/posthog.tsx @@ -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 {children} +} \ No newline at end of file diff --git a/apps/www/app/layout.tsx b/apps/www/app/layout.tsx index c72ae79..b4eafda 100644 --- a/apps/www/app/layout.tsx +++ b/apps/www/app/layout.tsx @@ -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", @@ -15,6 +16,7 @@ export default function RootLayout({ }>) { return ( + @@ -29,6 +31,7 @@ export default function RootLayout({ + ); } diff --git a/apps/www/hooks/posthog.tsx b/apps/www/hooks/posthog.tsx new file mode 100644 index 0000000..2728dfe --- /dev/null +++ b/apps/www/hooks/posthog.tsx @@ -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 {children} +} \ No newline at end of file diff --git a/package.json b/package.json index 4d250af..0dcef2b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 511d750..5034855 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: postcss: specifier: ^8 version: 8.4.47 + posthog-js: + specifier: ^1.184.1 + version: 1.184.1 supertest: specifier: ^7.0.0 version: 7.0.0 @@ -3595,6 +3598,9 @@ packages: core-js-pure@3.39.0: resolution: {integrity: sha512-7fEcWwKI4rJinnK+wLTezeg2smbFFdSBP6E2kQZNbnzM2s1rpKQ6aaRteZSSg7FLU3P0HGGVo/gbpfanU36urg==} + core-js@3.39.0: + resolution: {integrity: sha512-raM0ew0/jJUqkJ0E6e8UDtl+y/7ktFivgWvqw8dNSQeNWoSDLvQ1H/RN3aPXB9tBd4/FhyR4RDPGhsNIMsAn7g==} + core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -4240,6 +4246,9 @@ packages: picomatch: optional: true + fflate@0.4.8: + resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==} + figures@3.2.0: resolution: {integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==} engines: {node: '>=8'} @@ -5622,6 +5631,9 @@ packages: resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==} engines: {node: ^10 || ^12 || >=14} + posthog-js@1.184.1: + resolution: {integrity: sha512-q/1Kdard5SZnL2smrzeKcD+RuUi2PnbidiN4D3ThK20bNrhy5Z2heIy9SnRMvEiARY5lcQ7zxmDCAKPBKGSOtQ==} + preact-render-to-string@5.2.3: resolution: {integrity: sha512-aPDxUn5o3GhWdtJtW0svRC2SS/l8D9MAgo2+AWml+BhDImb27ALf04Q2d+AHqUUOc6RdSXFIBVa2gxzgMKgtZA==} peerDependencies: @@ -5630,6 +5642,9 @@ packages: preact@10.11.3: resolution: {integrity: sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==} + preact@10.24.3: + resolution: {integrity: sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA==} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -6762,6 +6777,9 @@ packages: wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} + web-vitals@4.2.4: + resolution: {integrity: sha512-r4DIlprAGwJ7YM11VZp4R884m0Vmgr6EAKe3P+kO0PPj3Unqyvv59rczf6UiGcb9Z8QxZVcqKNwv/g0WNdWwsw==} + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} @@ -10073,6 +10091,8 @@ snapshots: core-js-pure@3.39.0: {} + core-js@3.39.0: {} + core-util-is@1.0.3: {} cors@2.8.5: @@ -10972,6 +10992,8 @@ snapshots: optionalDependencies: picomatch: 4.0.2 + fflate@0.4.8: {} + figures@3.2.0: dependencies: escape-string-regexp: 1.0.5 @@ -12627,6 +12649,13 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 + posthog-js@1.184.1: + dependencies: + core-js: 3.39.0 + fflate: 0.4.8 + preact: 10.24.3 + web-vitals: 4.2.4 + preact-render-to-string@5.2.3(preact@10.11.3): dependencies: preact: 10.11.3 @@ -12634,6 +12663,8 @@ snapshots: preact@10.11.3: {} + preact@10.24.3: {} + prelude-ls@1.2.1: {} prettier-plugin-packagejson@2.5.3(prettier@3.3.3): @@ -13986,6 +14017,8 @@ snapshots: dependencies: defaults: 1.0.4 + web-vitals@4.2.4: {} + webidl-conversions@3.0.1: {} whatwg-url@5.0.0: