cmux/web/app/[locale]/posthog.tsx
Lawrence Chen 387742a5a0
Update all remaining cmux.dev references to cmux.com (#1721)
- 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>
2026-03-18 01:32:12 -07:00

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>
);
}