quivr/frontend/services/analytics/june/usePageTracking.ts
Zineb El Bachiri 886d30cf9e
feat(analytics): add google analytics (#1147)
* 🚚 move june analytics to folder and update paths

*  set up google analytics

*  sent firt GA event with react-ga

* 🔒️ update security headers to include vercel and google analytics

* 🚚 rename Vercel Analytics

*  use react-ga4 instread

* 💚 fix tests
2023-09-18 15:12:50 +02:00

26 lines
634 B
TypeScript

"use client";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
import { useSupabase } from "@/lib/context/SupabaseProvider";
import { useJune } from "./useJune";
export const usePageTracking = (): void => {
const analytics = useJune();
const pathname = usePathname();
const { session } = useSupabase();
useEffect(() => {
if (pathname !== null) {
const handleRouteChange = async () => {
await analytics?.identify(session?.user.id);
await analytics?.page(pathname);
};
void handleRouteChange();
}
}, [analytics, pathname, session?.user.id]);
};