Files
bakery-ia/frontend/src/hooks/useAnalytics.ts
2026-01-17 22:42:40 +01:00

34 lines
915 B
TypeScript

import {
trackPageView,
trackUserAction,
trackUserLocation,
trackSession,
getCurrentUserId,
isAnalyticsEnabled
} from '../utils/analytics';
/**
* React Hook for analytics
*
* NOTE: Page view tracking is handled globally by initializeAnalytics() in main.tsx.
* This hook only exposes tracking functions for use in components.
* Do NOT add automatic page tracking here to avoid duplicate events.
*/
export const useAnalytics = () => {
return {
// Manual page view tracking (use only for custom page events, not navigation)
trackPageView,
// Track user actions (button clicks, form submissions, etc.)
trackUserAction,
// Track user location (requires consent)
trackUserLocation,
// Track session (typically called once at app init)
trackSession,
// Get current user ID
getCurrentUserId,
// Check if analytics are enabled
isAnalyticsEnabled
};
};