Segment your Traffic with the User Defined Report

Tuesday, July 07, 2009 | 5:00 PM

Labels: ,

Have you ever been in the Visitors section of your favorite Google Analytics profile and wondered what the heck “User-Defined” was? Well today it's time to find out.

So, what is “User-Defined?"

The user defined variable allows you to "label" a visitor if they complete a certain action on your site, such as making a purchase or visiting a key page. These labels are useful because they last across multiple visits to your site.

These labels are often called Custom Segments (or Custom Segmentation). You can see the data from these Custom Segments in the User Defined report, which is the last report of the Visitors section in Google Analytics.

How do I add these “labels” to my website visitors?

Making use of the User-Defined report in Google Analytics requires a bit of extra coding help from your IT department or webmaster, but it’s often well worth the effort.

For example, let’s say that I want to add a label of “customers” to any visitor who reaches my shopping cart’s receipt page. In order to do this, I would add an additional line of code to the Google Analytics Tracking Code (GATC) on my receipt page. It would then look something like this:

<script type="text/javascript"> 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")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-XXXXXXX-1"); pageTracker._trackPageview(); pageTracker._setVar(”customers”); } catch(err) {}</script>

Notice the line in bold that includes _setVar. When this is present on a page within the Google Analytics Tracking Code, an additional cookie (called the __utmv cookie) gets set on a visitor’s computer, with its sole purpose being to identify the visitor by the label (or value) that you used in the code. If you take a look at the code example above, you will see that I used the termcustomers,“ the label that I want to appear in the User Defined report.

Now, on their next visit to the site, they will be identified as a part of the “customers” segment in the User Defined report, allowing you to perform analysis on all visitors who have purchased something from your online store. Neat, huh?

Can I use _setVar when someone clicks on a link instead of visiting a page?

Yes - you can also use the pageTracker._setVar function when someone clicks on an important link on your site, or makes a key selection on an important form that you want visitors to fill out. For example, if you wanted to add a custom label to any visitor who clicks on your “Live Help” applet, you can ask your IT department or webmaster to add an “onClick” event, and give them the following line of code:

onClick="pageTracker._setVar('Needs Help');"

What will this look like in the end?

When all of your coding is complete, check the User Defined report after about a day or so and you should see something like this:

After the data has been collected by Google Analytics, you can interact with it just like you would with any other report. Click on the “Goal Conversion” tab directly above the table to see how many customers have reached key pages of your site, or use the dimensioning feature to see what sources of traffic were responsible for bringing these special visitors to your website!

Are there any other ways to use _setVar?

One neat usage of the _setVar function is to use it to exclude your own traffic from reports when using a dynamic IP address. For example, let’s say that you wanted to exclude your entire company’s traffic from appearing in reports, and your company uses dynamic IP addresses.

Because it would be nearly impossible to write a filter to exclude traffic from a dynamic IP address, you can create an HTML page that is not a part of your website and add Google Analytics Tracking Code with the call to _setVar and a label of “employees” (or something similar).

Next, you can ask each employee to visit that page from their browser of choice – this will drop a cookie on their computer, identifying them as “employees.” Finally, you can then apply a filter with the following specifications to your profile, and your internal traffic will be excluded:

  • Filter Type: Custom Filter >> Exclude
  • Filter Field: User Defined
  • Filter Pattern: employees
  • Case Sensitive: No

Some technical notes about Custom Segmentation:

  1. As we just talked about, when a person visits a page calling the _setVar function, the __utmv cookie is set on their computer. This is a persistent, first-party cookie that has a lifetime of two years. This means that every time a user with a __utmv cookie returns to your site, the label assigned to the user will continue to identify them as such until they either delete the cookie or visit another page with another call to _setVar with a different label.

  2. The purpose behind something like a User-Defined report - and Custom Segmentation in general - is that it is not designed to be updated very often. This label, for the most part, should be a permanent one for a visitor. You should only use _setVar on pages like a receipt page of a shopping cart, or an account registration “success” page for a visitor who becomes a member of your site. You shouldn’t use _setVar on your homepage, or use several different _setVar’s with different labels scattered across many pages of your website.

  3. Google Analytics - at this time - only has the capacity to store one custom segment at any one time for one website. So if you are using multiple calls to _setVar on your site, Google Analytics can only store the latest value that a visitor runs into in the __utmv cookie. John Henson at LunaMetrics – a fellow Google Analytics Authorized Consultant - has created a custom version of the Google Analytics Tracking Code that can support multiple custom segment labels at any one time.

  4. On the other hand, Google Analytics uses what they call the “first association” of the session for visitor session calculations. If you are using multiple calls to _setVar on your site, be aware that if a user runs into the first one, and then runs into the second one in the same visit, their Goal Conversion and Pages per Visit metrics would be attributed to the label of the first encounter with _setVar.

  5. For page view calculations, Google Analytics uses the most recently defined value. So if a person runs into the second instance of _setVar on your site, all of their pageviews afterwards - including the current pageview - will be attributed to the second _setVar’s label, even though as we just learned in #4 above, visitor session information is attributed to the first encounter of _setVar.

A full, technical explanation of _setVar and the User-Defined Report can be found here.

Summary

The User Defined report in Google Analytics is a great place to start segmenting your traffic. With a little bit of help from your IT department, you can not only begin to collect awesome data, but you can also begin to gain advanced knowledge about what makes your VIP website visitors register, sign-up for your newsletter, or purchase something from your online store. This will definitely help you become that Analysis Ninja that Avinash Kaushik loves to talk about!

Written by Joe Teixeira of MoreVisibility, a Google Analytics Authorized Consultant.

16 comments:

anelson said...

Thanks for the detailed explanation....it makes much more sense when you think of it as "labeling".

I have seen the User Defined reports used to label "Customers" and has given a nice look at how Customers behave on a website versus non-Customers....definitely under-used. However, I have not seen this used for tracking visitors who "Need Help" or who are employees...great ideas!

tara.pingle said...

This is great information - I've been wondering about the User Defined section for a while!

To me, this brings up the question of when to use User Defined instead of Event Tracking or Goal Tracking? This seems to blur the line between those methods.

For example, if I want to track people who subscribe to my blog, should I set a User definition as "Blog Subscriber", or should I set an Event Tracking for it? What about creating a "Blog Subscription" goal?

It seems to me like the advantage of User Definitions is that you can see both Event Tracking and Goal Tracking like activities alongside each other for comparison... such as people who complete a form versus people who click on "Help" links.

I would like to hear more on this from the Analytics Blog, if possible. :)

katrina.liu said...

Thank you so much GA team! :)

michael said...

I'm curious how you know this is working. Does the filter only filter during the reporting stage (i.e. when I look at my stats) or does it filter during the data gathering stage (i.e. my visit does not get recorded)?

I tried to disable the filter, but didn't see any change in my stats and the User Defined value did not record my value.

Joe Teixeira said...

Thanks everyone for your replies!

@anelson - It's a great use for websites that use a "Live Chat" or "Need Assistance" applet. You can then zero-in on what pages this group of people visited and where on the website they may be having trouble

@Alistair - You are correct. Selecting the "Visits with Conversions" or "Visits with Transactions" Advanced Segments will show you all of the data pertaining to those groups.

In those Conversion / Transaction situations, it can definitely be used in lieu of a User-Defined label. However, there are many more uses for User-Defined - like, assigning a label to a visitor based on a form selection (and not necessarily completing the form). Or, using the "setVar" function on visitors who download a certain PDF document from your site.

Keep in mind that Advanced Segments cannot be applied to the Absolute Unique Visitors report, Keyword Positions, or the Funnel Visualization report.

@Tara - You definitely touch on a very interesting part of the whole analytics space. There are a lot of data points to take into account, and it's sometimes very difficult (even for me) to figure out what's REALLY important, and what other stuff is just medium-important.

I like to look at Goals, Events, and Labels like this:

Goals: Actions that you want visitors to perform on your site (Contacting you, buying from your store, filling out an RFP form)
Events: Actions / activities that visitors happen to perform while on your site (playing your flash-based game, viewing your latest video, click-and-dragging your latest homepage AJAX applet)
Labels: These are rarely-changing identifiers for specific visitors (customers, managers, owners, high annual salary, etc...)

Great comments!

Logan said...

wow, many thanks for posting this. the user-defined section was growing cobwebs because it seemed over my head. Makes much more sense now that you've presented some great examples of usage.

lokesh singh said...

That's right but more visual steps are needed.

webmaster said...

Not sure if I understand where to add the onClick="pageTracker._setVar('Needs Help');" statement. Do you add it to the a href link code? Or add it to the rest of the ga.js script?

Yiu Pang said...

If i have a page with is a item listing page using _setVar('list-type')
and a detail page using _setVar('catalog')

if i visit from listing and the to detail, will it bring the cookie from listing page to detail, so that will have 2 _setVar cookie on a single page?

becoz i using custom define segment report, i choose 2 of my custom var,
i found that the listing page contain detail page custom setVar cookie
eg: all visit:1,list-type1, catalog : 1

but it should not happen, right?

Alden said...

The Google Analytics IQ course contains a lesson on using setVar:
http://services.google.com/analytics/breeze/en/customvisitorsegmentation/index.html

@webmaster - add the statement to the rest of the ga.js script, on the page where you want the custom variable to get set.

@Yiu Pang - thanks for trying it out -- yes, you'll only have one custom variable.

Indus said...

This is very useful information. We will implement this script code in to our site and let you know the feedback to you all...


Thanks Google
Senthilvel S.P

James said...

Is it possible to set a user-defined value on a click from a third-party website?

Specifically, I want to track all visitors from a Facebook CPC campaign so that I can check how many conversions we receive. (Unfortunately, due to the limitations of our shopping cart it's not possible to just tag the URL in the normal way and look at conversions from this source.)

BuzzBox's Fast Forward Button said...

I did your script and I don't see the __utmv get set on Mozilla for an Mac. Have you seen this problem?

Amanda Record said...

Great post!

EVC said...

Is it possible to use a session ID for the variable? In other words, I want to Identify each individual by name when they purchase. They enter their name in the checkout process. So can I create a variable based on this and insert the name of the variable like this? _setVar('variable')

Gabriel said...

hi EVC,

Tracking the names of users is forbidden by our Terms and Conditions. Please don't do that.

Gabriel from the Google Analytics Team