807a77992e
- 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
27 lines
646 B
TypeScript
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;
|
|
}
|