mgonto / angularytics

The solution to tracking page views and events in a SPA with AngularJS
MIT License
630 stars 70 forks source link

Set tracking ID under config #46

Open niyando opened 8 years ago

niyando commented 8 years ago

Not exactly an issue but something that would be great to have.

Using below

.config(function(AngularyticsProvider, ENV) {
  if(ENV.name === "production")
    AngularyticsProvider.setEventHandlers(['Console', 'GoogleUniversal']);
  else
    AngularyticsProvider.setEventHandlers('Console');
}).run(function(Angularytics) {
  Angularytics.init();
})

as expected, I am able to trigger events only in production mode. But now I also wish to log events in staging (pre-production) env under some different tracking ID UA-XXXXX-Y (to segregate data). I need to set tracking id conditionally for this. Is there a way to set this in above block instead of hardcoding it in html file?

If not, I would be happy to contribute. Thanks for this awesome utility :+1:

GQuantrill commented 7 years ago

You can do this using lookup tables from within Google Tab Manager. I have UA-xxx-1 for pre-prod and the UA-xxxx-2 for all things production. You then alter the events and pageview triggers to use the lookup table to determine which tag to use.