简体   繁体   English

Google电子商务跟踪

[英]Google E-Commerce Tracking

I'm trying to submit data to Google E-Commerce Tracking but it doesn't seem to be working and I think it's because i've had to split the code apart... 我正在尝试将数据提交给Google E-Commerce Tracking,但似乎无法正常运行,我认为这是因为我不得不将代码分开...

Here is my code: 这是我的代码:

<html>
<head>
<title></title>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '{{$id}}',           // transaction ID - required
    '{{$name}}',  // affiliation or store name
    '{{$amount}}'          // total - required
  ]);

</script>


@foreach ($products as $product)
<script type="text/javascript">
      _gaq.push(['_addItem',
        '{{$id}}',           // transaction ID - required
        '{{$product['edg_code']}}',           // SKU/code - required
        '{{$product['product_name']}}',        // product name
        '{{$product['unit_price']}}',          // unit price - required
        '{{$product['quantity']}}'               // quantity - required
      ]);
      _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
</script>

@endforeach

<script type="text/javascript">
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>

</body>
</html>

Am I missing something or is it because i've split the script apart? 我是否缺少某些内容?或者是因为我将脚本分开了吗?

The Google Analytics script should come before the track pageview and add transaction, it would be something like this: Google Analytics(分析)脚本应位于跟踪浏览量之前并添加交易,如下所示:

<html>
<head>
<title></title>
<script type="text/javascript">


(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '{{$id}}',           // transaction ID - required
    '{{$name}}',  // affiliation or store name
    '{{$amount}}'          // total - required
  ]);


@foreach ($products as $product)
//the rest....
</script>

see if it works. 看看是否有效。

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

相关问题 使用Google跟踪代码管理器进行电子商务跟踪 - E-commerce tracking with google tag manager Google Analytics AJAX电子商务跟踪 - Google Analytics AJAX e-commerce tracking Google Analytics(分析)电子商务跟踪不适用于自定义PHP - Google Analytics E-commerce tracking is not working With Custom PHP GA-电子商务未跟踪商品 - GA - E-commerce not tracking items Google Analytics(分析)增强型电子商务跟踪功能是否可以取代“ ecommerce:addTransaction”? - Does Google Analytics enhanced e-commerce tracking replace “ecommerce:addTransaction”? Google Analytics Enhanced E-commerce Tracking/Analytics 无法通过 GTM 运行 - Google Analytics Enhanced E-commerce Tracking/Analytics is not working via GTM 将变量从PHP转换为Java脚本以进行Google Analytics(分析)电子商务跟踪代码 - Converting variables from PHP to Javascript for Google Analytics e-Commerce Tracking code 将收入数据从Google Analytics(分析)电子商务代码段提取到另一个收入跟踪代码段 - Pulling revenue data from a Google Analytics e-commerce snippet into another revenue tracking snippet Google Analytics(分析)电子商务产品 - Google Analytics e-commerce products Laravel中的电子商务 - E-commerce in Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM