revolunet / angular-google-analytics

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

Analytics is not defined #168

Closed m98 closed 8 years ago

m98 commented 8 years ago

I read your documentation. that is really complete and nice, but I have a problem

Here is my config inside a App.run()

App.config(function (AnalyticsProvider) {
            //Add configuration code as desired - see below
            AnalyticsProvider
                .logAllCalls(true)
                .setAccount(my_code_is_here)
                .trackPages(true)
                .trackUrlParams(true)
                .delayScriptTag(true)
                .readFromRoute(true);
        });

It is not working, when I go and see my Analytics account, it is not counting my visits!

I thought I need to call Analytics.pageView(), but it returns error which is:

Uncaught ReferenceError: Analytics is not defined

It is not working at all. But I added Google Analytics script and it can show I am online now, but it is not working when I change routes (And I think this is not the standard way):

       (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','https://www.google-analytics.com/analytics.js','ga');

        ga('create', my_code_is_here, 'auto');
        ga('send', 'pageview');

May I know; what is my problem? And what should I do?

Toxantron commented 8 years ago

You must call config before calling run and then you can inject Analytics into run or your controllers.

Please see #135 as well.