This snippet contains the code necessary to make google analytics calls from your extension.
It plays nicely with the AESP licensing framework so if the user decides to disable analytics
this component will honor that automatically. You don't need to do anything special to make
that behavior work. Just call the analytics functions assuming the user granted permission
and if they didn't the calls will do a no-op internally.
This code came straight out of the code for After Ease, is designed for its taxonomy/ontology and wasn't meant for distribution. As such you'll want to massage it before using it. For example you'll want to change line 70 to have the domain of your website in there.
var analytics = new Analytics('YOUR-TRACKING-ID');
// Call when your app opens a new screen (FYI the licensing
// framework already does this when the extension opens)
analytics.visit('app');
// Called to track a custom event
analytics.track(...);
// If you want to log if an error was raised
analytics.exception(e);
// Gets/sets if analytics is enabled. You shouldn't ever
// need this but just in case.
analytics.enabled();