简体   繁体   English

将Big Commerce更新为新的analytics.js

[英]Updating Big Commerce to the new analytics.js

I'm working on a site and I updated the tracking code to the new analytics.js I transferred their site and everything is working except for conversion. 我在一个网站上工作,并将跟踪代码更新为新的analytics.js,我转移了他们的网站,除转换外,其他所有功能均正常。 It's a Big Commerce site so I can't touch server side script but this what they generate 这是一个大型商务网站,所以我无法触摸服务器端脚本,但这是他们生成的

<script type="text/javascript">
$(document).ready(function() {
 if(typeof(pageTracker) != 'undefined') {
 pageTracker._addTrans(
'358',
'Backyard Toy Company ',
'0.01',
'0.00',
'0.00',
'Lakewood',
'New Jersey',
'United States'
);
 pageTracker._addItem(
'358',
'1336',
'test',
'',
'0.01',
'1'
);
  pageTracker._trackTrans();
}
});
</script>

I updated the client side code to this 我将客户端代码更新为此

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

  // START CUSTOM CODE
  function old2new() {
     // define object that can route old methods to new methods
     this._addTrans = addTrans;
     this._addItem = addItem;
     this._trackTrans = trackTrans;
  }

  function addTrans(orderID,store,total,tax,shipping,city,state,country) {
    // remap _addTrans
   ga('ecommerce:addTransaction', {
      'id': orderID,
      'affiliation': store,
      'revenue': total,
      'tax': tax,
      'shipping': shipping,
   });
  }

  function addItem(orderID,sku,product,variation,price,qty) {
    // remap _addItem
  ga('ecommerce:addItem', {
    'id': orderID,
    'sku': sku,
    'name': product,
    'category': variation,
    'price': price,
    'quantity': qty
  });
 }

function trackTrans() {
  ga('send', 'ecommerce'); 
}

// instantiate converter using name of old Google tracking object
// bigcommerce code will use this and be none the wiser
var pageTracker = new old2new();
// END CUSTOM CODE

I'm sorry I'm a newbie, but I looked all over can't figure out why it's not working. 对不起,我是新手,但到处都看不出为什么它不起作用。

I think the send method is supposed to be something like: 我认为send方法应该是这样的:

ga('ecommerce:send');

If this does not work, you can do the following and see if find something else that is wrong: 如果这不起作用,则可以执行以下操作,查看是否找到其他错误的地方:

Can you put an alert in all three functions and make sure that it is being called correctly? 您是否可以在所有三个功能中放置警报,并确保已正确调用它?

Also, there might be a bug in the code that might be affected by the overridden this . 另外,代码中可能存在一个错误,该错误可能会受到覆盖this影响。 Can you rewrite the methods like the following and see if that works: 您可以重写以下方法,看看是否可行:

  function addTrans(orderID,store,total,tax,shipping,city,state,country) {
   // alert("in addTrans");
   ga.call(window, 'ecommerce:addTransaction', {
      'id': orderID,
      'affiliation': store,
      'revenue': total,
      'tax': tax,
      'shipping': shipping,
   });
  }

  function addItem(orderID,sku,product,variation,price,qty) {
  // alert("in addTrans");
  ga.call(window, 'ecommerce:addItem', {
    'id': orderID,
    'sku': sku,
    'name': product,
    'category': variation,
    'price': price,
    'quantity': qty
  });
 }

function trackTrans() {
  // alert("in Trans");
  ga.call(window, 'ecommerce:send'); 
}

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

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