Question

I'm using the latest Google Analytics code:

(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', 'XXXXXXXXX', 'XXXXXXXX');   
      ga('send', 'pageview');

I've got event tracking to work on a download link using the following:

<a href="#" onclick="ga('send', 'event', 'Download', 'PDF', 'FILE NAME');">

However, it's not working on a mailto link - when I look in the console it says the request has been cancelled. This is what I'm using:

<a href="mailto:email@address.com" onclick="ga('send', 'event', 'Contact', 'Email', 'Name here');">

When I remove the "mailto" it will then track.

Am I setting it up wrong?

EDIT: It appears if I put a target="_blank" it will work - however it then opens up another window which isn't ideal.

Second Edit: It appears it's something to do with Chrome - I tested it in Firefox and IE and it worked when I did that - anyone else experienced this?

Was it helpful?

Solution

I found a relevant thread here: Google Analytics Event Tracking not firing for multiple accounts on Chrome ONLY

So in the end I got it working with chrome - this is how it looks now for those interested:

<a onclick="setTimeout(function(){ga('send', 'event', 'Email', 'Person Name');}, 1500);" href="mailto:email@address.com" >

A timeout function had to be added.

As Eduardo pointed out above another option that worked was having a mousedown function:

<a onmousedown="ga('send', 'event', 'Email', 'Person Name');" href="mailto:email@address.com" >

OTHER TIPS

Universal Analytics has built-in functionality for delaying sends called hitCallback.

ga('send', 'event', 'Contact', 'Email', 'Name here', {
  'hitCallback': function() {
    document.location.href = this.href
  }
});

Haven't tested it, but should be pretty close to working. Google-around for other ideas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top