Expand Reporting with Google Analytics

by Brennan Mann 27. April 2010 06:46

Before  I post the article on expanding reporting with ASP .Net 4.0, I want to show you a solution you can implement in a couple of hours. The folks at Google have put together an astonishing package of reports and analytics.  If you have not already, sign up for your free Google Analytics account (click here to sign up here).  Google offers us a gold mine of reporting tools.  Some of the reports include:

  • Pageviews
  • Average Pageviews
  • Visits
  • Visitor Overviews
  • Time on site
  • New vs Returning
  • e-Commerce Tracking
    • Order Header Level Detail
    • Order Detail Level Detail
  • Depth of Change
  • Loyalty
  • User-defined Reports
  • Analytics Intelligence
  • Dashboards
  • Custom Variables
  • Data Export  - Incliudes Excel, CSV, PDF and tab delimited files

Screen Shot of Home Page and Dashboard ( click on the image to zoom in)

 

Screen Shot of e-Commerce Tracking Home Page ( click on the image to zoom in):

Product Statistics

 

Order Level Transactions - Includes Ecometry order number, order total, tax and P&H. Click on the order number to drill-down on the order details ( click on the image to zoom in).

 

How does all this work?

A simple cut and paste ( Thanks to Google).

Overview of the process:

 

1.) Customer confirms his/her order on the order recap page.

2.) The website processes the order and sends the data to Ecometry's WEBORDER

3.) WEBORDER responds to the request and acknowledges the order

4.) Order Confirmation is displayed to the customer

5.) After the webpage is rendered, we submit a transaction to Google. This transaction happens behind the scenes. It can take up to 24 hours for your transaction level detail to be visible in Google Analytics.

 

Over the weekend, I implemented Google's e-Commerce Analytic tracking on an Ecometry e-Commerce website . The e-Commecre tracking provides a rich set of tools to track conversion rates, transactions, purchased products, and transactions. The entire setup took about 30 minutes.  Google really does all the work. We use already written JavaScript provided by Google to communicate with the Google Analytic servers. There are three JavaScript methods required for e-Commerce tracking.

 

Three JavaScript Methods are used:

 

1.) _addTrans()

This method initializes/creates the transaction object. The transaction object collects all the information about the a single transaction ( order ids, shipping charges, billing address...).

2.) _addItem()

The addItem() method tracks individual item transactions( SKU, price, category and quantity).

3.) _trackTrans()

The trackTrans() method finalizes the transaction to Google. It usually takes about 24 hours for all the transaction data to be available on Google.

 

Basically, we are going to add three JavaScript Snippets to the order confirmation page. The instructions below only apply to EEM ( aka Ecometry .Net Framework).

 

1.) The first snippet initializes the tracking object and add order header level information. I placed this snippet at the top of the order confirmation "aspx" web control/page.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-111111-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '<%=Cart.OrderNo%>',           // order ID - required
    'My Shopping Cart',  // affiliation or store name
    '<%=Cart.TotalAmount.ToString()%>',          // total - required
    '<%=Cart.TaxAmount.ToString()%>',           // tax
    '<%=Cart.ShippingAmount.ToString()%>',              // shipping
    '<%=Cart.Buyer.City%>',       // city
    '<%=Cart.Buyer.State%>',     // state or province
    'USA'             // country
  ]);

</script>

 

2.) The second snippet adds the order details to the tracking object.  You will need to place this snippet in the "foreach" cart lines loop.

<script type="text/javascript">

<%
                 
         
     foreach(CartLine line in  ship.CartLines) {   

%>
    
<script type="text/javascript">
   // 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
  _gaq.push(['_addItem',
    '<%=Cart.OrderNo%>',           // order ID - required
    '<%=line.Product.ItemNo%>',           // SKU/code
    '<%=line.Product.Description%>',        // product name
    'DR',   // category or variation
    '<%=line.Price.ToString()%>',          // unit price - required
    '<%=line.Quantity.ToString()%>'               // quantity - required

  ]);            
 </script>
 <%} %>  

*Do not copy the "foreach" code snippet. I only included this to demostrate the JavaScript placement. Please use the one already in place on your order confirmation page.

3.) The third snippet sends the data to google. I placed this snippet after the last line of HTML/ASP in the order confirmation "aspx" web control/page.

<script type="text/javascript">

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

  (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';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
  })();
</script>

That's it. Give Google about  24 hours to digest the data and you're off to the races.

A few suggestions:

  • Make sure you enable your Google Analytics web profile as an e-Commerce website. If you don't, the e-Commerce tracking will not work.
  • Make sure your Google Analytics are working with the main tracking object before adding the e-Commerce tracking. Every website profile you configure is assigned a Google Analytics tracking number ( GA-1111111-1). Google will provide you a tracking JavaScript snippet to be placed on all your pages. This is not the same as the e-Commerce setup.  If you are using EEM ( aka Ecometry .Net), you should place the JavaScript snippet in your HTML master template(s) or in the website footer page. Google recommends placing the JavaScript snippet right before the closing "</body>" HTML element.
  • When placing the JavaScript snippets, make sure you are in scope to use the ASP variables. If you are not, a null exception will be thrown.
  • Do your testing on a test website.

 

Happy data hunting.

Please feel free to ask any questions!

 

 

 

 

Tags: , ,

Analytics | Ecometry® | Programming | Reporting

Comments

About the author

Brennan Mann started working on the Ecometry® platform in 2000. For the past ten years, Brennan has provided custom solutions and consultation for Ecometry® and other e-commerce platforms. In 2006, Brennan entered the realm of  Microsoft's .Net Technology.