I have the following chrome plugin installed uBlock Origin , And i am using angular-google-analytics in my angular application. The adblocker is blocking angular-google-analytics.js script. Due to that i am getting injector modular error.
To solve that issue i have written it in the following way -
try {
// Check if the below module is available
angular.module('angular-google-analytics');
angular.module('myApp').requires.push('angular-google-analytics');
angular.module('myApp').config(function(AnalyticsProvider) {
AnalyticsProvider.setAccount('API', 'KEY');
AnalyticsProvider.trackPages(!0),
AnalyticsProvider.setDomainName("www.test.com"),
AnalyticsProvider.useAnalytics(!0),
AnalyticsProvider.useECommerce(!0, !0)
AnalyticsProvider.setCurrency('INR');
}).run(function(Analytics) {});
console.log("GA available");
} catch(e) {
// statements
console.error("GA not available"+ e);
}
And to use the dependency in other controllers/ services
if ($injector.has('angular-google-analytics'))
var Analytics = $injector.get('angular-google-analytics');
And this dependency is there in many controllers.
So my question is, is this the best way? Or is there any alternative better way that can be applicable?