Files
tm-landing/app/_components/GoogleAnalytics.tsx
T
AmirReza Jamali 807a77992e feat(analytics): Add Firebase Analytics integration with page tracking
- Initialize Firebase Analytics with configuration and client-side setup
- Create GoogleAnalytics component to track page views on route changes
- Add analytics utility functions for tracking custom events (button clicks, form submissions, link clicks, searches)
- Integrate GoogleAnalytics component into home, not-found, and marketing layouts with Suspense boundary
- Add firebase dependency to package.json
- Enable automatic page view tracking with pathname and search parameters
2025-11-22 10:56:40 +03:30

27 lines
646 B
TypeScript

"use client";
import { analytics } from "@/lib/firebase";
import { logEvent } from "firebase/analytics";
import { usePathname, useSearchParams } from "next/navigation";
import { useEffect } from "react";
export default function GoogleAnalytics() {
const pathname = usePathname();
const searchParams = useSearchParams();
useEffect(() => {
if (analytics) {
const url =
pathname +
(searchParams?.toString() ? `?${searchParams.toString()}` : "");
logEvent(analytics, "page_view", {
page_path: url,
page_title: document.title,
});
}
}, [pathname, searchParams]);
return null;
}