2015-10-13 111 views
2

美好的一天, 我正在嘗試爲我的網站配置AdWords轉換代碼,但在Google文檔中找不到我要查找的任何信息。最後,我想跟蹤表單提交輸入中的onClick事件。表單上的Google AdWords轉換跟蹤發送

我想知道我應該在我的onClick事件中包含什麼,因爲發送按鈕不會導致另一個頁面,但有一個AJAX加載?

我的AdWords跟蹤代碼爲:

<script type="text/javascript"> 
 
    /* <![CDATA[ */ 
 
\t goog_snippet_vars = function() { 
 
\t  var w = window; 
 
\t  w.google_conversion_id = 12345678; 
 
\t  w.google_conversion_label = "abcDeFGHIJklmN0PQ"; 
 
\t  w.google_remarketing_only = false; 
 
\t } 
 
\t // DO NOT CHANGE THE CODE BELOW. 
 
\t goog_report_conversion = function(url) { 
 
\t  goog_snippet_vars(); 
 
\t  window.google_conversion_format = "3"; 
 
\t  window.google_is_call = true; 
 
\t  var opt = new Object(); 
 
\t  opt.onload_callback = function() { 
 
\t  if (typeof(url) != 'undefined') { 
 
\t  window.location = url; 
 
\t  } 
 
\t } 
 
\t var conv_handler = window['google_trackConversion']; 
 
\t if (typeof(conv_handler) == 'function') { 
 
\t  conv_handler(opt); 
 
\t } 
 
\t } 
 
    /* ]]> */ 
 
</script> 
 
<script type="text/javascript" 
 
    src="//www.googleadservices.com/pagead/conversion_async.js"> 
 
</script>

回答

4

最終,我一直在尋找轉化爲被保存僅如果窗體成功地發送(JavaScript驗證之後)。我無法使用按鈕上的onClick,因爲即使表單由於字段中的值無效而導致表單未被取消,也可以保存轉換。

這樣做最簡單的方法,就是在jQuery的補充一點:

$('#contactform').submit(function(e){ 
    if($(this).valid()) { 
     goog_report_conversion ('http://example.com/your-link') // Change for your page link. 
     alert("Conversion!"); // Confirmation that the conversion has been sent. Remove after testing. 
    } 
}); 
0

可以的無腳本版本負荷,。

因此,在你的onClick事件中,將img附加到頁面上的某個元素,它將加載它並計算轉換。

1

我想這太晚了,但爲了後代。 AdWords有一種內置的方式來執行此操作。 它被描述爲in this article

簡而言之,您需要更改AdWords中的設置,它會生成您使用DOM加載的異步代碼,並使用onClick處理程序進行激活。


實施例:

<a onclick="goog_report_conversion ('http://example.com/your-link')" 
href="http://example.com/your-link">Download now!</a> 
相關問題