From e5100342504385f70271f0fde514b7efe73acd97 Mon Sep 17 00:00:00 2001 From: Paulo Jorge Reis Date: Wed, 2 Dec 2020 10:16:28 +0000 Subject: [PATCH] Merge pull request #3428 from overleaf/jpa-gaBlocked [GA] do not load GA Optimize, if we observed GA being blocked previously GitOrigin-RevId: 0e3a12c0b9a086a08797c32430a567b8540d25b7 --- services/web/app/views/layout.pug | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index ef5b6476f9..b0daa3846f 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -39,18 +39,30 @@ html( script(type='text/javascript'). ga('create', '#{gaToken}', '#{settings.cookieDomain.replace(/^\./, "")}'); ga('send', 'pageview'); + + try { + ga.isBlocked = localStorage.getItem('gaBlocked') === 'true' + if (!ga.isBlocked) { + window.addEventListener('load', function () { + setTimeout(function () { + if (!ga.loaded) localStorage.setItem('gaBlocked', 'true') + }, 4000) + }) + } + } catch (e) {} if gaOptimize === true && typeof(gaOptimizeId) != "undefined" - script(type='text/javascript'). - ga('require', '#{gaOptimizeId}') - ga('send', 'event', 'pageview', document.title.substring(0, 499), window.location.href.substring(0, 499)) //- Anti-flicker snippet style(type='text/css') .async-hide { opacity: 0 !important} script(type='text/javascript'). - (function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date; - h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')}; - (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c; - })(window,document.documentElement,'async-hide','dataLayer',4000, - {'#{gaOptimizeId}':true}); + if (!ga.isBlocked) { + ga('require', '#{gaOptimizeId}'); + ga('send', 'event', 'pageview', document.title.substring(0, 499), window.location.href.substring(0, 499)); + (function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date; + h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')}; + (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c; + })(window,document.documentElement,'async-hide','dataLayer',4000, + {'#{gaOptimizeId}':true}); + } - else script(type='text/javascript').