Commit d980372d authored by jan.koester's avatar jan.koester
Browse files

test

parent 5031ca86
Loading
Loading
Loading
Loading
+30 −13
Changes for plugins/gtm/gtm.cpp: 30 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -111,10 +111,15 @@ namespace blogi {
                       << "});"
                       << "</script>";

                // If consent granted, send consent update to switch to granted
                if(ga4Granted){
                // Lazy load: defer GTM/GA4 until user interaction or timeout
                if(gtmGranted || ga4Granted){
                    headjs << "<script>"
                           << "gtag('consent', 'update', {"
                           << "(function(){"
                           << "var loaded=false;"
                           << "function loadGTM(){";

                    if(ga4Granted){
                        headjs << "gtag('consent','update',{"
                               << "'ad_storage':'granted',"
                               << "'ad_user_data':'granted',"
                               << "'ad_personalization':'granted',"
@@ -122,26 +127,38 @@ namespace blogi {
                               << "'functionality_storage':'granted',"
                               << "'personalization_storage':'granted',"
                               << "'security_storage':'granted'"
                           << "});"
                           << "</script>";
                               << "});";
                    }

                    if(gtmGranted){
                    headjs  << "<!-- Google Tag Manager -->"
                    << "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':"
                        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 << "');</script>"
                    << "<!-- End Google Tag Manager -->";
                               << "})(window,document,'script','dataLayer','" << GTM << "');";
                    }

                    if(ga4Granted){
                    headjs << "<!-- Google tag (gtag.js) -->"
                    << "<script async src=\"https://www.googletagmanager.com/gtag/js?id=" << G4A << "\"></script>"
                    << "<script>"
                        headjs << "var s=document.createElement('script');"
                               << "s.async=true;s.src='https://www.googletagmanager.com/gtag/js?id=" << G4A << "';"
                               << "document.head.appendChild(s);"
                               << "gtag('js',new Date());"
                    << "gtag('config', '"<< G4A << "');"
                               << "gtag('config','" << G4A << "');";
                    }

                    headjs << "}"  // end loadGTM
                           << "function trigger(){"
                           << "if(loaded)return;loaded=true;"
                           << "loadGTM();"
                           << "['scroll','click','keydown','touchstart'].forEach(function(e){"
                           << "document.removeEventListener(e,trigger,{passive:true});"
                           << "});"
                           << "}"
                           << "['scroll','click','keydown','touchstart'].forEach(function(e){"
                           << "document.addEventListener(e,trigger,{passive:true});"
                           << "});"
                           << "setTimeout(trigger,5000);"
                           << "})();"
                           << "</script>";
                }