Since angular-google-analytics requires a config block to set up an account, it’s best to separate the Google Analytics reporting into a separate sub-module of your application:
//create separate module for analytics reporting var reportingModule = angular.module('mainApp.reporting', [ 'angular-google-analytics' ]) .config(function(AnalyticsProvider) { AnalyticsProvider.setAccount('UA-HELLO-GA'); }) .run(function(Analytics) { console.log('mmm.. analytics is good for you'); });
And then add this submodule to your main module asynchronously through the module.requires array so that it starts after the main load module completes:
var mainApp = angular.module('mainApp', [ ]) .controller('MyCtrl', function($scope) { $scope.message = 'Hello World!'; });
Thus, the main module completes the download without errors associated with the submodule message.
Here's a forked version of your plunkr: http://plnkr.co/edit/lgNZOz4MZx0FGoCOGRC9
source share