javascript - Google Analytics 通用电子商务跟踪实现

标签 javascript google-analytics e-commerce tracking

我正在将我们的谷歌分析代码升级为通用谷歌通用分析。我们的网站上还有需要更新的电子商务跟踪。我想知道这个实现是否正确:

在所有页面的标题中添加代码

<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-xxxxxxx-x', 'auto');
                  ga('send', 'pageview');

</script>

然后在我们的感谢页面(标题对于网站上的所有页面都是通用的),我添加了以下用于电子商务跟踪的代码:

<script type="text/javascript"> 

        ga('require', 'ecommerce', 'ecommerce.js');   // Load the ecommerce plug-in.

        ga('ecommerce:addTransaction', {
          'id': 'xxxx-ID',                     
          'affiliation': 'Example',   
          'revenue': '124.15',              
          'shipping': '0.00',                 
          'tax': '5.00'                 
        });

                        ga('ecommerce:addItem', {
                                  'id': 'xxxx-ID',                     
                                  'name': 'testSKU',                
                                  'sku': 'testID',                   
                                  'category': '',       
                                  'price': '114.95',                 
                                  'quantity': '1'                   
                                });



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

在加载电子商务插件之前我需要添加以下几行吗?

ga('创建', 'UA-35844822-1', '自动'); ga('发送', '浏览量');

正确的实现是什么?

有什么方法可以在投入生产之前对其进行跟踪吗?

谢谢

最佳答案

是的,您需要在加载电子商务插件之前添加“创建”和“发送”行。

ga('create', 'UA-xxxxxxx-x', 'auto');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');

这里有一些很好的信息:http://cutroni.com/blog/2013/03/22/tracking-ecommerce-transactions-with-universal-analytics/

希望这有帮助!

关于javascript - Google Analytics 通用电子商务跟踪实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25045562/

相关文章:

JAVASCRIPT:如何跟踪和记录网站上的用户事件(如 Google Analytics)

google-analytics - Google Analytics(分析)中的逐页转换率

cookies - 使用 SameSite 和 Secure 属性设置 Google 跟踪代码管理器 cookie

php - Magento:在特殊 View 上进行分层导航

php - 信用点 Web 应用程序

javascript - 无法在 Angular JS 中使用 ng-repeat 打印 View 中的数组

javascript - Youtube 视频 div 覆盖故障

php - 如何仅使用时间选择器更新更改日期格式

javascript - 设置 TH 最小和最大宽度非常慢

java - java电子商务(我的火的洗礼)