angularjsgoogle-analyticsangulartics

Error integrating Angulartics


I´m trying to integrate Angulartics in my AngularJS 1.0.7 web app for Google Analytics. When trying to load the main page I get this error:

Uncaught TypeError: undefined is not a functionangulartics.min.js:6 (anonymous function)angular.js:2892 invokeangulartics.min.js:6 (anonymous function)angular.js:2895 invokeangular.js:2744 (anonymous function)angular.js:130 forEachangular.js:2744 createInjectorangular.js:978 resumeBootstrapInternalangular.js:993 bootstrapangular.js:954 angularInitangular.js:14843 (anonymous function)jquery-1.10.2.min.js:4 x.Callbacks.cjquery-1.10.2.min.js:4 x.Callbacks.p.fireWithjquery-1.10.2.min.js:4 x.extend.readyjquery-1.10.2.min.js:4 q

I have added the modules like this:

angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers', 'myApp.i18n', 'myApp.properties', 'angularSpinner', 'ngCookies', 'ngSanitize', 'ngProgress', 'angularMoment', 'tmh.dynamicLocale', 'angulartics', 'angulartics.google.analytics'])
  .config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider, $routeParams) {...}

I have included the javascript plugins:

<!-- Angulartics -->
    <script src='lib/plugins/angulartics.min.js'></script>
    <script src='lib/plugins/angulartics-ga.min.js'></script>

And finally added the Google tracking snippet code (commenting the last line):

<script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-59702007-1', 'auto');
      // Removed requested by Angulartics (see doc) ga('send', 'pageview');

    </script>

Solution

  • Finally solved it by using Angularytics instead of Angulartics. I had no integration dependencies issues.