Skip to content

disableAnalytics requires an account #226

@lapo-luchini

Description

@lapo-luchini

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?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions