Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
📈 Enable page view analytics (#1434)
Luke Vella4f98661a12de
diff --git a/apps/web/src/app/posthog-page-view.tsx b/apps/web/src/app/posthog-page-view.tsxnew file mode 100644index 000000000..40d9614be--- /dev/null+++ b/apps/web/src/app/posthog-page-view.tsx@@ -0,0 +1,24 @@+"use client";+import { usePathname, useSearchParams } from "next/navigation";+import { usePostHog } from "posthog-js/react";+import { useEffect } from "react";++export function PostHogPageView() {+ const pathname = usePathname();+ const searchParams = useSearchParams();+ const posthog = usePostHog();+ useEffect(() => {+ // Track pageviews+ if (pathname && posthog) {+ let url = window.origin + pathname;+ if (searchParams?.toString()) {+ url = url + `?${searchParams.toString()}`;+ }+ posthog.capture("$pageview", {+ $current_url: url,+ });+ }+ }, [pathname, searchParams, posthog]);++ return null;+}diff --git a/apps/web/src/app/providers.tsx b/apps/web/src/app/providers.tsxindex 6c5fb3fea..8f99b054c 100644--- a/apps/web/src/app/providers.tsx+++ b/apps/web/src/app/providers.tsx@@ -12,6 +12,8 @@ import { trpcConfig } from "@/trpc/client/config";import type { AppRouter } from "@/trpc/routers";import { ConnectedDayjsProvider } from "@/utils/dayjs";+import { PostHogPageView } from "./posthog-page-view";+export const trpc = createTRPCReact<AppRouter>({unstable_overrides: {useMutation: {@@ -33,6 +35,7 @@ export function Providers(props: { children: React.ReactNode }) {<I18nProvider><TooltipProvider><PostHogProvider>+ <PostHogPageView /><UserProvider><ConnectedDayjsProvider>{props.children}diff --git a/packages/posthog/package.json b/packages/posthog/package.jsonindex 099bb555f..0397387c3 100644--- a/packages/posthog/package.json+++ b/packages/posthog/package.json@@ -15,6 +15,10 @@"posthog-js": "^1.178.0","posthog-node": "^4.2.1"},+ "devDependencies": {+ "@rallly/eslint-config": "*",+ "@rallly/tsconfig": "*"+ },"peerDependencies": {"next": "^14.2.13","react": "^18.2.0"diff --git a/packages/posthog/tsconfig.json b/packages/posthog/tsconfig.jsonindex 42e5369c0..04f595776 100644--- a/packages/posthog/tsconfig.json+++ b/packages/posthog/tsconfig.json@@ -1,5 +1,9 @@{"extends": "@rallly/tsconfig/next.json",- "include": ["**/*.ts", "**/*.tsx"],+ "include": [+ "**/*.ts",+ "**/*.tsx",+ "../../apps/web/src/posthog-page-view.tsx"+ ],"exclude": ["node_modules"]}diff --git a/packages/tsconfig/base.json b/packages/tsconfig/base.jsonindex 66373c9ff..ae4cfac9c 100644--- a/packages/tsconfig/base.json+++ b/packages/tsconfig/base.json@@ -10,6 +10,7 @@"noUncheckedIndexedAccess": false,"noImplicitReturns": false,"verbatimModuleSyntax": true,- "skipLibCheck": true+ "skipLibCheck": true,+ "strictNullChecks": true}}