AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2.1K members online now
2.1K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Clicks to <a> elements don't show up.

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm trying to track downloads with a JS onclick event, and only 3 out of my 5 possible events are getting through.  I can see them go out in Chrome's dev tools, and I've tried 'plain vanilla' IE with no adblockers or other funny business.

 

The events are all like:

 

<a onclick="ga('send', 'event', 'Education Kits', 'Downloaded', 'Whole kit', '0');"
    href="http://mypublicsite.net/wp-content/uploads/2015/06/FF_Whole_Kit.pdf">
</a>

 

That all look on the up-and-up?  What are my next steps?

 

Thanks for the help...

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Greg B
October 2016

Only some events showing, even after 72 hours.

Explorer ✭ ✭ ☆
# 2
Explorer ✭ ✭ ☆

Hi @Greg B

 

Since you're tracking clicks on links with a javascript, you have to be aware that many browsers will stop executing javascript when the new page (in this case a pdf file) begins loading.

 

In order to ensure correct tracking, you will have to either...:

 

1) Write an event handler function to delay load of the new page until the Analytics script has fired

2) Use the transport beacon feature

 

 

Also see the official documentation on outbound link tracking:

https://developers.google.com/analytics/devguides/collection/analyticsjs/events#outbound_link_and_fo...

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Greg B
October 2016

Only some events showing, even after 72 hours.

Explorer ✭ ✭ ☆
# 2
Explorer ✭ ✭ ☆

Hi @Greg B

 

Since you're tracking clicks on links with a javascript, you have to be aware that many browsers will stop executing javascript when the new page (in this case a pdf file) begins loading.

 

In order to ensure correct tracking, you will have to either...:

 

1) Write an event handler function to delay load of the new page until the Analytics script has fired

2) Use the transport beacon feature

 

 

Also see the official documentation on outbound link tracking:

https://developers.google.com/analytics/devguides/collection/analyticsjs/events#outbound_link_and_fo...

Re: Only some events showing, even after 72 hours.

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

That's a big help, thanks Phillip.

 

1) Write an event handler function to delay load of the new page until the Analytics script has fired

 

For future Googlers, the document Phillip linked to points to a section of the docs about how to do this using a callback passed to ga.

 

2) Use the transport beacon feature

For browser support, see here.

 

Seems undesirable to have events go unregistered just because the user's using a browser that doesn't support beacon transport.  So, I'll be opting for the callback method.

 

Note also that setting _target=blank prevents the browser from stopping JS, so if that behavior's OK, that's an easy fix.

 

Thanks again!