0

I am attempting to track outbound link clicks with Google Analytics (GA). Basic page logging works with GA. In my development environment, outbound link tracking works.

Here is the script I have in my base page:

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

Here is an example anchor tag:

<a href="http://www.example.com/" onclick="trackOutboundLink('http://www.example.com'); return false;">Example Site</a>

I am running the site on a Digital Ocean app using nginx and gunicorn.

When a link is clicked, the status bar on the banner shows traffic to GA and then the browser is redirected to the original page with the link url appended to it.

https://original-site.com/slug_of_page/www.example.com

This generates a 404

This is not a duplicate question as the question cited is the code I am using almost verbatim.

Dan S.
  • 162
  • 2
  • 13

0 Answers0