Created
October 13, 2014 11:49
-
-
Save SearchStar/b9d433404fe82ad6ef47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$transactionId='test1001'; | |
$sku=array('test1003','test1001','test1002'); | |
$name=array('six1','six2','six3'); | |
$category=array('142139113','161477257','574557754'); | |
$price=array(53.90,9.99,36.36); | |
$quantity=array(1.00,1.00,1.00); | |
$transactionAffiliation='affil'; | |
$transactionTotal='100.25'; | |
$transactionTax=00.00; | |
$transactionShipping='0.00'; | |
$length = count($sku); | |
for ($i=0; $i+1<=$length; $i++) | |
{ | |
if ($i+1<$length) | |
{ | |
$cartProducts[$i] = " | |
_gaq.push(['_addItem', | |
'" . $transactionId . "', // transaction ID - required | |
'" . $sku[$i] . "', // SKU/code - required | |
'" . $name[$i] . "', // product name | |
'" . $category[$i] . "', // category or variation | |
'" . $price[$i] . "', // unit price - required | |
'" . $quantity[$i] . "' // quantity - required | |
]),"; | |
} | |
else | |
{ | |
$cartProducts[$i] = " | |
_gaq.push(['_addItem', | |
'" . $transactionId . "', // transaction ID - required | |
'" . $sku[$i] . "', // SKU/code - required | |
'" . $name[$i] . "', // product name | |
'" . $category[$i] . "', // category or variation | |
'" . $price[$i] . "', // unit price - required | |
'" . $quantity[$i] . "' // quantity - required | |
])"; | |
} | |
}; | |
?> | |
<html> | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-40915691-1']); | |
_gaq.push(['_trackPageview']); | |
_gaq.push(['_addTrans', | |
'<?php echo $transactionId?>', // transaction ID - required | |
'<?php echo $transactionAffiliation?>', // affiliation or store name | |
'<?php echo $transactionTotal?>', // total - required | |
'<?php echo $transactionTax?>', // tax | |
'<?php echo $transactionShipping?>' // shipping | |
]); | |
<?php foreach ($cartProducts as $row) {echo $row;}?> | |
_gaq.push(['_trackTrans']); | |
(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> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment