Disabling a section of code in html with something like an if statement

I have a live site, and I must continue to work on it on a live site, which means that I often browse the page.

I am wondering if there is a way to use, as an if statement in HTML, I can disable google analytic code so that it does not spoil our reports? Therefore, I can simply change the value on the page (e.g. TRUE / FALSE) so that I can work on it in my heart, and I do not destroy the analytics.

+5
source share
3 answers

The best approach is for Google analytics to filter your IP address.

https://support.google.com/analytics/answer/1034840?hl=en

+4
source

Check window.location.search for the querystring variable and set this variable if you do not want analytics. Below code is shown to hide only if querystring contains hidegoogle = yes

var hide = window.location.search.match(/hidegoogle=(yes|no)/); if (hide !== null && hide[1] === "yes") { console.log('yes'); } else { console.log('no'); // Run analytics here } 
+1
source

Consider using Google Tag Manager:

http://tagmanager.google.com/

It can manage Google Analytics tags.

0
source

Source: https://habr.com/ru/post/1233726/


All Articles