繁体   English   中英

Google电子商务跟踪

[英]Google E-Commerce Tracking

我正在尝试将数据提交给Google E-Commerce Tracking,但似乎无法正常运行,我认为这是因为我不得不将代码分开...

这是我的代码:

<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>

我是否缺少某些内容?或者是因为我将脚本分开了吗?

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>

看看是否有效。

暂无
暂无

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

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