4

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' );
}
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Crashalot
  • 33,605
  • 61
  • 269
  • 439

4 Answers4

4
_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.

Yahel
  • 37,023
  • 22
  • 103
  • 153
  • thanks. this is the confusing part since some twitter events do come through. just not all of them. any thoughts? – Crashalot Jul 14 '13 at 05:18
  • Can you provide screenshots of what you're seeing in your reporting? What happens when you drill down into the Category? What do you see with the Action? – Yahel Jul 14 '13 at 14:21
  • nm, we're idiots. the events were never coming through. i think your solution fixes things. – Crashalot Jul 15 '13 at 08:59
2

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.

tafh
  • 181
  • 4
1

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.

Community
  • 1
  • 1
Martin Magakian
  • 3,746
  • 5
  • 37
  • 53
1

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

Carl Mastrangelo
  • 5,970
  • 1
  • 28
  • 37
  • the docs, and according to someone else here, appear to say that the third argument is required? – Crashalot Jul 19 '13 at 07:48
  • Yes, you are right it is required. Unfortunately you probably can't leave it empty and have it work reliably. Perhaps it should read: _gaq.push( ['_trackEvent', 'Share', 'Twitter'] ); – Carl Mastrangelo Jul 20 '13 at 04:58