eCommerce Tracking with Google Analytics

October 08, 2012

Reading time ~1 minute

Up and running in 5 mins

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce

http://online-behavior.com/googleanalytics/tracking-ecommerce 24:00

Be very careful with Google's requirements. You must have an SKU, and it must be unique. Commas in a number will be read as decimal points. Currency signs create problems. Don't use them.

Some common issues include non-unique SKUs. JS errors, programming errors, reloads of receipt page, and users who have JS or cookies turned off.

The below code is for CartThrob and ExpressionEngine.

{exp:weblog:entries weblog="orders" limit="1" parse="inward" disable="categories|member_data|pagination|trackbacks" entry_id="{embed:entry_id}"}

    {!-- <!-- 
        Google Analytics tracking code
     --> --}
    <script type="text/javascript"> 
    _gaq.push(['_addTrans',
    '{entry_id}',               // order ID - required
    'Client Site',              // affiliation or store name
    '{order_total}',            // total - required
    '{order_tax}',              // tax
    '{order_shipping}',         // shipping
    '{order_billing_city}',     // city
    '{order_billing_state}',    // state or province
    '{order_billing_country}'   // country
    ]);

    // add item might be called for every item in the shopping cart
    // where your ecommerce engine loops through each item in the cart and
    // prints out _addItem for each 
    {order_items}
    _gaq.push(['_addItem',
    '{entry_id}',               // order ID - required
    '{item:title}',             // SKU/code
    '{item:products_title}',    // product name
    '{item:size}',              // category or variation
    '{item:price}',             // unit price - required
    '{item:quantity}'           // quantity - required
    ]);
    {/order_items}

    _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

    </script>

{/exp:weblog:entries}
comments powered by Disqus

ExpressionEngine Support in EE 2

TL;DR EE's forum is still alive It's not officially supported, StackExchange has all the action Official support requires a subscription If…… Continue reading