mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-28 17:56:37 +02:00
📈 Enable page view analytics (#1434)
This commit is contained in:
parent
ee68d80026
commit
4f98661a12
5 changed files with 38 additions and 2 deletions
24
apps/web/src/app/posthog-page-view.tsx
Normal file
24
apps/web/src/app/posthog-page-view.tsx
Normal file
|
@ -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;
|
||||
}
|
|
@ -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}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"noUncheckedIndexedAccess": false,
|
||||
"noImplicitReturns": false,
|
||||
"verbatimModuleSyntax": true,
|
||||
"skipLibCheck": true
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue