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
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"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;
|
||||
}
|
||||
Reference in New Issue
Block a user