简体   繁体   English

Google Analytics(分析)电子商务跟踪数据问题

[英]Google Analytics Ecommerce Tracking Data Issue

The Google Analytics example code for tracking ecommerce in the new analytics.js instead of ga.js gives data in the fields where I have $product['name'] etc. 用于在新的analytics.js(而不是ga.js)中跟踪电子商务的Google Analytics(分析)示例代码在我具有$ product ['name']等的字段中提供了数据。

The code below currently doesn't work and I'm not 100% sure it's pulling the correct information onpage as this is what is shown in the page source instead of 'id': '{1455}', it's showing 'id': '{$order_query['order_id']}',. 下面的代码当前无法正常工作,我不确定100%确定是否在页面上提取正确的信息,因为这是页面源中显示的内容,而不是'id':'{1455}',它显示的是'id': '{$ order_query [' 的order_id ']}' ,. We're using Opencart 1.5.5.1. 我们正在使用Opencart 1.5.5.1。

Is this the correct code? 这是正确的代码吗? Are the $price, $product['name'] sections correct? $ price,$ product ['name']部分正确吗?

<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-21397982-1', 'auto');
  ga('send', 'pageview');
  ga('require', 'ecommerce', 'ecommerce.js');

ga('ecommerce:addTransaction', {
  'id': '{$order_query['order_id']}',
  'revenue': '{$price}',
});
ga('ecommerce:addItem', {
  'id': '$order_query['order_id']',
  'name': '{$product['name']}',
  'sku': '{$product['model']}',
  'price': '{$product['price']}',
  'quantity': '{$product['quantity']}',
  'currency': 'GBP'
});

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

This is your code 这是你的代码

 <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-21397982-1', 'auto'); ga('send', 'pageview'); ga('require', 'ecommerce', 'ecommerce.js'); ga('ecommerce:addTransaction', { 'id': '{$order_query['order_id']}', 'revenue': '{$price}', }); ga('ecommerce:addItem', { 'id': '$order_query['order_id']', 'name': '{$product['name']}', 'sku': '{$product['model']}', 'price': '{$product['price']}', 'quantity': '{$product['quantity']}', 'currency': 'GBP' }); ga('ecommerce:send'); </script> 

Surly Opencart using tpl file for template. Surly Opencart使用tpl文件作为模板。 and this code suppose to work. 该代码应该可以工作。 since it is not working then try below code. 由于它不起作用,请尝试以下代码。

 <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-21397982-1', 'auto'); ga('send', 'pageview'); ga('require', 'ecommerce', 'ecommerce.js'); ga('ecommerce:addTransaction', { 'id': '<?php echo $order_query['order_id'];?>', 'revenue': <?php echo $price;?>, }); ga('ecommerce:addItem', { 'id': '<?php echo $order_query['order_id'];?>', 'name': '<?php echo $product['name'];?>', 'sku': '<?php echo $product['model'] ;?>', 'price': <?php echo $product['price'];?>, 'quantity': <?php echo $product['quantity']};?>, 'currency': 'GBP' }); ga('ecommerce:send'); </script> 

and if there is problem with your variables then you should go through this link http://www.notesonclick.com/blog/ecommerce-tracking-in-opencart-2-3/ this might be useful . 如果您的变量存在问题,则应通过以下链接http://www.notesonclick.com/blog/ecommerce-tracking-in-opencart-2-3/进行操作。

your raw php code should be echoing out the values in to the JavaScript 您的原始php代码应该在JavaScript中回显值

'id': '{<?php echo $order_query['order_id']; ?> }',

what you are sending to Google Anlayitcs now is the 您现在发送给Google Anlayitcs的是

id of " {$order_query['order_id']} " which is a text string and not going to work. ID为“ {$order_query['order_id']} ”,它是文本字符串,不起作用。

The best way to implement this would be to use an extension already made. 实现此目的的最佳方法是使用已经进行的扩展。 It will save you messing about and should work straight away. 这样可以省去您的麻烦,应立即开始工作。 There's loads on the store. 商店里有很多东西。 I've tried a few analytics extensions for opencart but the best and easiest to work with in my experience is this one: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4496 It took me about 10 minutes to set up and I had ecommerce and site data in my analytics account the same day 我已经尝试过一些针对opencart的分析扩展,但是根据我的经验,最容易使用的扩展是: http : //www.opencart.com/index.php? route=extension/extension/info&extension_id=4496我大约需要10分钟的设置时间,并且当天我的分析帐户中已有电子商务和网站数据

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

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