Files
copilotkit__copilotkit/docs/lib/hooks/use-google-analytics.tsx
John Rae-Grant e9e6fbdd85 Docs Rebranding with fixes (#2982)
Co-authored-by: Max Korp <maxkorp@8bytealchemy.com>
Co-authored-by: Santiago Cubino <scubino@litebox.ai>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-08 14:28:26 -08:00

26 lines
641 B
TypeScript

"use client";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
import ReactGA from "react-ga4";
import { normalizePathnameForAnalytics } from "@/lib/analytics-utils";
export function useGoogleAnalytics() {
const GA_ID = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID;
if (!GA_ID) {
return;
}
const pathname = usePathname();
useEffect(() => {
ReactGA.initialize([{ trackingId: GA_ID }]);
}, []);
useEffect(() => {
const normalizedPathname = normalizePathnameForAnalytics(pathname);
ReactGA.send({ hitType: "pageview", page: normalizedPathname });
}, [pathname]);
}