2

I'm testing Google Analytics Event tracking with my local server.

I'm using the debug version of ga.js, ga_debug.js, in order to print debug text automatically in my browser console. Furthermore, i set domain name to none, which is supposed not sending the data to your Analytics account (stackoverflow post):

_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
...

But my events tracked are still sent to my Analytics Account, so my question is how to avoid this? Is the _gaq.push(['_setDomainName', 'none']); disable data sending only for page view and not event tracking?

Thanks for your help,

Xavier

Community
  • 1
  • 1
Xavier
  • 23
  • 7

1 Answers1

1

Add the following snippet to your dev environment:

window['ga-disable-UA-XXXXXX-Y'] = true;

For more information read https://developers.google.com/analytics/devguides/collection/gajs/#disable

jontro
  • 10,241
  • 6
  • 46
  • 71
  • Not too bad :-) Please note your solution skipped debugging text printing. Some debugging datas are still printed on the console which is enough for me (`_gaq.push processing "_trackEvent" for args: "[Category_Text,Action_Text,2150,,false]": `), but some people might need the whole debugging text. Thank you for your quick reply. – Xavier Jun 18 '13 at 09:57
  • Finally setting domain name to none is useless for local testing? – Xavier Jun 18 '13 at 10:07
  • Well if the debug output is only printed when there is actual data sent you could set up a new profile on google analytics that you only use for testing purposes – jontro Jun 18 '13 at 11:21
  • If I have the dev end production environment open in two different tabs in the same browser, is tracking going to work in prod environment? – Xavier Jun 18 '13 at 13:13
  • "developement and production environment ", sorry – Xavier Jun 18 '13 at 13:31
  • That you have them open in different tabs has no effect on the code. Look at the network inspector to see what happens – jontro Jun 18 '13 at 13:55
  • I used it a bit different: `window['ga-disable-UA-XXXXX-Y'] = !('https:' == document.location.protocol);`, in my case https is used only in production. – Vitor Canova May 20 '16 at 17:52