如何在每个页面中包含谷歌分析,但只在我的“谢谢你页面”中进行eccomerce跟踪

时间:2015-09-29 12:04:39

标签: google-analytics

我在网站布局中加入了Google Analytics跟踪功能,因此可以跟踪每个网页。

<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-XXXXX-YY', 'none');
        ga('send', 'pageview');
   </script>

我想在购买完成后的最后一个感谢页面中包含电子商务跟踪脚本。

             <script> 

                 ga('ecommerce:addTransaction', {
                'id': '<%:order.DocumentNo%>',                   // Transaction ID. Required.
                'revenue': '<%:order.TotalOrderPriceWithVat%>',  // Grand Total.
                'shipping': '<%:order.TotalTransportPrice %>',   // Shipping.
                'tax': '0'                                       // Tax.
            });

    <
            ga('ecommerce:addItem', {
                'id':   '<%:order.DocumentNo %>',                 // Transaction ID. Required.
                'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>',  // Product name. Required.
                'sku': '<%:item.Item_Id %>',                    //Item ID

                'category': '<%:item.CustomData %>',                          // Category or variation.
                'price': '<%:item.OrderPriceWithVat %>',       // Unit price.
                'quantity': '<%:item.Quantity %>'            // Quantity.
            });





</script>

问题是在最后一页我得到错误 ga未定义

1 个答案:

答案 0 :(得分:2)

基本跟踪

  1. load analytics.js library
  2. init tracker(创建)
  3. 跟踪综合浏览量

    <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-YYY', 'none');
        ga('send', 'pageview');
    

  4. 电子商务跟踪

    1. load analytics.js library
    2. init tracker(创建)
    3. 加载电子商务插件
    4. 跟踪综合浏览量
    5. 添加交易说明
    6. 跟踪交易

      <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-YYY', 'none');
          ga('require', 'ecommerce'); // load ecommerce plugin
          ga('send', 'pageview');
      
          ga('ecommerce:addTransaction', {
              'id': '<%:order.DocumentNo%>',                   // Transaction ID. Required.
              'revenue': '<%:order.TotalOrderPriceWithVat%>',  // Grand Total.
              'shipping': '<%:order.TotalTransportPrice %>',   // Shipping.
              'tax': '0'                                       // Tax.
          });
      
      
          ga('ecommerce:addItem', {
              'id':   '<%:order.DocumentNo %>',                 // Transaction ID. Required.
              'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>',  // Product name. Required.
              'sku': '<%:item.Item_Id %>',                    //Item ID
      
              'category': '<%:item.CustomData %>',                          // Category or variation.
              'price': '<%:item.OrderPriceWithVat %>',       // Unit price.
              'quantity': <%:item.Quantity %>            // Quantity.
          });
      
          ga('ecommerce:send'); // track transaction
      

    7. 文档

      https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce