/** * Google Analytics initialization module * Handles analytics loading and privacy notices */ class AnalyticsManager { constructor() { this.isProduction = window.location.hostname === 'app.worklenz.com'; this.trackingId = this.isProduction ? 'G-7KSRKQ1397' : 'G-3LM2HGWEXG'; } /** * Initialize Google Analytics asynchronously */ init() { const loadAnalytics = () => { // Load the Google Analytics script const script = document.createElement('script'); script.async = true; script.src = `https://www.googletagmanager.com/gtag/js?id=${this.trackingId}`; document.head.appendChild(script); // Initialize Google Analytics window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', this.trackingId); }; // Use requestIdleCallback if available, otherwise setTimeout if ('requestIdleCallback' in window) { requestIdleCallback(loadAnalytics, { timeout: 2000 }); } else { setTimeout(loadAnalytics, 1000); } } /** * Show privacy notice for non-production environments */ showPrivacyNotice() { const notice = document.createElement('div'); notice.style.cssText = ` position: fixed; bottom: 16px; right: 16px; background: #222; color: #f5f5f5; padding: 12px 16px 10px 16px; border-radius: 7px; box-shadow: 0 2px 8px rgba(0,0,0,0.18); z-index: 1000; max-width: 320px; font-family: Inter, sans-serif; border: 1px solid #333; font-size: 0.95rem; `; notice.innerHTML = `