Javascript 使用 AJAX 表单进行 Google AdWords 转化跟踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2240807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google AdWords Conversion Tracking with AJAX form
提问by infinity2k9
I have a google adwords conversion tracking code that I need to implement basically on an onclick event. The form I am tracking submits information using AJAX and then renders a Thank you message to the page by replacing the form's div with the thank you HTML ( $('div').html("thank you....., etc"); )
我有一个 google adwords 转换跟踪代码,我需要在 onclick 事件上实现它。我正在跟踪的表单使用 AJAX 提交信息,然后通过将表单的 div 替换为感谢 HTML ( $('div').html("thank you....., etc") 向页面呈现感谢消息); )
I'm wondering if there's a way to a) trigger a conversion track when the SUBMIT button is clicked, or b) if I include the google script to be posted to the site in the html() function that writes to a div, will that track the conversion? or c) Any other thoughts on doing this?
我想知道是否有办法 a) 在单击“提交”按钮时触发转换跟踪,或者 b) 如果我在写入 div 的 html() 函数中包含要发布到站点的谷歌脚本,将跟踪转换?或 c) 对此有何其他想法?
I've searched a bit on this but haven't had much luck.... Thanks!
我对此进行了一些搜索,但运气不佳......谢谢!
回答by Brian D'Astous
Use an IFRAME to call an HTML file with the conversion tracking code on it.
使用 IFRAME 调用带有转化跟踪代码的 HTML 文件。
回答by Edgar Gri?ant
AFAIK the best way to do it in your scopeis using the no-script image.
AFAIK在您的范围内执行此操作的最佳方法是使用无脚本图像。
I will show you 2 ways:
我将向您展示两种方法:
You can put it on your "thank you HTML" as is, with escaped characters where necesary.
Or... Just put an empty image tag like this anywhere on your HTML document:
<img src="" width="1" height="1" style="visibility:hidden;" alt="" id="myconversion" />Then add this line of jQuery to your script before or after the your "thank you HTML":
$("#myconversion").attr("src","xxxxxxxxx");Where xxxxxxxxx is the src attribute of the no-script image.
您可以按原样将其放在“谢谢您的 HTML”上,并在必要时使用转义字符。
或者...只需在 HTML 文档的任何位置放置一个像这样的空图像标签:
<img src="" width="1" height="1" style="visibility:hidden;" alt="" id="myconversion" />然后在你的“thank you HTML”之前或之后将这行 jQuery 添加到你的脚本中:
$("#myconversion").attr("src","xxxxxxxxx");其中 xxxxxxxxx 是无脚本图像的 src 属性。
回答by Kethatril
I have heard that the iframe method is unreliable. Dynamically inserting the script does work however as the conversion script uses document.write you have to do something like this http://www.webdeveloper.com/forum/showthread.php?t=195112to load the script otherwise it doesn't work.
我听说 iframe 方法不可靠。动态插入脚本确实有效,但是因为转换脚本使用 document.write 你必须做这样的事情http://www.webdeveloper.com/forum/showthread.php?t=195112加载脚本否则它不会工作。
回答by user324074
Try dynamically inserting the tracking code in the page after the user is converted.
尝试在用户转换后在页面中动态插入跟踪代码。

