[英]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.