1

I am trying to set up e-commerce tracking on my custom e-commerce site. On the thank you for ordering page I have added this code at the bottom, it also has the normal ga.js tracking code in the header, as it does on every page of the site.

<script type="text/javascript">
// Google Analytics
var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-31467450-1']);
    _gaq.push(['_trackPageview']);

        transactionId = <?php echo $order_id ?>;
        affiliation = '';
        total = <?php echo $grand_total ?>;
        tax = <?php echo $vat_total ?>;
        shipping = <?php echo $shipping_total ?>;
        country = <?php echo $address ?>;

    _gaq.push(['_addTrans',
        transactionId,
        affiliation,
        total, 
        tax,
        shipping,
        city,
        state,
        country
    ]);

    <?php 
    $item_qry = mysql_query("SELECT `products_price`,`products_quantity`,`products_name`,`products_model` FROM `orders_products` WHERE `orders_id`=$order_id");

    while($item_row = mysql_fetch_assoc($item_qry)) {
    echo"_gaq.push(['_addItem','$order_id','$item_row['products_model']','$item_row['products_name']','','$item_row['products_price']',$item_row['products_quantity'])";
}
?>

    _gaq.push(['_trackTrans']);
</script>

Is this all that is required to track ecommerce?

I added the loop so it runs through every item added, do I do this correctly?

1

Yeah, it appears that you have all the required parameters. I suggest you test it with a tool like HTTPFox or Google Analytics Debugger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.