- Swift app: feedback API endpoint, docs URLs, changelog URL, CLI help - PostHog proxy: r.cmux.dev -> r.cmux.com - All 20 README files: docs and blog links - Homebrew cask: homepage URL in update-homebrew workflow Co-authored-by: Lawrence Chen <lawrencecchen@users.noreply.github.com>
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: "https://r.cmux.com",
|
|
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>
|
|
);
|
|
}
|