简体   繁体   English

通过标签管理器跟踪谷歌分析电子商务中的折扣值

[英]Discount values in google analytics ecommerce tracking via tag manager

We're implementing GA conversion tracking with GTM per the following documentation, but I'm not finding any information about how to handle discounts (coupons) at the order level.我们正在按照以下文档使用 GTM 实施 GA 转换跟踪,但我没有找到有关如何在订单级别处理折扣(优惠券)的任何信息。 https://support.google.com/tagmanager/answer/6106097?hl=en https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce https://support.google.com/tagmanager/answer/6106097?hl=en https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

I can send revenue, shipping, and tax, but these won't total correctly for orders that include a discount.我可以发送收入、运费和税金,但对于包含折扣的订单,这些金额的总和不正确。 If an order is placed as follows:如果下单如下:

T-Shirt:     $5
Socks:       $5
subtotal:   $10
tax:         $2
shipping:    $3
discount:   -$5
order total: $10

Should my dataLayer look like this?我的数据层应该像这样吗?

<script>
dataLayer = [{
    'transactionId': '1234',
    'transactionAffiliation': 'Acme Clothing',
    'transactionTotal': 10,
    'transactionTax': 2,
    'transactionShipping': 3,
    'transactionProducts': [{
        'sku': 'DD44',
        'name': 'T-Shirt',
        'category': 'Apparel',
        'price': 5,
        'quantity': 1
    },{
        'sku': 'AA1243544',
        'name': 'Socks',
        'category': 'Apparel',
        'price': 5,
        'quantity': 1
    }]
}];
</script>

Will that cause any inaccuracies or inconsistencies in GA?这会导致 GA 中的任何不准确或不一致吗?

A co-worker and I are tackling the same question right now.我和一个同事现在正在解决同样的问题。

Before I get into that though you should never, ever declare your dataLayer like that.在我开始之前,尽管您永远不应该像那样声明您的 dataLayer。 Sadly it seems to be the way that Google themselves do it in all their code examples, but it's incredibly dangerous because it will overwrite your existing dataLayer with a new one that only contains those key : value pairs.可悲的是,这似乎是 Google 自己在所有代码示例中的做法,但这是非常危险的,因为它会用仅包含那些键值对的新数据层覆盖您现有的数据层。 Instead check if dataLayer exists, creating it if it doesn't, and push to it.而是检查 dataLayer 是否存在,如果不存在则创建它,然后推送到它。

window.dataLayer = window.dataLayer || [];
dataLayer.push({
  'key' : 'value'
});

Additionally assuming you've switched over to Universal Analytics consider toggling Enhanced Ecommerce Tracking.此外,假设您已切换到 Universal Analytics,请考虑切换增强型电子商务跟踪。 It's simultaneously a much more powerful, and cleaner implementation of ecommerce tracking.它同时是一种更强大、更清洁的电子商务跟踪实现。

So far we've come up with a couple seemingly workable approaches.到目前为止,我们已经提出了几个看似可行的方法。 You can ignore the discount all together, like you did above, and report the total revenue manually after the discount has been applied.您可以像上面一样忽略所有折扣,并在应用折扣后手动报告总收入。 One thing I would add if you switch to Enhanced Ecommerce is a coupon code to acknowledge that a product has a discount applied.如果您切换到增强型电子商务,我要添加的一件事是优惠券代码,用于确认产品已应用折扣。

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'ecommerce': {
      'purchase': {
        'actionField': {
          'id': '1234',
          'affiliation': 'Acme Clothing',
          'revenue': '10.00',
          'tax':'2.00',
          'shipping': '3.00',
          'coupon': 'SUMMER_SALE' //Transaction-scope coupon. This would
//be where you'd include discounts like '$10 off purchases of $50 or more'
        },
        'products': [{
          'name': 'T-Shirt',
          'id': 'DD44',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1
         },
         {
          'name': 'Socks',
          'id': 'AA1243544',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1,
          'coupon': 'FREE_SOCKS' //Product-scope coupon. This would be for 
//discounts like 'free socks with purchase of a t-shirt'
         }]
      }
    }
  });
</script>

Alternatively you can enter the discounts as negative value SKUs and track them as their own line items in the transaction.或者,您可以将折扣作为负值 SKU 输入,并将它们作为交易中自己的行项目进行跟踪。

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'ecommerce': {
      'purchase': {
        'actionField': {
          'id': '1234',
          'affiliation': 'Acme Clothing',
          'revenue': '10.00',
          'tax':'2.00',
          'shipping': '3.00'
        },
        'products': [{
          'name': 'T-Shirt',
          'id': 'DD44',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1
         },
         {
          'name': 'Socks',
          'id': 'AA1243544',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1,
         },
         {
          'name': 'Socks-Discount',
          'id': 'free-socks',
          'price': '-5.00',
          'category': 'Apparel',
          'quantity': 1,
         }]
      }
    }
  });
</script>

Ultimately my recommendation is to mirror the logic for how you're handling the discount in the cart itself.最终,我的建议是反映您如何处理购物车中的折扣的逻辑。 If discounts are their own line items with their own SKUs in your cart report them in GA the same way.如果折扣是他们自己的行项目,在您的购物车中有自己的 SKU,则以相同的方式在 GA 中报告它们。 If coupon codes make more sense do that.如果优惠券代码更有意义,那就这样做。 You can even combine the two if you'd like.如果您愿意,您甚至可以将两者结合起来。

Use the coupon field to specify the fact that the transaction and/or product is being discounted.使用优惠券字段指定交易和/或产品正在打折的事实。 eg例如

"coupon" : "10% summer sale" or just "general discount" “优惠券”:“10% 夏季促销”或“一般折扣”

Then use a custom metric (scope=hit, format=decimal) to track the total amount of discount applied for the transaction.然后使用自定义指标(scope=hit,format=decimal)来跟踪应用于交易的折扣总额

'dimension1': '50.0' '维度1':'50.0'

Ref: https://developers.google.com/tag-manager/enhanced-ecommerce#checkout参考: https : //developers.google.com/tag-manager/enhanced-ecommerce#checkout

Your transaction total in the DL should get pushed to the addTrans call.您在 DL 中的交易总额应该被推送到 addTrans 调用。 So just make sure whatver value you send to it is what you want to send.所以只要确保你发送给它的任何值都是你想要发送的。 GA does not care how you define revenues. GA 不关心您如何定义收入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM