2016-06-29 9 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> 

私は何かが欠けているか、私は離れてスクリプトを分割したのでそれはあるだろうか?それが動作するかどうか

<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

"それは動作していないようです"ということについて詳しく説明できますか?エラーメッセージが表示されているか、レポートにデータが入力されていないかなど – nyuen

答えて

0

Google Analyticsのスクリプトがトラックページビューの前に来て、トランザクションを追加する必要があり、それはこのようなものになるだろう。

+0

こんにちは、これは必ずしも真実ではありません。 https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce#Example – nyuen

+0

で、非同期の例を確認してください。オハイオ州オハイオ州、コードに間違いがないことを気付かずに、何をお勧めしますか? –

関連する問題