如何使脚本在访问 URL 时仅触发一次 Google Conversion Tracking

发布于 2025-01-14 21:03:47 字数 2149 浏览 3 评论 0原文

我正在使用 Google Ads 跟踪我的电子商务网站上的购买转化情况。当用户点击我的产品 G​​oogle 广告,然后进行购买并登陆感谢页面时,就会触发转化事件并向 Google 发送数据,以便 Google 知道已下订单并可以跟踪转化。

我的问题是,每次同一个感谢页面加载该用户订单 id 令牌时,它都会触发该脚本,并且 Google 会将其跟踪为另一次转换。这应该只发生一次,这只应该在第一次使用该订单令牌访问页面时发生。

以下面这个网址为例。一位用户看到我的 Google 广告,然后点击并购买,然后他进入了感谢页面。此时,它被视为转化。 https://mywebsite.com/purchase/thank-you/order/1001632bfd1c-2x5a-701t-1xs90a0a4444

在同一天或 20 天后的某个时间,用户在手机上打开浏览器,页面重新加载,或者用户想要检查他的浏览历史并点击此网址。一旦他登陆,脚本就会再次触发,并将其算作他最初点击的广告的转化。

有没有办法让脚本只在第一次加载 url 时触发? 使用 Shopify 的商家只需将转化事件脚本包装为 {% If First_time_accessed %} 使用 Liquid(Shopify 的语言)。这样一来,即使用户重新加载相同的网址,脚本也不会再次触发来跟踪该页面访问作为另一次转化。

如果我使用 C# MVC 在 ASP.net 中开发网站,我该如何执行此类逻辑? 是否有一些 javascript 可以用来包装我的事件片段,使其像 Shopify 一样工作? 我已经搜索过这个,但只找到有关如何在 Shopify 上执行此操作的信息。 注意...我没有使用跟踪代码管理器,我只想将事件代码段保留在我的页面上,而无需在跟踪代码管理器中设置任何内容。

这是我当前的脚本:

<!-- Global site tag (gtag.js) - Google Analytics -->  

<script async src="https://www.googletagmanager.com/gtag/js?id=G-M3WT222222"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag('js', new Date());

    //conversion tracking for Google Analytics
    gtag('config', 'G-M3WT222222');

    //conversion tracking from Google Ads
    gtag('config', 'AW-12057888501');
</script>
<!-- Event snippet for MYwebsite Purchase conversion page -->
<script>
        gtag('event', 'conversion', {
            'send_to': 'AW-12057888501/x0QzZp_vliJUHNC-B08Zx',
            'value': @ViewBag.Display_subtotal,
            'currency': '@ViewBag.Display_currencyAbbreviation',
            'transaction_id': '@ViewBag.Display_invoiceNumber'
        });
</script>

这是 Shopify 的操作示例这。请注意,代码被封装在此处显示的一些液体代码中 {% if first_time_accessed %}

{% if first_time_accessed %}
<!-- Event snippet for Purchases Shopify conversion page -->
<script>
  gtag('event', 'conversion', {
  'send_to': 'AW-2035565011/frthgrt455_151f5rfc',
  'transaction_id': '{{ order_number  }}'
  });
</script>
{% endif %}

I am using Google Ads to track purchase conversions on my Ecommerce website. When a user clicks on my Google Ad for a product and then makes the purchase and lands on the thank you page, the conversion event is triggered and sends google the data so that it knows that an order has been placed and it can track the conversion.

My problem is that EACH time that same thank-you page is loaded with that users order id token, it fires that script and Google tracks that as another conversion. This should only be happening once, this should only happen the first time the page is accessed with that order token.

Take this url below for example. A user saw my Google Ad and then clicked on it and purchased and then he landed on the thank you page. At this point it was tracked as a conversion.
https ://mywebsite.com/purchase/thank-you/order/1001632bfd1c-2x5a-701t-1xs90a0a4444

Sometime later the same day or 20 days later, the user opens up the browser on his phone and that page reloads, or the user wants to check his browsing history and clicks on this url. As soon as he lands on it, the script will fire once again and count that as a conversion for the ad he originally clicked on.

Is there a way that I can make it so that the script only fires the first time a url loads?
Merchants who are using Shopify simply wrap the conversion event script with
{% If First_time_accessed %} in Liquid which is Shopify's language. This makes it so that even if the user reloads that same url, the script won't fire again to track that page visit as another conversion.

How do I do this type of logic if I am developing my site in ASP.net using C# MVC ?
Is there some javascript I can wrap my event snippet with to make it work like Shopify does it?
I have searched for this but keep only finding info on how to do it on Shopify.
Note...I am not using Tag Manager, I want to just leave the event snippet on my page without having to set up anything in tag manager.

Here is my script currently:

<!-- Global site tag (gtag.js) - Google Analytics -->  

<script async src="https://www.googletagmanager.com/gtag/js?id=G-M3WT222222"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag('js', new Date());

    //conversion tracking for Google Analytics
    gtag('config', 'G-M3WT222222');

    //conversion tracking from Google Ads
    gtag('config', 'AW-12057888501');
</script>
<!-- Event snippet for MYwebsite Purchase conversion page -->
<script>
        gtag('event', 'conversion', {
            'send_to': 'AW-12057888501/x0QzZp_vliJUHNC-B08Zx',
            'value': @ViewBag.Display_subtotal,
            'currency': '@ViewBag.Display_currencyAbbreviation',
            'transaction_id': '@ViewBag.Display_invoiceNumber'
        });
</script>

This is an example of how Shopify does this. Notice the code is wrapped in some liquid code shown here {% if first_time_accessed %}

{% if first_time_accessed %}
<!-- Event snippet for Purchases Shopify conversion page -->
<script>
  gtag('event', 'conversion', {
  'send_to': 'AW-2035565011/frthgrt455_151f5rfc',
  'transaction_id': '{{ order_number  }}'
  });
</script>
{% endif %}

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

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

发布评论

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

评论(2

佞臣 2025-01-21 21:03:47

与其说是解决方案,不如说是一种解决方法,但在 Google Ads 中设置新的转化操作时,可以选择将广告点击次数限制为仅计入单次转化:

在此处输入图像描述

当然,更改此选项到“一次”还意味着,如果有人在与广告互动后在您的网站上进行了两次单独的购买,则仍然只能算作一次转化。

More of a workaround than a solution, but when setting up a new conversion action in Google Ads, there's the option of restricting ad clicks to only be counted for a single conversion:

enter image description here

Of course, changing this option to "One" also means that if someone makes two separate purchases on your site after interacting with an ad, it would still only be counted as a single conversion.

童话里做英雄 2025-01-21 21:03:47

transaction_id字段用于过滤掉重复的交易。

确保每次页面重新加载时它具有相同的值。

您无法禁用事件触发,但不会影响转化计数。

transaction_id field is used to filter out duplicate transactions.

Make sure it has same value for every page reloading.

You can't disable event firing, but it will not affect conversion count.

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