How do I make use of the google analytics global object (GA). According to the Analytics documentation the default analytics implementation creates a global object called ga.
I'm trying to add some custom onClick handlers to some of the links on a page that send custom google analytics events.
Something like:
<a href="mailto:contactemail" onClick="ga('send', 'event', 'MailtoEmail', 'Click', 'ContactPage');">Email link</a>
But unfortunately I only get an error in the JS console:
Uncaught ReferenceError: ga is not defined.
This is using the latest version of the google analytics module on Drupal 7. Am I missing something?
I do see the options to add js code under the advanced settings, but those appear to be run once per page. If I were to use that, how would I apply this event tracking to individual links?
Comments
Comment #1
JemBijoux commentedComment #2
hass commentedThat looks like http://cgit.drupalcode.org/google_analytics/tree/googleanalytics.js?h=7.... and this is also the example I can give you.
No idea why this does not work. You need to try to find out. You are adding GA to head, aren't you?
You know that email tracking is already build into the module?
Comment #3
JemBijoux commentedUgh. Haha, you are totally right.
It's working fine, what happened was GA was set to ignore tracking for certain roles, and I was testing as an administrator. I didn't originally put two and two together. Your comment (and maybe sleeping on it) helped me make that realization.
Thanks.