Firefox does not trigger hitCallback in Google Analytics while tracking outbound links

StackOverflow https://stackoverflow.com/questions/23482090

  •  16-07-2023
  •  | 
  •  

سؤال

I read a lot of tutorials how to measure outbound links with Google analytics.. I have this code:

<a onclick="return trackOutboundLink(this);" href="google.com" target="_blank">
   link
</a>

And this is at the bottom of my site:

<script type="text/javascript">

(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-XXXXXX-6', 'my-site.tld');
ga('send', 'pageview');

trackOutboundLink = function(o) {
  ga('send', 'event', "outbound", "click", o.href, {'hitCallback': function() {
      alert("OK");  
    }
  });
 return true;
}

</script> 

In google chrome it works like a charm - I click on the link and alert is fired + new tab is openned.

But in Mozzila Firefox it doesn't work.. I guess that google send data, but never trigger callback..

Am I missing something?

هل كانت مفيدة؟

المحلول

Problem was with Firefox Adblock plugin which was blocking google analytics requests

نصائح أخرى

The following article explains how to implement this without breaking things for users who use AdBlock or similar tools:

http://veithen.github.io/2015/01/24/outbound-link-tracking.html

Try removing the return from the onclick, and adding return false; after you call your function.

<a onclick="trackOutboundLink(this); return false;" href="google.com" target="_blank">
   link
</a>

Also, remove return true; to your trackOutboundLink function.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top