3

我使用的是最新的谷歌分析代碼:新的谷歌Analytics(分析)事件追蹤不會對郵寄地址工作

(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'); 

我已經得到了事件跟蹤使用下載鏈接的工作如下:

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

但是,它並不適用於mailto鏈接 - 當我查看控制檯時,它表示請求已被取消。這是我正在使用的:

<a href="mailto:[email protected]" onclick="ga('send', 'event', 'Contact', 'Email', 'Name here');"> 

當我刪除「mailto」它會跟蹤。

我是否設置錯了?

編輯:它出現,如果我把一個目標=「_ blank」它將工作 - 但它然後打開另一個不理想的窗口。

第二編輯:看起來這是與Chrome有關的事情 - 我在Firefox和IE中測試過它,當我這樣做時它就起作用 - 其他任何人都經歷過這種情況?

+1

您是否嘗試過使用'onmousedown'而不是'onclick'? – Eduardo

+1

嗨愛德華多 - 我試過onmousedown,它的工作 - 謝謝你!這對我來說似乎是最好的解決方案,因爲您不需要額外的標記! – user1788364

回答

8

我發現了一個相關的線程在這裏:Google Analytics Event Tracking not firing for multiple accounts on Chrome ONLY

所以我把它與鉻工作結束 - 這是它現在的樣子對於那些有興趣:

<a onclick="setTimeout(function(){ga('send', 'event', 'Email', 'Person Name');}, 1500);" href="mailto:[email protected]" > 

超時功能必須是添加。

正如愛德華指出,上述的另一種選擇是工作是有一個鼠標按下功能:

<a onmousedown="ga('send', 'event', 'Email', 'Person Name');" href="mailto:[email protected]" > 
0

通用Analytics(分析)還內置了延遲發送功能被稱爲hitCallback

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

沒有測試過它,但應該非常接近工作。谷歌周圍的其他想法。

相關問題