On localhost, I disable my google analytics code by incorporating it into an if statement like so:
var s = window.location + "";
if (s.indexOf('localhost') < 0) {
//GA universal analytics tracking snippet
}
However, throughout my site there are various event tags using ga('send', 'event', etc...);
- when my GA snippet is disabled on localhost these functions return errors (Uncaught ReferenceError: ga is not defined
).
Is there a way to disable these functions without putting them all into their own individual if statements? I was thinking some kind of global statement like this might work, but it doesn't:
var s = window.location + "";
if (s.indexOf('localhost') > 0) {
ga = function () {};
}
Is there a good best practice for solving this? Thanks!