Analytics
1.8K members online now
1.8K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Code to track links attached to image not working

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am trying to track how often visitors to a website click on images assigned to a URL.  I have tried the following methods and neither seem to work.  I am not that familiar with writing code so am pulling my hair out.  Any suggestions?

 

Method One:

I have the general tracking code in the header and added the following to the link/image information. 

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify"> onclick=”ga('send', 'event', {eventCategory: ’Link’, eventAction: ’Click - Action’, eventLabel: ‘Classification’});”<img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/></a>

 

Method Two:

I added the following code to the header along with the general tracking code.

<script>
var trackOutboundLink = function(url) {
ga('send', 'event', 'Link', 'Click-Action', Classification, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>

 

Then, below the header:

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify"
onclick="trackOutboundLink('https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify');return false;
<img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/>
</a>

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Alycia C
March 2016

Re: Code to track links attached to image not working

[ Edited ]
Participant ✭ ✭ ☆
# 2
Participant ✭ ✭ ☆

Both methods should work but in both you've made some small mistakes.

This is a proper code for the first method:

 

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify" onclick="ga('send', 'event', {eventCategory: 'Link', eventAction: 'Click - Action', eventLabel: 'Classification'});"><img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/></a>

 

And this is for the second one:

 

<script>
var trackOutboundLink = function(url) {
ga('send', 'event', 'Link', 'Click-Action', 'Classification', {
'hitCallback': function(){document.location = url;}
});
}
</script>

 

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify"
onclick="trackOutboundLink('https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify');return false;">
<img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/></a>

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Alycia C
March 2016

Re: Code to track links attached to image not working

[ Edited ]
Participant ✭ ✭ ☆
# 2
Participant ✭ ✭ ☆

Both methods should work but in both you've made some small mistakes.

This is a proper code for the first method:

 

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify" onclick="ga('send', 'event', {eventCategory: 'Link', eventAction: 'Click - Action', eventLabel: 'Classification'});"><img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/></a>

 

And this is for the second one:

 

<script>
var trackOutboundLink = function(url) {
ga('send', 'event', 'Link', 'Click-Action', 'Classification', {
'hitCallback': function(){document.location = url;}
});
}
</script>

 

<a href="https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify"
onclick="trackOutboundLink('https://www.zooniverse.org/#/projects/kosmala/season-spotter-questions/classify');return false;">
<img src="images/MultipleChoice_175x175.png" alt="" class="gallery"/></a>

Re: Code to track links attached to image not working

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

This is still not working for me. Once the code is updated, should Google Analytics start capturing the event immediately?

 

I have this basic code in the header for method one.  Should there be more added to track the event?  Thank you so much for your help.  I've been working on this all day....ugh

 

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-72169903-1', 'auto');
  ga('send', 'pageview');
</script>

</head>

 

Re: Code to track links attached to image not working

Participant ✭ ✭ ☆
# 4
Participant ✭ ✭ ☆
Did you check Real-Time > Events report?

Re: Code to track links attached to image not working

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
I did. Nothing is displaying there or in Behavior->Events

Re: Code to track links attached to image not working

Participant ✭ ✭ ☆
# 6
Participant ✭ ✭ ☆
Could you share your website URL?

Re: Code to track links attached to image not working

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
It's seasonspotter.org. I have a colleague trying to help me this morning as well. Will let you know if we get it figured out.

Re: Code to track links attached to image not working

Participant ✭ ✭ ☆
# 8
Participant ✭ ✭ ☆

The code is ok. And when I clicked the link, data was sent to Google Analytics server.

So everything should work fine. Check again Behavior > Events > Top Events report for today or yesterday.

 

debug.png

Re: Code to track links attached to image not working

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
It is working! It seems there was just a delay in the data going into Analytics so data from yesterday showed up this morning. Thanks for your help!!