同一页面上有多个 Google Adwords 转化标签

发布于 2024-12-19 06:17:24 字数 1016 浏览 0 评论 0原文

我可以在一个网页上使用多个 Google AdWords 转化标签吗?看起来 javascript 变量只会互相覆盖。

如果我删除 javascript 变量并只保留 noscript 链接会怎么样?

转换 1

var google_conversion_id = 123;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "666666";
var google_conversion_label = "abc";
var google_conversion_value = 0;

转换 2:

var google_conversion_id = 456;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "000000";
var google_conversion_label = "def";
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/..."/>

</div>

Can I have more than one google adwords conversion label on a single web page? It looks like the javascript variables would just overwrite each other.

What if I remove the javascript variables and just keep the noscript link?

conversion 1

var google_conversion_id = 123;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "666666";
var google_conversion_label = "abc";
var google_conversion_value = 0;

conversion 2:

var google_conversion_id = 456;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "000000";
var google_conversion_label = "def";
var google_conversion_value = 0;

followed by script tag:

<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script>

and sample noscript tags:

<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/..."/>

</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月静好 2024-12-26 06:17:24

对我们有用的只是包含整个代码块(包括

What worked for us was just including the entire block of code (including the <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script> tag itself) twice. Because the script tag contains code which is executed immediately, including it twice will cause it to execute twice - each time using the variables declared immediately before it.

口干舌燥 2024-12-26 06:17:24

JavaScript 函数。

var goog_report = function(id, label, value){
    if(typeof(value)==='undefined') value = 0;
    var base_url = 'www.googleadservices.com/pagead/conversion/';
    var img = new Image(1,1);
    img.src = base_url + id +'/?label='+label+'&value='+ value +'&script=0';
};

设置您的 Google 变量。

var goog_id = 1234;
var goog_label = 'xyz';
var goog_value = 10.99;

示例 1:在 HTML 中调用。

<script>
goog_report(goog_id, goog_label, goog_value);
</script>

示例 2:在事件处理程序中调用。

<script>
var handleSomeEvent = function(evt) {
    goog_report(good_id, goog_label, goog_value);
};
</script>

示例3:jQuery Ajax 成功调用后调用。

<script>
$.ajax({
    type: "POST",
    url: "/charge/",
    data: $('form').serialize(),
    success: function(data) {
        goog_report_purchase(goog_id, goog_label, data.charge_amount);
    }
});
</script>

示例 4:锚点元素上的硬编码 OnClick 事件

<a href="javascript:;" onclick="goog_report(1234, 'xyz', 10.99)">Boom! Conversion.</a>

The Javascript function.

var goog_report = function(id, label, value){
    if(typeof(value)==='undefined') value = 0;
    var base_url = 'www.googleadservices.com/pagead/conversion/';
    var img = new Image(1,1);
    img.src = base_url + id +'/?label='+label+'&value='+ value +'&script=0';
};

Set your Google variables.

var goog_id = 1234;
var goog_label = 'xyz';
var goog_value = 10.99;

Example 1: Call within HTML.

<script>
goog_report(goog_id, goog_label, goog_value);
</script>

Example 2: Call within an event handler.

<script>
var handleSomeEvent = function(evt) {
    goog_report(good_id, goog_label, goog_value);
};
</script>

Example 3: Call after jQuery Ajax success call.

<script>
$.ajax({
    type: "POST",
    url: "/charge/",
    data: $('form').serialize(),
    success: function(data) {
        goog_report_purchase(goog_id, goog_label, data.charge_amount);
    }
});
</script>

Example 4: Hard-coded OnClick event on Anchor Element

<a href="javascript:;" onclick="goog_report(1234, 'xyz', 10.99)">Boom! Conversion.</a>
轻许诺言 2024-12-26 06:17:24

请注意,自 2017 年 10 月起,您可以(并且应该)使用 Google 的新 gtag.js,这是一个新的网络标记库,取代了旧的 AdWords 网站转化跟踪和再营销标记。

gtag.js 允许您将跟踪数据发送到多个 AdWords 帐户,方法是为您将使用的每个帐户添加对“config”命令的调用,并指定每个帐户的转化 ID:

<!-- Global Site Tag (gtag.js) - Google AdWords: GOOGLE_CONVERSION_ID_1 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-GOOGLE_CONVERSION_ID_1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'AW-GOOGLE_CONVERSION_ID_1');
  gtag('config', 'AW-GOOGLE_CONVERSION_ID_2');
</script>

这是现代解决方案应遵循的模式。

Note that as of October 2017, you can (and should) use Google's new gtag.js, which is a new web tagging library that replaces the older AdWords website conversion tracking and remarketing tags.

gtag.js allows you to send tracking data to multiple AdWords accounts by adding a call to the ‘config’ command for every account you’ll be using, specifying each account’s conversion ID:

<!-- Global Site Tag (gtag.js) - Google AdWords: GOOGLE_CONVERSION_ID_1 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-GOOGLE_CONVERSION_ID_1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'AW-GOOGLE_CONVERSION_ID_1');
  gtag('config', 'AW-GOOGLE_CONVERSION_ID_2');
</script>

This is the pattern that modern solutions should follow.

云巢 2024-12-26 06:17:24

您需要在每组变量下方插入标签

// first slot of variables

// 第二个变量槽
// 你不再需要 'var' 语句

或者你只插入 noscript 标签的内容,但没有(大部分与 javascript 标签一样好)

You need to insert the tag below each group of variables

// first slot of variables

// second slot of variables
// you don't need 'var' statement anymore

Or you insert on only the content of the noscript tag, but without (is mostly as good as the javascript tag)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文