2010-12-20 102 views
1

我試圖跟蹤與Google Analytics的電子郵件鏈接,但由於某些原因,它不起作用。 這裏是我的代碼:分析 - 電子郵件跟蹤

<script type="text/javascript"> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'xxxxxx']); 
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

</script> 

,這裏是在網頁源代碼中的onClick功能:

<a href="mailto:[email protected]" onClick="_gaq.push(['_trackEvent', 'Index','Klik - email','[email protected]']);">[email protected]</a> 

我試過相同的跟蹤其他網頁上的鏈接和它的工作。在我安裝GA調試後,我發現當我跟蹤mailto鏈接時,出現錯誤 - 無法加載資源:mailto:[email protected]

有人有任何想法,爲什麼有一個錯誤以及如何解決它? 感謝

+0

只是因爲GA調試說它的錯誤並不意味着它沒有跟蹤。出現此錯誤時,「mailto:」鏈接是否停止工作?你是否在GA中獲得跟蹤的事件?我試過這段代碼,它可以很好地處理GA調試。 – Yahel 2010-12-20 15:38:06

回答

0

大膽猜測:

請問您的onClick的內容,甚至解決它之前添加javascript:

<a href="mailto:[email protected]" onClick="javascript:_gaq.push(['_trackEvent', 'Index','Klik - email','[email protected]']);">[email protected]</a> 
+0

不......沒有幫助 – JanyC 2010-12-20 14:53:19

+1

不可能做任何事情。添加'javascript:'的唯一做法是將執行上下文從本地更改爲全局,這對使用'this'關鍵字至關重要。 http://stackoverflow.com/questions/2479557/why-is-it-bad-practice-to-use-links-with-the-javascript-protocol – Yahel 2010-12-20 15:39:50

+0

感謝您的信息。無論如何,我經常'瘋狂'錯誤:D – 2010-12-23 16:58:26

0

我假設這些鏈接將在電子郵件客戶端(如outlook和Gmail)中可見。大多數(如果不是全部的話)電子郵件客戶端在顯示電子郵件之前將所有JavaScript從電子郵件中刪除 如果您想跟蹤電子郵件打開和其他此類信息,唯一的選擇是使用像素跟蹤方法。

相關問題