Build & Deploy / 🔍 Prepare (push) Successful in 9s
Build & Deploy / 🧪 QA (push) Failing after 1m18s
Build & Deploy / 🏗️ Build (push) Failing after 2m58s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
- Added Umami Smart Proxy route handler - Refactored Umami adapter to use proxy-based fetch - Implemented TrackedButton, TrackedLink, and ScrollDepthTracker - Integrated event tracking into ContactForm - Enhanced Analytics component with manual pageview and performance tracking
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback } from "react";
|
|
import { getDefaultAnalytics } from "../../utils/analytics";
|
|
import type { AnalyticsEventName } from "./analytics-events";
|
|
|
|
/**
|
|
* Custom hook for tracking analytics events.
|
|
* Wraps the analytics service for easy use in components.
|
|
*/
|
|
export function useAnalytics() {
|
|
const trackEvent = useCallback(
|
|
(
|
|
eventName: string | AnalyticsEventName,
|
|
properties?: Record<string, any>,
|
|
) => {
|
|
const analytics = getDefaultAnalytics();
|
|
analytics.trackEvent(eventName, properties);
|
|
|
|
if (process.env.NODE_ENV === "development") {
|
|
console.debug("[Analytics] Tracked event:", eventName, properties);
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
|
|
const trackPageview = useCallback((url?: string) => {
|
|
const analytics = getDefaultAnalytics();
|
|
analytics.page(url || window.location.pathname);
|
|
|
|
if (process.env.NODE_ENV === "development") {
|
|
console.debug("[Analytics] Tracked pageview:", url ?? "current location");
|
|
}
|
|
}, []);
|
|
|
|
return {
|
|
trackEvent,
|
|
trackPageview,
|
|
};
|
|
}
|