0

因此,我已经为新的 Google Universal Analytics 获得了正确的电子商务跟踪代码,但我对变量的填充方式感到困惑?如何在此脚本中获取正确的商品、价格、类别或商品数量(对于 addItem)?我一直在网上寻找,我不认为我在这里看到了完整的图片。

<script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-44464798-1', 'safeway.com');
  ga('send', 'pageview');
  ga('require', 'ecommerce', 'ecommerce.js');

  ga('ecommerce:addTransaction', {
  'id': '200028184',                // Transaction ID. Required.
  'affiliation': 'Safeway',   // Affiliation or store name.
  'revenue': '11.99',              // Grand Total.
  'shipping': '5.00',               // Shipping.
  'tax': '1.00'                    // Tax.
});

  ga('ecommerce:addItem', {
  'id': '200028184',               // Transaction ID. Required.
  'name': 'Apples',   // Product name. Required.
  'sku': 'CVC2US',                  // SKU/code.
  'category': '',        // Category - you can put some category if we have such
  'price': '11.99',                // Unit price.
  'quantity': '1'                  // Quantity.
});

 // If there are additional items they should be added the same way. The sum of all    Items prices should match with the "revenue" data from above. 

  ga('ecommerce:send');  // 
</script>
4

2 回答 2

0

您希望引用变量的值,而不是脚本中的值。这些将在购买完成时由购物车代码分配。

Google 文档有一个 PHP 示例。 分析 JS 电子商务开发说明

于 2014-05-17T20:23:01.147 回答
0

我不知道您的网站是用什么语言编写的。假设它是 PHP 或 asp.net,您将需要进入构建网站本身的代码并添加这些标签。

因此,为了回答您的问题,变量和值由您在网站后面的代码中填充。可能在用户结帐的同时。

于 2014-03-11T07:32:49.160 回答