Google Analytics: how to track outgoing links that open on a new tab?

I have a number of outbound links on a website that I hope to track using Google Analytics (analytics.js).

Google 's outbound link tracking docs are clear, and the implementation they offer works for me. The problem is with links opened in a new tab / window . Google suggests opening links through a callback function that updates document.location as soon as the tracking event is sent to GA. But this, obviously, will not open the links in a new tab. And, importantly, using window.open instead becomes a victim of pop-up blockers.

This is Google's proposed implementation:

<script>
var trackOutboundLink = function(url) {
   ga('send', 'event', 'outbound', 'click', url, {'hitCallback':
     function () {
     document.location = url;
     }
   });
}
</script>

, , Google , , , - .

+4
1

, . . , . , / , click .

, /, script, Google Analytics. :

  • mousedown href JavaScript. http://example.com /yourTrackingScript?gaCategory=Something&gaEvent=Click&gaLabel=SomeLink&url=http%3A%2F%2Fexample.com. , mousedown, - , /, script . Google .
  • /yourTrackingScript Google Analytics, .
  • /yourTrackingScript 302 URL, .
  • , , .
+9

All Articles