Analytics (Mixpanel, Amplitude, Google Analytics) now only initialise after user accepts cookies. Reject option available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import mixpanel from 'mixpanel-browser';
|
|
import * as amplitude from '@amplitude/unified';
|
|
|
|
let initialized = false;
|
|
|
|
export function initAnalytics() {
|
|
if (initialized) return;
|
|
initialized = true;
|
|
|
|
// Mixpanel
|
|
mixpanel.init('0d370dad59a8483f8b568639a649a535', {
|
|
debug: false,
|
|
track_pageview: true,
|
|
persistence: 'localStorage',
|
|
autocapture: true,
|
|
record_sessions_percent: 100,
|
|
});
|
|
|
|
// Amplitude
|
|
amplitude.initAll('363aa4bae4e29f5dd72baaacf1428342', {
|
|
analytics: { autocapture: true },
|
|
sessionReplay: { sampleRate: 1 },
|
|
});
|
|
|
|
// Google Analytics (load gtag script dynamically)
|
|
const script = document.createElement('script');
|
|
script.async = true;
|
|
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-V7408CVBRY';
|
|
document.head.appendChild(script);
|
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(...args: unknown[]) {
|
|
window.dataLayer.push(args);
|
|
}
|
|
gtag('js', new Date());
|
|
gtag('config', 'G-V7408CVBRY');
|
|
}
|
|
|
|
declare global {
|
|
interface Window {
|
|
dataLayer: unknown[];
|
|
}
|
|
}
|