Javascript 如何跟踪 Google Adwords 的 onclick 转化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2082129/
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
How to track a Google Adwords conversion onclick?
提问by janpio
Google Adwords offers no code to add to your page to count a conversion if somebody clicks on a link. But as it's Javascript, I am sure there is a way to do this.
如果有人点击链接,Google Adwords 没有提供任何代码来添加到您的页面以计算转化。但由于它是 Javascript,我相信有一种方法可以做到这一点。
Here's the code (unaltered) Google gives you to include in the page, that should count as a conversion (most of the time a thank you page):
这是 Google 提供给您的页面中包含的代码(未更改),这应该算作一次转换(大多数情况下是感谢页面):
<!-- Google Code for Klick Conversion Page -->
<script type="text/javascript">
<!--
var google_conversion_id = 1062751462;
var google_conversion_language = "de";
var google_conversion_format = "1";
var google_conversion_color = "ffffff";
var google_conversion_label = "dKXuCODvugEQ5pnh-gM";
var google_conversion_value = 0;
//-->
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1062751462/?label=dKXuCODvugEQ5pnh-gM&guid=ON&script=0"/>
</div>
</noscript>
With other conversion tracking scripts some function has to be executed to count the conversion. Here, just adding the JS-File to your page can be enough to trigger the conversion-tracking, as conversion.js calls a function on load (download it and look at it after running it through a code beatuifier, it's really quite nice work!).
对于其他转换跟踪脚本,必须执行一些函数来计算转换。在这里,只需将 JS 文件添加到您的页面就足以触发转换跟踪,因为 convert.js 在加载时调用一个函数(下载它并在通过代码优化器运行后查看它,这真的是非常好的工作!)。
Any idea how to tackle this?
知道如何解决这个问题吗?
回答by Eli
Don't know if you've already found it... I mention it anyway for future surfers...
不知道你是否已经找到了它......无论如何我都会提到它给未来的冲浪者......
I was looking for the same, and found this piece of code :
我正在寻找相同的内容,并找到了这段代码:
<script type="text/javascript">
function trackConv(google_conversion_id, google_conversion_label) {
var image = new Image(1, 1);
image.src = "//www.googleadservices.com/pagead/conversion/" + google_conversion_id + "/?label=" + google_conversion_label + "&script=0";
}
</script>
Then for links which you want to track just do this :
然后对于您要跟踪的链接,只需执行以下操作:
<a onclick="trackConv(1234567890, 'LQV8CNq6RxCKlPbvAw');" href="http://www.example.com">Link</a>
回答by Jonathan Guerrera
It appears that Google now offers an onclick option that you can copy and paste from the Conversions page in AdWords. From the AdWords Conversions page:
看来 Google 现在提供了一个点击选项,您可以从 AdWords 的“转化”页面复制和粘贴该选项。从 AdWords 转化页面:
Add the tag to a button on your website, such as a "Buy now" button.
将标签添加到您网站上的按钮,例如“立即购买”按钮。
Here's a snippet from the page of documentation entitled Track clicks on your website as conversions. Replace XXXXX with conversion ID and label:
以下是标题为将您网站上的点击次数作为转化进行跟踪的文档页面的片段。将 XXXXX 替换为转化 ID 和标签:
<!-- Google Code for Conversion Page
In your html page, add the snippet and call
goog_report_conversion when someone clicks on the
chosen link or button. -->
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = XXXXXXX;
w.google_conversion_label = "XXXXXXX";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
}
}
var conv_handler = window['google_trackConversion'];
if (typeof(conv_handler) == 'function') {
conv_handler(opt);
}
}
/* ]]> */
</script>
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
And somewhere else in your code
在你的代码中的其他地方
button.addEventListener('click', function() {
console.log('Button clicked!');
goog_report_conversion();
});
回答by Irshad Khan
Google Conversion Tracking concept using Ajax on a submit button :
在提交按钮上使用 Ajax 的 Google 转化跟踪概念:
$.ajax({
type: "POST",
url: "enquiry-submit.php",
data: data,
success: function (result) {
$("#msg").fadeIn(400).html(result);
/* Conversion Tracking Start */
var google_conversion_id = YOUR_CONVERSION_ID_HERE;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "YOUR_CONVERSION_LABEL_HERE";
var google_remarketing_only = false;
$.getScript('//www.googleadservices.com/pagead/conversion.js');
var image = new Image(1, 1);
image.src = "//www.googleadservices.com/pagead/conversion/YOUR_CONVERSION_ID_HERE/?label=YOUR_CONVERSION_LABEL_HERE&guid=ON&script=0";
/* Conversion Tracking End */
}
});
It is 100% working on my Google Ads Campaign.
我的 Google Ads 广告系列 100% 正在发挥作用。
Note: You must Test this by clicking on your ad. The effect of conversion will be visible after 12 minute on your AdWords Console
注意:您必须通过点击您的广告进行测试。12 分钟后,您将在 AdWords 控制台上看到转化效果
回答by Bruno Brand?o
I've a similar problem.
我有类似的问题。
The Problem: My client have a contact page that have a form. After the user fill all the form fields, there is a validation(to check if the user filled correctly all the fields). After the validation, the user is redirected to the webmail server page. There isn't an "Success" or "Thank You" page. So i needed to put the Adwords tag, after the form validation.
问题:我的客户有一个带有表单的联系页面。用户填写所有表单字段后,将进行验证(检查用户是否正确填写了所有字段)。验证后,用户将被重定向到 webmail 服务器页面。没有“成功”或“谢谢”页面。所以我需要在表单验证之后放置 Adwords 标签。
The Solution:
解决方案:
The validation was done this way:
验证是这样完成的:
var missinginfo = "";
var f = document.forms["CONTACT"];
if (f.name.value == ""){
missinginfo += "\n - name";}
.
.
.
if (missinginfo != "")
{
missinginfo ="_____________________________\n" +
"Empty Field" + "incorrectly filled" +
missinginfo + "\n_____________________________"
alert(missinginfo);
return false;
}
//End of Validation
So i added this snippet code:
所以我添加了这个片段代码:
else if(missinginfo == ""){ //Check if the form was filled correctly
adw_conv(); //Function Name
return false;
}
function adw_conv(){
var img = new Image() //Creates an image using JS to make the request
img.src = "http://www.googleadservices.com/pagead/conversion/123456789/?label=-8bcaCNHv6AIQl_v8_QM&guid=ON&script=0";
img.onload = function(){
var form = document.getElementsByName('CONTACT')[0];
form.submit();
}}
This way, after the form validation and before the website redirect the user to the webmail page, is triggered the Adwords Conversion!
这样,在表单验证之后和网站将用户重定向到 webmail 页面之前,就会触发 Adwords 转换!
回答by Dave Davis
Add the code below to the section of the page you want to track conversions on.
将下面的代码添加到您要跟踪转化的页面部分。
<script>
function adwTrack() {
var img = new Image(1,1);
img.src = "https://www.googleadservices.com/pagead/conversion/XXXXXXXXXX/?value=1.00&currency_code=EUR&label=XXXXXXXXXX&guid=ON&script=0";
}
}
Just replace the XXX… with your actual conversion id and label.
只需将 XXX... 替换为您的实际转化 ID 和标签。
Then call the adwTrack() function we created above in your link's onclick event:
然后在您的链接的 onclick 事件中调用我们上面创建的 adwTrack() 函数:
<a href="#" onclick="adwTrack();">Track This</a>
You can also do this using GTM: https://www.redflymarketing.com/blog/track-conversions-without-a-thank-you-page/
您也可以使用 GTM 执行此操作:https: //www.redflymarketing.com/blog/track-conversions-without-a-thank-you-page/

