Sunday, 7 February 2010

Google Analytics Custom Variables – part 1 - Introduction

One of the most underused features of Google Analytics is the “Custom Variables” report, not to be confused with the “User defined” visitor tracking report. Custom variables were made available in Advanced Segments and Custom Reports in December 2009 and are one of the most powerful additions of the last 6 months.

What are custom variables?

Let’s have a practical example. Let’s suppose we have an office supplies online shop that is selling to several typologies of customers let’s say:
  • Consumers
  • Home office, small office
  • Large businesses
  • Public administrations
At the same time let’s suppose that the products sold online fall into 3 broad classes:
  • Computer and Printer hardware
  • Office supplies and stationery
  • Office furniture
With custom variables we will be able to tag a visitor with a customer type (the first variable) according to different factors like: Registration data (if it’s already a customer), Landing pages, campaigns the visitor is coming from, content he is viewing and so on. Additionally we will be able to tag the visitor with a second variable corresponding to the type of products he is viewing preferentially. The possibilities are endless as we will be able to cross correlate the two dimensions and have a better understanding of our visitors.

What can we use custom variable for?

Additional examples are:
  • Segmenting visitors
  • Segmenting customers according to the order history
  • Segmenting visitors based on the campaigns they see prior converting
  • Segmenting visitors based on content visited
  • Segmenting visitors based on landing page
…to name a few.

How can we use Custom Variables?

In order to use custom variables we will have to modify the tracking code (the snippet of JavaScript that we paste before the tag) and use the _setCustomVar() method. I will give all the details on how to do this practically in next week post “Google Analytics Custom Variables – part 2”

Variable attributes

The Custom Variables features is powered by a new method: _setCustomVar()
As we will see later we can have up to 5 simultaneous variable tracking. Each variable has 4 attributes.

1 - Variable Scope

Before going deeper into our explanation we have to introduce the Variable scope concept. The scope is the context where we are going to define the variable. It is quite important to understand this.
There are 3 scopes:
1.1 - Page-level
Every type of variable that we can associate to a single page view (or event tracking) can be set at the page level.
Example: In our office supplies shop, suppose that we classify the product pages with a product type (“Computer and Printer hardware”, “Office supplies and stationery”, “Office furniture”). We will then set a variable with 3 possible values that we will associate to each product page. We will be than able to count the page views for each of the product type we have defined.

Pushing the idea further, if we want, we could also create a subtype variable extending our product classification.
1.2 – Session-level
Every type of variable that we can associate to a session. Example: we can number the visits that resulted with purchase and compare it to the visits that didn’t have any purchase attempt. In the session level scope, the variable will be counted at the end of the session and it will take the last value assigned before the end of the session.
1.3 - Visitor-level
Every type of variable that we can associate to a permanent cookie. You would typically use visitor-level variables to distinguish categories of visitors across multiple sessions. For our example you would assign the visitor type (Consumer, Home office small office, Large business or Public administrations) once and then track this value across multiple visits.

2 - Name

This is the string with the variable name. It will appear in the top-level Custom Variables report.

3 - Value

This string contains the value that will be attributed to the variable. Example, you could define the variable “gender” and give as value either “male” or “female”.

4 - Index

This is the placeholder or slot in which we are going to load the variable. Index can be an integer from 1 to 5. A variable should not be used across different slots. Theoretically you will be able to set 5 page level, 5 session level and 5 visitor level variables, for a total of 15 variables. In practice thought there will be interactions between variables making the reuse of variables in the same slot tricky. I will detail these interactions in the next post. My advice is to start using a maximum of 5 different variables only, placing them in different slots. In my next post I will give you few tips on how to use more than 5 variables.

Syntax

Now that we have seen the attributes we can set to the variable let’s see how we can call the function.

_setCustomVar(index, name, value, opt_scope)

Index: Can have integer values from 1 to 5
Name: The name for the custom variable (a string)
Value: The value for the custom variable (a string). Be careful that the sum of the length of Name and the length of Value cannot exceed 64 characters.
Opt_scope: This is he scope for the custom variable. The possible values are 1 (visitor-level), 2 (session-level), or 3 (page-level). When left undefined, the custom variable scope defaults to page-level interaction.

Next week

Next week I will show a practical implementation of the custom variables report and how to alter the tracking code in order to start using this extremely powerful new feature.

8 comments:

  1. Great coverage of Custom Variables.

    You can actually get more than 5 custom variables.

    Details here:

    http://analyticsimpact.com/2010/05/24/get-more-than-5-custom-variables-in-google-analytics/

    ReplyDelete
  2. Thanks! :-)

    Wow.. Ophir, that is great info! This undocumented feature is incredibly useful... I am going to test it asap!

    ReplyDelete
  3. It’s a pretty interesting tool. I will definitely be using it once I get the chance. Thanks for sharing!

    ReplyDelete
  4. This tool looks as though it will be perfect. Thanks so much for the suggestion!

    ReplyDelete
  5. Hi Luca,

    above, when explaining page-level variables, you say, that "We will be than able to count the page views for each of the product type we have defined." Is that really true? And if yes how?

    Or isn't more like you are able to count the page views that have been made during visits that also visited at least one page from one of those categories (e.g. "Office furniture")?

    Thanks for clarifying this!

    --Jakob

    ReplyDelete
  6. Hi
    how can we find out unique users and frequent user and infrequent users with some business logic.
    newuser- first time visit
    frequent - visiting within one month
    infrequent - visiting after one month
    newuser- visited after 3 months..
    can we get reports for this? need guidlines from you to achive this.
    regards
    Guru

    ReplyDelete
  7. Hi. Great to see people working on this.

    I think custom variables are awesome, although we've found some issues while implementing it.

    Right now, we're seeing that "Bounce Rate zero for the content tracked with Custom Variables."

    I have been searching the web, even the official forums, without getting any answer.

    We would really appreciate if anyone can assist us on getting it to work. We are using Page level Custom Variables, in case this is useful.

    Thank you very much for your help. Looking forward for an answer.

    Juan

    ReplyDelete
  8. Hi, does anybody had probles tracking the bounce rate?

    Right now, we're seeing that Bounce Rate is zero for the content tracked with Custom Variables.

    I have been searching the web, even the official forums, without getting any answer.

    We would really appreciate if anyone can assist us on getting it to work. We are using Page level Custom Variables, in case this is useful.

    Thank you very much for your help. Looking forward for an answer.

    Juan

    ReplyDelete