prawito hudoro prawito hudoro - 1 year ago 103
PHP Question

how to disable google analytics on localhost

I use this for google analytics,

<iframe src="//" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

and this

<script>(function(w, d, s, l, i) {
w[l] = w[l] || [];
'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 =
'//' + i + dl;
f.parentNode.insertBefore(j, f);})(window, document, 'script', 'dataLayer', 'GTM-KCQGLT');</script>

Can I disable this script when I run this code in localhost?

Answer Source

Use below code.

var host = window.location.hostname;
if(host != "localhost")
    // your google analytic code here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download