// site/analytics.jsx — thin wrapper around gtag() for CTA tracking. // Usage: trackEvent('cta_hero_primary', { section: 'hero', lang: 'it' }) // Events are sent only if the GA snippet loaded; if consent is "denied", // Consent Mode v2 buffers them server-side without storing _ga cookies. function trackEvent(eventName, params) { try { if (typeof window.gtag === 'function') { window.gtag('event', eventName, params || {}); } } catch (e) { /* swallow — analytics must never break the page */ } } // Called by the consent banner when the user accepts "all". function grantAnalyticsConsent() { try { if (typeof window.gtag === 'function') { window.gtag('consent', 'update', { 'analytics_storage': 'granted' }); } } catch (e) {} } Object.assign(window, { trackEvent, grantAnalyticsConsent });