Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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