3

I am trying to track clicks on my site using the analytics.js script for tracking events. I implement the snippet and test using the "Real Time" view and nothing shows up. Here is the snippet I am using:

<a href="my-file-link.pdf" onClick="ga('send', 'event', {
eventCategory: 'download', eventAction: 'click', eventLabel: 'download
overview'});" target="_blank">Link</a>

I have also tried:

<a href="my-file-link.pdf" onClick="ga('send', 'event', 'download', 'click','download overview');" target="_blank">Link</a>

Anyone know what I am doing wrong?

  • Both syntaxes are acceptable. Can you install GA Debugger (Chrome) and see if the hit shows up in the dev console? Also, make sure you are not filtering out your own hits. – nyuen Dec 12 '16 at 18:22
  • This is not an answer but suggestion. Google tag manager makes it easy to Crete such events. I suggest you check it out – ledzee Dec 13 '16 at 12:48
  • How do you know they are not registering? The only place you can see them right away is in the "real time reporting" section. Otherwise you have wait 24 hours for any events you send to show up in the reporting. – Stephen Ostermiller Dec 13 '16 at 12:50
  • Is your Google Analytics snippet active? – sdhaus Dec 14 '16 at 3:18
  • Add ga('create', 'YOUR_ANALYTICS_ID', 'auto'); before the ga( 'send' function – martin schwartz Sep 18 '19 at 23:16
1

This is the event code you want to trigger -

ga('send', 'event', 'download', 'click','download overview');

However, it could be that the tracker object (in the sample above it is ga), might have been initialized with a different variable name.

For e.g the WordPress plugin Monster Insights typically initializes the tracker object as __gaTracker.

What I would do is open up your site's source code and check the name of this tracker object.

Also for all custom tracker codes put in, it might be a good idea to check if the object exists before firing this event.

if (ga) {
    ga('send', 'event', 'download', 'click','download overview');
}

Another quick method of check this script before you deploy it in your site is to run it on Developer Console of your browser and check in Google Analytics Real-time reports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.