mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
e9e6fbdd85
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>
26 lines
641 B
TypeScript
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]);
|
|
}
|