简体   繁体   中英

Google Analytics not tracking events in HTML5 mobile app properly on iPhones

We are using Google Analytics to track events, but events don't appear to track 100% of the time. Sometimes they track, and sometimes they don't. We're not exceeding quota limits per session (at most we have 20 events per session). That shouldn't be the issue.

The tracking fails to work consistently on our normal website as well as our HTML5 mobile app version, though it's far less reliable with the HTML5 mobile app version.

Code:

var share_url = 'http://twitter.com/intent/tweet?text=';        

// Log in GA
_gaq.push( ['_trackEvent', 'Share Twitter', ''] );

// Open URL in browser
open_external( share_url + encodeURIComponent( msg ) );


function open_external( url ) {
    window.open( url + '#phonegap=external' );
}
_gaq.push( ['_trackEvent', 'Share Twitter', ''] );

This won't do anything.

For _trackEvent , the third argument (where you pass an empty string) is required . It's the 'Action' parameter. But an empty string is falsey, so it just fails silently.

Pass any value there, and it'll work.

Is this a reduced case? You shouldn't be seeing any events with that code.

Are you positive that you waited long enough for the data to be processed by Google? Especially since some tracking seems to be working. I had the same behaviour (in a mobile app btw) but after waiting for more than a day it still came through. This still occurs on a daily basis... Hope this is the case for you too.

I'm not exactly sure what your problem can be, so I will throw some idea. Most of them are obvious but it might help.

On your website:

  • Are you sure your embed the Google Analytics code snippet on every page who required tracking?
  • Load Google analytics from the asynchronous way .
  • On Google analytics check on Real time > Overview. As full report are delayed from few hours.
  • If you url is something like httq://localhost/ then your need to add the javascript code _gaq.push(['_setDomainName', 'none']); please read this post
  • It can't work with file:// url
  • (Probably not) Check if you can download the JavaScript from Google Analytics. Maybe your proxy block Google analytics tracking ?


In your application:

  • You are using embedded HTML 5 page within your app. So the way your open a page is using file://PATH_TO_MY_DIR/index.html as it's on your hard drive you can't send data to Google analytics.
  • As you are probably using PhoneGap, you need to "jump out" of your HTML page into native Objective-c code and send the event from your Objective-C code. Read Google Analytics and PhoneGap and this google group thread


Hope it help.

The problem is third parameter in:

_gaq.push( ['_trackEvent', 'Share Twitter', ''] );

The 2nd element of the array should be the category and the 3rd should be the action. For example:

_gaq.push( ['_trackEvent', 'Share', 'Twitter'] );

You can verify this yourself by pasting each of the above into your developer console (F12 in Chrome, Ctrl-Shift-K in Firefox) and watching the network traffic.

Reference:

https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM