2016-06-29 158 views
0

我正在嘗試向Google電子商務跟蹤提交數據,但它似乎沒有工作,我認爲這是因爲我不得不將代碼拆分開...Google電子商務跟蹤

這裏是我的代碼:

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

我缺少的東西或者是因爲我開拆腳本?

+0

您可以詳細說明「它似乎沒有工作」嗎?你是否看到錯誤信息,你沒有看到數據在你的報告中填充,等等? – nyuen

回答

0

的谷歌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> 

看看它是否工作。

+0

嗨,這不一定是真的。查看https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce#Example – nyuen

+0

上的異步示例哦,好吧,那麼,我沒有注意到他的代碼中有什麼錯,您有什麼建議? –

相關問題