ggendre / GALocalStorage

A google analytics version that works with localstorage instead of cookies for webviews usage (deprecated)
114 stars 46 forks source link

Not working on phonegap... #21

Closed NaxYo closed 9 years ago

NaxYo commented 9 years ago

I'm getting troubles to make it works under phonegap (cordova v3.6.3). It throws no errors, but I never get the trackPageview on my analytics dashboard. If I try the same app on my desktop browser (or even in a mobile browser) it works perfect, but if I try it on phonegap app, nothing happen.

I went through the trackPageview function and I add a some debug lines between lines 322 and 323, so I can debug it a little:

var img = new Image();
if(IS_DEBUG) {
    console.log(url);
    img.onerror = function() { alert('Error'); };
}
img.src = url;

I always get the error alert, but if I use the given url on any browser it works. The first thowt was that phonegap was getting some cross origin error, so I add:

    <access origin="http://*.google-analytics.com"/>
    <access origin="https://*.google-analytics.com"/>

But it's still not working (and logcat didn't tell a thing about cross origin)...

Any Idea? Thanks!

NaxYo commented 9 years ago

Solved!

It's an Phonegap / Android problem. Phonegap is supposed to have full internet access by default... it puzzled me because I could access to my API, but the true was that the permissions were wrong.

Solution (AndroidManifest.xml):

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.NETWORK_ACCESS" />