From 527bbefc83f7bb6d5ef639d6719505468f6cba33 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Mon, 2 Nov 2026 15:56:33 +0300 Subject: [PATCH] add Ga --- html/js/main.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/html/js/main.js b/html/js/main.js index b431cf7..9e72aee 100644 --- a/html/js/main.js +++ b/html/js/main.js @@ -1,5 +1,5 @@ -// Analytics: use the existing Metrika counter and the supplied GTM container. -// A GTM- identifier is a Tag Manager container, not a GA4 measurement ID. +// Analytics load only after consent: Metrika, GTM and direct GA4. +// GA4 is configured here; do not configure the same GA4 tag/events again in GTM. (function() { const key = 'olyapka_analytics_v2'; const banner = document.getElementById('cookieBanner'); @@ -16,6 +16,12 @@ document.head.append(metrika); window.ym(110606131, 'init', {clickmap: true, trackLinks: true, accurateTrackBounce: true, webvisor: true}); window.dataLayer = window.dataLayer || []; + window.gtag = window.gtag || function() { window.dataLayer.push(arguments); }; + window.gtag('js', new Date()); + window.gtag('config', 'G-T6084CKB81'); + const ga = document.createElement('script'); + ga.async = true; ga.src = 'https://www.googletagmanager.com/gtag/js?id=G-T6084CKB81'; + document.head.append(ga); window.dataLayer.push({'gtm.start': Date.now(), event: 'gtm.js'}); const gtm = document.createElement('script'); gtm.async = true; gtm.src = 'https://www.googletagmanager.com/gtm.js?id=GTM-M5HGH586'; @@ -75,7 +81,11 @@ if (window.analyticsAllowed && typeof ym !== 'undefined') { try { ym(110606131, 'reachGoal', goal); } catch(err) {} } - // Google Analytics + // Send existing button goals directly to GA4. + if (window.analyticsAllowed && typeof window.gtag === 'function') { + window.gtag('event', goal, {send_to: 'G-T6084CKB81'}); + } + // Keep custom events available to the existing GTM container. if (window.analyticsAllowed && window.dataLayer) window.dataLayer.push({event: goal}); }); })();