- Delete docs-site/ (superseded by web/app/docs) - Add posthog-js with Vercel reverse proxy at /cdata to bypass adblockers - Track pageviews (SPA-aware), download clicks (hero/navbar/mobile_drawer), and GitHub link clicks (hero/navbar/mobile_drawer/footer)
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import posthog from "posthog-js";
|
|
import { PostHogProvider as PHProvider } from "posthog-js/react";
|
|
import { usePathname, useSearchParams } from "next/navigation";
|
|
import { useEffect, Suspense } from "react";
|
|
|
|
if (typeof window !== "undefined") {
|
|
posthog.init("phc_opOVu7oFzR9wD3I6ZahFGOV2h3mqGpl5EHyQvmHciDP", {
|
|
api_host: "/cmuxterm",
|
|
ui_host: "https://us.posthog.com",
|
|
person_profiles: "identified_only",
|
|
capture_pageview: false,
|
|
capture_pageleave: true,
|
|
});
|
|
}
|
|
|
|
function PageviewTracker() {
|
|
const pathname = usePathname();
|
|
const searchParams = useSearchParams();
|
|
|
|
useEffect(() => {
|
|
if (pathname && posthog) {
|
|
let url = window.origin + pathname;
|
|
const search = searchParams.toString();
|
|
if (search) url += "?" + search;
|
|
posthog.capture("$pageview", { $current_url: url });
|
|
}
|
|
}, [pathname, searchParams]);
|
|
|
|
return null;
|
|
}
|
|
|
|
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<PHProvider client={posthog}>
|
|
<Suspense fallback={null}>
|
|
<PageviewTracker />
|
|
</Suspense>
|
|
{children}
|
|
</PHProvider>
|
|
);
|
|
}
|