新的Google Analytics事件跟踪无法在mailto上运行

时间:2021-09-15 15:17:00

I'm using the latest google analytics code:

我正在使用最新的Google分析代码:

(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:

但是,它没有在mailto链接上工作 - 当我在控制台中查看它说请求已被取消。这就是我正在使用的:

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

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

当我删除“mailto”时,它将跟踪。

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?

第二次编辑:它似乎与Chrome有关 - 我在Firefox和IE中测试过,当我这样做时它有效 - 其他人都经历过这个吗?

2 个解决方案

#1


8  

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

我在此处找到了一个相关主题:Google Analytics事件跟踪仅针对Chrome上的多个帐户触发

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

所以最后我得到了它与chrome一起工作 - 这就是那些感兴趣的人现在的样子:

<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:

正如Eduardo在上面指出的另一个有效的选项是具有mousedown功能:

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

#2


0  

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

Universal Analytics具有内置功能,用于延迟名为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.

没有测试过,但应该非常接近工作。谷歌周围的其他想法。

#1


8  

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

我在此处找到了一个相关主题:Google Analytics事件跟踪仅针对Chrome上的多个帐户触发

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

所以最后我得到了它与chrome一起工作 - 这就是那些感兴趣的人现在的样子:

<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:

正如Eduardo在上面指出的另一个有效的选项是具有mousedown功能:

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

#2


0  

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

Universal Analytics具有内置功能,用于延迟名为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.

没有测试过,但应该非常接近工作。谷歌周围的其他想法。