mgonto / angularytics

The solution to tracking page views and events in a SPA with AngularJS
MIT License
630 stars 70 forks source link

How to run in cordova/phonegap app? #29

Open bcarvalho89 opened 10 years ago

bcarvalho89 commented 10 years ago

I developed an application in phonegap and deployed your plugin. When open on desktop, works well, I can see the hits in real time through the google panel. But to compile and test the application on android, does not appear the hits.

Is there any thing can do?

Thank you.

andymac4182 commented 10 years ago

Hi,

This is one that I am looking at currently. If someone could point me in the right direction I am happy to help with the changes required.

Cheers

andymac4182 commented 10 years ago

After doing some new research it appears this has been fixed with Tasks in the new analytics.js

ga('set', 'checkProtocolTask', null); // Disable file protocol checking.

https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks

bcarvalho89 commented 10 years ago

Hello. I put this in my index.html (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-48718316-3', { 'cookieDomain': 'none' }); ga('set', 'checkProtocolTask', null); // Disable file protocol checking. and this in my app.js angular.module('starter', ['angularytics']) .config(function(AngularyticsProvider) { AngularyticsProvider.setEventHandlers(['Console', 'GoogleUniversal']); }).run(function(Angularytics) { Angularytics.init(); }) I can see the console log message URL visited /tab/dash, but nothing happens in google real time panel.

andymac4182 commented 10 years ago

Here is what I added to my index.html and i have confirmed with Google Analytics real time that it is working perfectly.

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

    ga('create', 'UA-54191237-1', 'auto');
    ga('set', 'checkProtocolTask', null);
andymac4182 commented 10 years ago

Need an init for the trackers so that you can set these values.

bcarvalho89 commented 10 years ago

Sorry, but I used the same code that you put up and still not working. Can you explain me what would that init? Or if you can, see my codes in http://pastebin.com/BqsZ5a22

Thanks for your help.

ultrawebsites commented 10 years ago

@bhrun Have you tried adding <access origin="*://*.google-analytics.com/*" subdomains="true" /> to your config.xml? Worth a shot.

@andymac4182 When you say it's working perfectly, are you referring to when browsed via a web browser, or when used in PhoneGap? If PhoneGap, what version are you using?

andymac4182 commented 10 years ago

I used Cordova 3.5.1 through Telerik Appbuilder.

niyando commented 8 years ago

@andymac4182

ga('set', 'checkProtocolTask', null);

indeed works. :+1:

I also had to prepend https: to //www.google-analytics.com/analytics.js so that it doesn't try to load with file:// protocol.

Thank you. :beers: