2016-06-29 11 views
0

Ich versuche, Daten an Google E-Commerce-Tracking zu senden, aber es scheint nicht zu funktionieren und ich denke, es ist, weil ich den Code auseinander teilen musste ...Google E-Commerce-Tracking

Hier ist mein Code:

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

bin ich etwas fehlt oder ist es, weil ich das Drehbuch auseinander geteilt haben?

+0

Können Sie näher ausführen, wie "es scheint nicht zu funktionieren"? Werden Fehlermeldungen angezeigt, sehen Sie keine Daten in Ihren Berichten usw.? – nyuen

Antwort

0

Das Google Analytics-Skript vor dem Spurseitenaufruf kommen sollte, und fügen Sie Transaktion würde es so etwas wie dieses:

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

sehen, ob es funktioniert.

+0

Hallo, das stimmt nicht unbedingt. Sehen Sie sich das asynchrone Beispiel unter https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce#Example – nyuen

+0

an. Oh, dann habe ich nichts falsches in seinem Code bemerkt. Was schlagen Sie vor? –

Verwandte Themen