Google Analytics Demystified: Part 3 - E-Commerce Tracking

Date July 28, 2007

Google AnalyticsIn Part 2 of this series, Google Analytics Demystified: Part 2 - “Vanilla” Google Analytics I talked about what I call “Vanilla” Google Analytics and provided some helpful insight on how to install it, how to check the status of it, and offered some tips for troubleshooting when it seems Google does not recognize your tracking code.

In Part 3 of this series here, I reveal the secrets to successfully using E-Commerce Tracking in Google Analytics. I’ll briefly go over installation, and then “activation” of Google E-Commerce tracking for Zen Cart. There are two steps required to get e-commerce tracking working, and both need to be completed or you will get “0’s” returned in your statistics.

Keep in mind that to utilize e-commerce tracking, you must first have Google Analytics installed for your website.

E-Commerce Tracking

Google Analytics E-Commerce Tracking is used to track product sales, sales revenues, transaction data, etc… When you install E-Commerce tracking, you’ll get reporting figures for things like “dollar amount of total sales for the period”, “product sales revenues for the period”, “top selling products”, and more.

The code you use to install Google E-Commerce Tracking looks something like this and MUST be placed BELOW the “Basic” Analytic Tracking code (shown above) on the sales RECEIPT page. This is the page a user arrives at after completing a successful sale at your store.

Sample of Google E-Commerce Tracking Code:

<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|[order-id]|[affiliation]|
[total]|[tax]| [shipping]|[city]|[state]|[country] UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|
[quantity] </textarea>
</form>

Zen Cart users that are utilizing the Simple Google Analytics Contribution do not have to worry about adding any code for e-commerce tracking. It is automatically added for you when you install the contribution. However, you still need to make sure you enable e-commerce tracking from within your Google Analytics Account as indicated below.

Important Note:
Just because you have installed the Google E-Commerce Tracking script on your sales receipt page, doesn’t mean you are ready to track sales data on your website. You must do one more thing in order to let Google know you want to track sales data.

You must tell Google that your site is an “E-Commerce Website” by enabling e-commerce tracking (or you will get “0’s” across the board in your e-commerce statistic reports.)

To do this, you login to your Google Analytics account and go to your Analytics tab then click on the “Edit” link to the right of the website profile you wish to activate e-commerce tracking for.

Google Analytics E-Commerce Tracking

On the next page you come to (profile settings), click the “Edit” link to the right of the first section heading that says “Main Website Profile Information”. This will bring you to the final screen, and the screen at which you actually “activate” e-commerce tracking for your store.

Google Analytics E-Commerce Tracking

At this final screen, simply select the “Yes” radio button option next to “E-Commerce Website:” and then click the “Save Changes” button.

Google Analytics Enabling E-Commerce tracking

Now, and only now, you are ready to start tracking e-commerce transactions at your online store.

In my new workbook titled “Google Analytics Uncovered for Zen Cart: The Workbook“, to be released on or before August 15th, 2007; I go into even more detail about how to install, read, and utilize Google E-Commerce tracking for Zen Cart. Keep an eye out for that.

With close to 100 pages of content, it’s sure to provide a wealth of unknown information and uncover some revealing details to help you read and understand what your Google Analytics are telling you. This information, when used properly, can assist you in increasing conversion of your website.

**** UPDATED 7/30/07 ****

I’ve had a number of users ask to show the Zen Cart customized code that should be used if you are planning on inserting it by hand (and not electing to use the Simple Google Analytics contribution; my recommended method). So, to help those users out, I have included instructions and code below to achieve that.

To insert the code for e-commerce tracking into Zen Cart by hand, you will need to alter two different files.

The first file you will need to alter is:
/includes/[your_template]/templates/common/tpl_main_page.php

Find that file, and insert the following code into it just above the closing tag, but below the “Vanilla” Google Analytics Tracking code. It is important that this code goes below the original tracking code Google Analytics provides, or it will not work correctly.

<?php
if ($_GET['main_page']=="checkout_success") { // if transaction is a successful purchase then record the order details
?>

<body onLoad="javascript:__utmSetTrans()">
<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|<?php echo $zv_orders_id ?>||<?php echo $zv_order_total_cd ?>|<?php echo $zv_order_tax ?>|0.00|<?php echo $zv_order_city ?>|<?php echo $zv_order_state ?>|<?php echo $zv_order_country ?>
<?php // Loop through products purchased to track in Google (these come from the "cart_orders_products TABLE)
//sku = "products_model"; productname = "products_name"; category = ""; price = "final_price"; quantity = "products_quantity"
$products_displayed_google = array();
for ($i=0, $n=sizeof($products_array_google); $i<$n; $i++) {
if (!in_array($products_array_google[$i]['id'], $products_displayed_google)) {
echo 'UTM:I|' . $zv_orders_id . '|' . $products_array_google[$i]['model'] . '|' . $products_array_google[$i]['text'] . '||' . $products_array_google[$i]['price'] . '|' . $products_array_google[$i]['quantity'];
$products_displayed_google[] = $products_array_google[$i]['id'];
}
}
?>
</textarea>
</form>

<?php
} //End if for adding e-commerce tracking code.
?>

The second file you will need to find and edit can be found in the following location:
/includes/modules/pages/checkout_success/header_php.php

Add the following lines of code to that file.

Take Note, for older versions of Zen Cart, you will want to add this code just below the following line:

$zv_order_total_cd = $orders->fields[’order_total’]; (approximately line # 74.)

On newer versions the line you would want to add it below looks like this:

$orders_id = $zv_orders_id; (approximately line #54.)

Here is the code you’ll want to insert.

// Added the below field for Google Analytics E-commerce Tracking
$zv_order_tax = $orders->fields['order_tax'];
$zv_order_city = $orders->fields['delivery_city'];
$zv_order_state = $orders->fields['delivery_state'];
$zv_order_country = $orders->fields['delivery_country'];

// Google Analytics Tracking (This can be removed and not harm anything)
//Altered code below to accomdate additional fields that Google Analytics can Track
$products_query = "select products_id, products_name, products_model,products_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . $zv_orders_id . "'
order by products_name";
$products_google = $db->Execute($products_query);
//********************Google codes**************************
while (!$products_google->EOF) {
$products_array_google[] = array('id' => $products_google->fields['products_id'],
'text' => $products_google->fields['products_name'],
'model' => $products_google->fields['products_model'],
'price' => $products_google->fields['products_price'],
'quantity' => $products_google->fields['products_quantity']);
$products_google->MoveNext();
}
//*************************End Google Codes*******************
// End Google Analytics Code

Finally, make sure you also include the following line (to get the order total) if it is not already present as well.

$zv_order_total_cd = $orders->fields['order_total'];

That should help those who want to add the code by hand. Any questions. Let me know.

For more detailed information on how you can use Google E-Commerce to increase conversion of your website, along with full disclosure of how it can integrate with your Google Analytics account for even more powerful reporting capabilities, be sure to check out Google Analytics Uncovered for Zen Cart: The Workbook..

Part 4 of this series delves into the use of Conversion Tracking for Google Analytics to help increase your conversion.

Share This Article With Others! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Sphinn
  • DZone
  • BlinkList
  • Reddit
  • Slashdot
  • SphereIt
  Don't miss a single tip! Subscribe to my RSS feed.

Related Posts

  • NEW RELEASE: Simple Google Analytics v1.2.0 - New “ga.js” code compatible
  • NEW RELEASE: Simple Google Analytics Version 1.2.2
  • Google Analytics Demystified: Part 2 - Vanilla Google Analytics


  • 15 Responses to “Google Analytics Demystified: Part 3 - E-Commerce Tracking”

    1. Amy McCoy said:

      It would be very helpful if you were to put the actual values that Zencart uses into the ecommerce code you have listed. I didn’t get the Analytics module to work for ecommerce, so I ended up going into my database to find the correct id’s for the code and then inserting the code into a footer banner.

      Just a suggestion :o) I am looking forward to your ebook. I have utilized the recommendations from your blog and have seen great results! Thanks for all you do…
      Amy

    2. econcepts said:

      Amy,

      Are you using the Simple Google Analytics Contribution?

      If you are, then e-commerce tracking is already installed with it.

      If you are not using that, and are doing it by hand, then you will need to alter 2 different files to get it to work with Zen. You’ll need to edit:

      /includes/[your_template]/templates/common/tpl_main_page.php

      and

      /includes/modules/pages/checkout_success/header_php.php

      Glad that you have found success by implementing my continued suggestions on this site. I only post what I have already tested and have found to work.

      I’m constantly testing and re-testing new options. As I find those that work, I like to let others know.

    3. Ben said:

      So do we just enter this code without any modifications?

      UTM:T|[order-id]|[affiliation]|
      [total]|[tax]| [shipping]|[city]|[state]|[country] UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|
      [quantity]

      Or do we need to alter it to fit our set up? Also, based on your comment above, we also need to edit the main page and header template file? I thought it was just the checkout_confirmation page that got this e-commerce tracking code.

    4. econcepts said:

      So do we just enter this code without any modifications?

      Ben,

      I have edited this post and updated it with the code you should use if you are manually inserting e-commerce tracking into Zen Cart.

      Keep in mind that if you are using the Simple Google Analytics module for Zen Cart, you should not have to insert code by hand at all to install e-commerce tracking. That is automatically done for you when you install the module.

    5. Skye said:

      Hi Eric,
      Thank you for your wonderful help! It’s really helpful, especially if you are a new Zenner like me.
      I came upon your site right after I implemented a GA tracking which was suggested by “ses707″ on Zen forum:
      http://www.zen-cart.com/forum/showpost.php?p=159558&postcount=33=

      Does the solution provided on Zen forum achieve the same results?

      I would have loved to use the Simple Google Analytics module but it is for v1.3.6 and I’m running v1.3.7

      Thank you for the help!

    6. econcepts said:

      Does the solution provided on Zen forum achieve the same results?

      It looks similar, however, since I have never used that exact code, in the places they mentioned, I can’t for sure say.

      I can say that that solution does not include Conversion Tracking.

      I would have loved to use the Simple Google Analytics module but it is for v1.3.6 and I’m running v1.3.7

      The Simple Google Analytics module works just fine on 1.3.7 (I’m using it on a few sites running 1.3.7 right now). Anything over 1.3.6 it works with. I even think it works on 1.3.5.

    7. Shawn said:

      I am sure that most people figured it out, but for a newcomer it may not be so obvious. Here were your original instructions:

      /includes/[your_template]/templates/common/tpl_main_page.php

      Should it not have been:

      /includes/templates/[your template]/common/tpl_main_page.php

      Also the latest download (1.1.1) from the Zen Cart site does not have the files already modified so I had to do the manually config instructions. My current version of ZC (1.2.6 I believe) did not have $zv_order_total_cd = $orders->fields[’order_total’]; or the other type of code. You may want to say you need to copy and paste this line (if you do not have it) at the beginning of the instructions instead of the end.

      Just some thoughts :o)

      Shawn

    8. AJ said:

      On December 13 2007, Google updated Analytics to use ga.js instead of using urchin.js. See the following post: Google Analytics ga.js. How does this affect integration of ecommerce tracking for Zen Cart?

      Google shows a way to do this manually for any shopping cart system: http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528, but it seems there should be a plugin out there that would make integration with ZenCart even simpler.

    9. econcepts said:

      For Zen Cart, I have already developed the updated plug-in using that replaces the “urchin” code with the updated “ga” code. It is set for release here later today or tomorrow.

    10. Robin said:

      Do you know if the tracker can recieve null data and still work?

      pageTracker._addTrans(
      "",
      "",
      "{$order.grandtotal|commify}",
      "{$order.taxtotal|commify}",
      "{$order.shiptotal|commify}",
      "{$info.billing.billing_city}",
      "{$info.billing.billing_state}",
      "{$info.billing.billing_country}"
      );

    11. Eric Leuenberger said:

      Do you know if the tracker can recieve null data and still work?

      It won’t “break” the tracking outright. It will cause some strange figures in your e-commerce reports with regard to sales figures, product info. etc…

      Why would you ever see a “null” transaction? If you sold a product, the transaction should include the data relating to that product.

    12. Robin said:

      Why would you ever see a “null” transaction? If you sold a product, the transaction should include the data relating to that product.

      The current commerce engine we are using doesn’t track order id numbers so that field would be null. I could place some arbitrary data in there if it meant actually getting some results on my e-commerce reports. Currently we have had absolutely no success with it. Here is a sample of what should be a tracked transaction:

      var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

      var pageTracker = _gat._getTracker("UA-XXXXXX-X");
      pageTracker._initData();
      pageTracker._trackPageview();

      pageTracker._addTrans(
      "",
      "",
      "79.89",
      "4.95",
      "14.95",
      "Burbank",
      "CA",
      "United States"
      );

      pageTracker._addItem(
      "",
      "41305",
      "Leather Curved Focus Mitts with XL Hand Cage",
      "",
      "59.99",
      "1"
      );

      pageTracker._trackTrans();

    13. Eric Leuenberger said:

      Robin,

      I see. You’ll have a tough time getting accurate results for ecommerce without a unique product id.

      Entering arbitrary info into that field won’t do a whole lot of good either unless, that information remains consistent and does not interfere with a later “arbitrary” number.

      If your current ecommerce engine doesn’t track order id numbers, then how do you keep track of orders? What’s to prevent one from interfering with another?

      I would take a careful look at your current ecommerce system if it does not track order ids. if you plan on expanding and growing, that could cause a problem in the future.

      Just a few thoughts.

    14. Robin said:

      Thanks Eric… just a follow up. I am still not getting any data in the reports at all. Accurate or not there is nothing coming through for the E-Commerce content. Is there anything wrong with what you see above that could indicate such a lack of content?

    15. Eric Leuenberger said:

      With the exception of the initial “transaction” id, the code above looks ok.

      Have you turned on E-Commerce tracking for your Google Analytics Profile?

      If you haven’t done that yet, then it won’t track ecom data no matter how good the tracking code is?

    Post a Comment on This Article

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>