Page view

This commit is contained in:
Luke Vella 2024-11-02 13:48:10 +00:00
parent 66ff75096a
commit 65a46e42aa
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
5 changed files with 156 additions and 112 deletions

View file

@ -2,6 +2,7 @@ import "tailwindcss/tailwind.css";
import "../../style.css";
import languages from "@rallly/languages";
import { PostHogProvider } from "@rallly/posthog/client";
import {
DropdownMenu,
DropdownMenuContent,
@ -46,6 +47,7 @@ export default async function Root({
return (
<html lang={locale} className={sans.className}>
<body>
<PostHogProvider>
<I18nProvider locale={locale}>
<div className="mx-auto flex min-h-full w-full max-w-7xl flex-col space-y-12 p-4 sm:p-8">
<header className="flex w-full items-center">
@ -60,7 +62,11 @@ export default async function Root({
</Link>
<nav className="hidden items-center space-x-8 lg:flex">
<NavLink href="https://support.rallly.co/workflow/create">
<Trans t={t} i18nKey="howItWorks" defaults="How it Works" />
<Trans
t={t}
i18nKey="howItWorks"
defaults="How it Works"
/>
</NavLink>
<NavLink href="/pricing">
<Trans t={t} i18nKey="pricing" />
@ -152,6 +158,7 @@ export default async function Root({
</footer>
</div>
</I18nProvider>
</PostHogProvider>
<Analytics />
</body>
</html>

View file

@ -4,6 +4,7 @@ import "../../style.css";
import { PostHogProvider } from "@rallly/posthog/client";
import { Toaster } from "@rallly/ui/toaster";
import type { Viewport } from "next";
import dynamic from "next/dynamic";
import { Inter } from "next/font/google";
import React from "react";
@ -12,6 +13,10 @@ import { Providers } from "@/app/providers";
import { getServerSession } from "@/auth";
import { SessionProvider } from "@/auth/session-provider";
const PostHogPageView = dynamic(() => import("@rallly/posthog/next"), {
ssr: false,
});
const inter = Inter({
subsets: ["latin"],
display: "swap",
@ -38,6 +43,7 @@ export default async function Root({
<Toaster />
<SessionProvider session={session}>
<PostHogProvider distinctId={session?.user?.id}>
<PostHogPageView />
<Providers>
{children}
<TimeZoneChangeDetector />

View file

@ -8,13 +8,15 @@
},
"exports": {
"./server": "./src/server/index.ts",
"./client": "./src/client/index.ts"
"./client": "./src/client/index.ts",
"./next": "./src/next.ts"
},
"dependencies": {
"posthog-js": "^1.178.0",
"posthog-js": "^1.180.1",
"posthog-node": "^4.2.1"
},
"peerDependencies": {
"react": "^18.2.0"
"react": "^18.2.0",
"next": "^14.2.13"
}
}

View file

@ -0,0 +1,29 @@
"use client";
import { usePathname, useSearchParams } from "next/navigation";
import React from "react";
import { usePostHog } from "./client";
export default function PostHogPageView() {
const pathname = usePathname();
const searchParams = useSearchParams();
const posthog = usePostHog();
const previousUrl = React.useRef<string | null>(null);
React.useEffect(() => {
// Track pageviews
if (pathname && posthog) {
let url = window.origin + pathname;
if (searchParams?.toString()) {
url = url + `?${searchParams.toString()}`;
}
if (previousUrl.current !== url) {
posthog.capture("$pageview", {
$current_url: url,
});
previousUrl.current = url;
}
}
}, [pathname, searchParams, posthog]);
return null;
}

View file

@ -12817,10 +12817,10 @@ postgres-range@^1.1.1:
resolved "https://registry.yarnpkg.com/postgres-range/-/postgres-range-1.1.4.tgz#a59c5f9520909bcec5e63e8cf913a92e4c952863"
integrity sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==
posthog-js@^1.178.0:
version "1.178.0"
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.178.0.tgz#80005798e6c67d4d6565a5648939a0f017b0879b"
integrity sha512-ILD4flNh72d5dycc4ZouKORlaVr+pDzl5TlZr1JgP0NBAoduHjhE7XZYwk7zdYkry7u0qAIpfv2306zJCW2vGg==
posthog-js@^1.180.1:
version "1.180.1"
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.180.1.tgz#e4b1bb2917b306f40c6063102a1508539f44ba2a"
integrity sha512-LV65maVrpqkAh0wu32YvU7FpCSEjg6o+sZFYCs1+6tnEa9VvXuz8J6ReLiyRpJABI4j1qX/PB2jaVY5tDbLalQ==
dependencies:
core-js "^3.38.1"
fflate "^0.4.8"