首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google电子商务跟踪

Google电子商务跟踪
EN

Stack Overflow用户
提问于 2016-06-29 23:28:47
回答 1查看 56关注 0票数 0

我正在尝试向Google E-Commerce Tracking提交数据,但它似乎不起作用,我想这是因为我不得不拆分代码……

下面是我的代码:

代码语言:javascript
复制
<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>

是我漏掉了什么,还是因为我把脚本拆分了?

EN

回答 1

Stack Overflow用户

发布于 2016-06-30 00:43:33

Google Analytics脚本应该出现在跟踪页面视图和添加事务之前,它应该是这样的:

代码语言:javascript
复制
<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>

看看它能不能用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38103993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档