Google Analytics E-Commerce Tracking Pt. 4: Tacking Lead Gen Forms

July 2, 2008 by Justin Cutroni

One thing that I try to stress in my client work and training is that Google Analytics is a platform. If you understand the framework you can use it to track many different things. E-commerce tracking is one part of Google Analytics that is particularly flexible and can be used many different ways.

There’s a lot you can do with e-commerce tracking even if you’re a non-commerce site. You can use the e-commerce reporting to monetize lead gen forms and measure visitor interactions with a form.

The Need

Let’s say we have a lead gen site that sells books, cars and jets (a completely unlikely combination). The site has a very simple lead generation form that let’s the user choose the item they are interested in and their time frame for purchase.

We want to measure which fields visitors fill out, the values they choose, and the overall value of the form.

The Implementation

To measure the above I created a simple form using HTML and JavaScript. Here’s what the form looks like:

And here is the source of the above form:

When the visitor submits the form the JavaScript code assigns a value to both the item that the visitor chose and their time frame for purchase. It then calculates a total value for the form by summing both values.

In this example a form that includes a high priced item (like a jet) and a short time frame (buy now!) is worth more than a low priced item with an unknown time frame. I chose arbitrary values for each item and each time frame, but you could derive these values from business data.

After manipulating the data the code places both pieces of information in the GA e-commerce format where they are happily whisked away to Google.

I decided to do all of the calculations in JavaSript because it was easy. You could create a “form calculator” on the server side, but you would still need to format the data like a transaction in order to send it to Google Analytics.

The Data & Analysis

Remember, we’re using the e-commerce framework to equate products to form choices. So any report that displays product information will really show form elements and their values.

The best example of this is the E-Commerce > Product Performance > Product Overview report. This report simply lists all of the products that were purchased in all of the transactions.

Based on the way I created the code, each “product” in the report will be a combination of the item that he visitor is interested in and their time frame for purchase.

Google Analytics Prodcut Performance Report.

How is this data actionable? This information is the direct voice of the visitor. The visitor is literally telling us what they want and when they want it.

From the report above we can see that everyone wants a jet. Most visitors did not specify a time frame for purchase but one visitor wanted a jet today. I’d call that a hot lead!

Another report that is very useful is the E-commerce > Transactions report. In our configuration this report lists all of the forms that have been submitted and the value of each.

Google Analytics Transaction Report for Lead Gen Site.

The great thing about this report is we can drill into each transaction and review the specific form details. If I click on the first transaction in the report above I get the details of the form (see image below).

Individual Google Analytics Transaction Detail

I know this example is not that exciting, but image a form with many, many fields. You would be able to see all of the visitor’s choices and better understand what made a specific form valuable.

The effect of using e-commerce tracking for a lead gen form goes far beyond the e-commerce reports. Remember many reports in Google Analytics have an e-commerce tab that displays monetary metrics related to the data in a report.

For example, the Traffic Source > All Traffic Sources report will show metrics like average order value, transactions and revenue for each traffic source. If you use standard goal tracking you will only get conversion rate. I think this is far more valuable.

Google Analytics Traffic Sources report for Lead Gen.

A Reminder

You’ve probably figured out that you can use e-commerce to collect many different types of data. Please be mindful of your site’s visitors and the Google Analytics privacy policy. It is not permitted to collect personally identifiable information using Google Analytics.

This is part 4 in a multi-part series on e-commerce tracking. You may be interested in parts 1, 2 and 3:

Google Analytics E-Commerce Tracking Pt. 1: How It Works
Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup
Google Analytics E-Commerce Tracking Pt. 3: Why EVERYONE Should Use It

Subscribe:

Google Analytics E-Commerce Tracking Pt. 2: Installation & Setup

January 22, 2008 by Justin Cutroni

This is part 2 in my series on Google Analytics e-commerce tracking. In part 1 I described, at a conceptual level, how GA e-commerce tracking works. In this post I’ll get into the specifics of the code and how to install it.

This isn’t the most exciting stuff (that will be part 3), but a correct setup leads to correct data. :)

Step 1: Activate the Reports

The first step in setting up GA e-commerce tracking is enabling the e-commerce reports. Log into GA and edit the profile settings. Specify that your site is an e-commerce site. This activates the e-commerce reports.

Google Analytics E-Commerce Reports

There are other e-commerce settings that don’t get much use (unless you’re an international site). You can specify one of 25 different currencies (wow!) and the number of decimal places you would like displayed (1,2 or 3). Even if you use USD you can specify 3 decimal places. Go ahead and try it, it’s interesting.

Remember, e-commerce reports is a profile setting that is “off” by default. You’ll need to activate the reports for each new profile you create.

Step 2: Tag your Receipt Page

I know this seems like a silly step, but make sure you add the GA tracking code you your receipt page. You must have the standard GA tracking code on your receipt page in order to track transactions. The reason is that the e-commerce tracking code is stored in the ga.js. If this file is not included on the receipt page then you can’t track transactions.

Step 3: Install the Code

This is the hard part: code construction. As we learned in part 1, GA uses a JavaScript collection technique to track e-commerce transactions. Your server code must inject transaction information into the GA JavaScript before sending the receipt page back to the browser. When the receipt page renders in the visitor’s browser the JavaScipt executes and sends the transaction info to GA.

Get ready for some construction.

Let’s take a look at the code:


<script type="text/javascript">
pageTracker._addTrans(
      "order-id", // required
      "affiliate or store name",
      "total",
      "tax",
      "shipping",
      "city",
      "state",
      "country"
); 

pageTracker._addItem(
      "order-id", // required
      "SKU",
      "product name",
      "product category",
      "unit price",  // required
      "quantity"  //required
); 

pageTracker._trackTrans();
</script>

The three parts of GA e-commerce trackingThe first thing that you’ll notice is that there are three distinct parts to the JavaScript. Each is a different method. The first section, identified by the _addTrans() method, creates the transaction and stores all the information about the transaction.

The second section, identified by the _addItem() method, is used to add an item to the transaction. You need to create an _addItem() section for each different item, or SKU, in the transaction. The order ID in the _addItem() method must be the same order ID used in the _addTrans() method. That’s how GA ties an item to a transactions.

The final section is the _trackTrans() method. This method actually sends the data to GA by requesting the __utm.gif file once for the transaction and once for each item in the transaction. So if you have 3 different SKUs in a transaction there will be 4 requests fot the __utm.gif.

The above JavaScript can appear anywhere on your receipt page. Just make sure that it appears after the main GA page tag. The reason is that the e-commerce code is part of the pageTracker object. If the pageTracker object has not been created then you can’t call the e-commerce methods.

Just to reiterate a point: you must create server side code that outputs the transaction data in the format above. If you do not have access to your shopping cart code, and your cart provider does not provide e-commerce tracking, then you may be out of luck.

Once the code has been installed you should begin to see e-commerce data in your reports.

Notes and Suggestions

Like many things in Google Analytics, there are some things that can trip you up:

  • If you do not wish to pass a certain piece of data to GA then do not add anything between the quotation marks. The only required fields are the order ID, the unit price of each item and the quantity of each item. Everything else is optional.
  • Do not use currency identifiers or commas (to separate thousands) in any of the numeric fields (i.e. total, tax, shipping). These characters have caused problems in the past.
  • Each piece of transaction data that you send to Google Analytics becomes a data element in GA, just like any other piece of data in GA (geo data, campaign data, browser data, etc.). You can do all sorts of neat things with filters and e-commerce data. More on this later.
  • The affiliate or store name field is no longer used in the GA reports. However, the data is still collected by GA so you can use it in a filter.
  • The transaction geographic data collected by GA is no longer used BUT it is collected. Google Analytics determines the location of the user, and thus their transaction, based on their IP address. The old version of the GA tracking code used the data specified in the transaction. Like the affiliate field, the data can be used in a filter.

Up Next

In the next post I’m going to talk about some creative ways to use e-commerce tracking. Specifically, why I believe that everyone should use e-commerce tracking on their website.

This is part 1 in a multi-part series on e-commerce tracking:

Google Analytics E-Commerce Tracking Pt. 1: How It Works
Google Analytics E-Commerce Tracking Pt. 3: Why EVERYONE Should Use It
Google Analytics E-Commerce Tracking Pt. 4: Tacking Lead Gen Forms

Subscribe: