Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disableAnalytics requires an account #226

Open
lapo-luchini opened this issue Feb 12, 2019 · 1 comment
Open

disableAnalytics requires an account #226

lapo-luchini opened this issue Feb 12, 2019 · 1 comment
Assignees
Labels

Comments

@lapo-luchini
Copy link

lapo-luchini commented Feb 12, 2019

Hi, for the sake of avoiding an if around every Analytics.trackEvent line we have in our code, I'd like to have a way to disable this module when a UA account is not defined (that's an option that our users will have to use or not).

Unfortunately disableAnalytics requires an account or gives a stack trace exception, so I worked it around like this:

mod.config(/*@ngInject*/ function (AnalyticsProvider, analyticsId) {
    if (analyticsId)
        AnalyticsProvider.setAccount(analyticsId); 
    else {
        AnalyticsProvider.setAccount(''); // else fails on next line
        AnalyticsProvider.disableAnalytics(true);
    }
})

This works ok (and any page change and event tracking generate no errors), but is there a recommended way to achieve this?

@justinsa
Copy link
Collaborator

justinsa commented Apr 6, 2019

I need to understand what you are encountering a little better. The disableAnalytics() config method sets a variable during configuration, that is all, so it is not generating an error on its own.

The reason this requires an account is because this is a feature of GA and something we are exposing during the script injection on the page. This is the code performing this:

if (disableAnalytics === true) {
  accounts.forEach(function (trackerObj) {
      that._log('info', 'Analytics disabled: ' + trackerObj.tracker);
      $window['ga-disable-' + trackerObj.tracker] = true;
  });
}

As you can tell this requires at least one account to exist. This entire library is premised on at least 1 account being defined for operation and a warning is issued during tracker registration if the list is undefined or empty.

Your particular use case sounds like what you expected was a way to disable the Analytics service and not just the GA behaviors.

@justinsa justinsa self-assigned this Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants