Loading plugins/gtm/gtm.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -111,12 +111,21 @@ namespace blogi { << "});" << "</script>"; // Lazy load: defer GTM/GA4 until user interaction or timeout // Always load GTM container (respects Consent Mode internally) headjs << "<script>" << "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" << "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," << "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" << "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" << "})(window,document,'script','dataLayer','" << GTM << "');" << "</script>"; // Update consent when user has granted permissions if(gtmGranted || ga4Granted){ headjs << "<script>" << "(function(){" << "var loaded=false;" << "function loadGTM(){"; << "function loadConsented(){"; if(ga4Granted){ headjs << "gtag('consent','update',{" Loading @@ -130,14 +139,6 @@ namespace blogi { << "});"; } if(gtmGranted){ headjs << "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" << "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," << "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" << "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" << "})(window,document,'script','dataLayer','" << GTM << "');"; } if(ga4Granted){ headjs << "var s=document.createElement('script');" << "s.async=true;s.src='https://www.googletagmanager.com/gtag/js?id=" << G4A << "';" Loading @@ -146,10 +147,10 @@ namespace blogi { << "gtag('config','" << G4A << "');"; } headjs << "}" // end loadGTM headjs << "}" // end loadConsented << "function trigger(){" << "if(loaded)return;loaded=true;" << "loadGTM();" << "loadConsented();" << "['scroll','click','keydown','touchstart'].forEach(function(e){" << "document.removeEventListener(e,trigger,{passive:true});" << "});" Loading @@ -167,7 +168,7 @@ namespace blogi { } libhtmlpp::HtmlElement *body=curpage->getElementbyTag("body"); if(gtmGranted && body){ if(body){ libhtmlpp::HtmlString gtmjs; gtmjs << "<!-- Google Tag Manager (noscript) -->" << "<noscript><iframe src=\"https://www.googletagmanager.com/ns.html?id=" Loading Loading
plugins/gtm/gtm.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -111,12 +111,21 @@ namespace blogi { << "});" << "</script>"; // Lazy load: defer GTM/GA4 until user interaction or timeout // Always load GTM container (respects Consent Mode internally) headjs << "<script>" << "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" << "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," << "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" << "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" << "})(window,document,'script','dataLayer','" << GTM << "');" << "</script>"; // Update consent when user has granted permissions if(gtmGranted || ga4Granted){ headjs << "<script>" << "(function(){" << "var loaded=false;" << "function loadGTM(){"; << "function loadConsented(){"; if(ga4Granted){ headjs << "gtag('consent','update',{" Loading @@ -130,14 +139,6 @@ namespace blogi { << "});"; } if(gtmGranted){ headjs << "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':" << "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0]," << "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=" << "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);" << "})(window,document,'script','dataLayer','" << GTM << "');"; } if(ga4Granted){ headjs << "var s=document.createElement('script');" << "s.async=true;s.src='https://www.googletagmanager.com/gtag/js?id=" << G4A << "';" Loading @@ -146,10 +147,10 @@ namespace blogi { << "gtag('config','" << G4A << "');"; } headjs << "}" // end loadGTM headjs << "}" // end loadConsented << "function trigger(){" << "if(loaded)return;loaded=true;" << "loadGTM();" << "loadConsented();" << "['scroll','click','keydown','touchstart'].forEach(function(e){" << "document.removeEventListener(e,trigger,{passive:true});" << "});" Loading @@ -167,7 +168,7 @@ namespace blogi { } libhtmlpp::HtmlElement *body=curpage->getElementbyTag("body"); if(gtmGranted && body){ if(body){ libhtmlpp::HtmlString gtmjs; gtmjs << "<!-- Google Tag Manager (noscript) -->" << "<noscript><iframe src=\"https://www.googletagmanager.com/ns.html?id=" Loading