revolunet / angular-google-analytics

Google Analytics tracking for your AngularJS apps
MIT License
652 stars 172 forks source link

Argument 'fn' is not a function, got string #181

Closed harshamadala closed 7 years ago

harshamadala commented 7 years ago

Followed these stips but getting error "Argument 'fn' is not a function, got string"

  1. bower install angular-google-analytics
  2. var myApp = angular.module('myModule', ['angular-google-analytics']);
  3. myApp.config(function (AnalyticsProvider) { // Add configuration code as desired AnalyticsProvider.setAccount('UU-XXXXXXX-X'); //UU-XXXXXXX-X should be your tracking code }).run(['Analytics'], function(Analytics) { });

I am getting error after doing 4th step. Am i doing anything wrong? Can anyone please help? Is there any version requirement for angular js?

lyvyu commented 7 years ago

What version of angular are you using ?

revolunet commented 7 years ago

looks like myApp.config(function (AnalyticsProvider) { is not minifier-friendly ?

shouldnt you use myApp.config(['AnalyticsProvider', function (AnalyticsProvider) { ?

revolunet commented 7 years ago

just realized this is written the same way on the README. can someone confirm the correct syntax for the config block ?

Toxantron commented 7 years ago

@revolunet from the top of my head I would agree. I see no reason why config() would behave differently when minified. @harshamadala could you try to copy the method syntax from run()?

justinsa commented 7 years ago

The problem is the 'run' method is configured incorrectly.

}).run(['Analytics'], function(Analytics) { });

That is not how DI declarations work in Angular. This should be:

}).run(['Analytics', function(Analytics) { }]);

Array declaration DI requires the function handler be the last item in the array. Angular was telling you that it found a string instead of a function as the last item in your array.

revolunet commented 7 years ago

good catch @justinsa 👀

should we also fix the injection for AnalyticsProvider in the README ?

harshamadala commented 7 years ago

Thanks everyone for quick replies