Last week wrote a piece about using custom segments to exclude yourself from Google Analytics tracking. I didn’t stop to think that some folks may not know what custom segmentation is and how it is implemented with Google Analytics. So today I’ll cover how to setup and use custom segmentation with Google Analytics.
Segmentation of data involves slicing the data based on some visitor characteristic. A very common data segment is new and returning visitors. This means that we can look at the website traffic and identify what portion is generated from new visitors, what portion is generated from returning visitors and what those groups did while on the site. Google Analytics has a number of pre-defined segments that you can find in the Marketing Optimization > Visitor Segment Performance reports.
In addition to these standard segments, you can define your own custom segment. This means you can divide your traffic into various groups, as defined by you, and then observe how those groups interact with your marketing activities and your website.
If you need more information about segmentation, or why you should do it, you can or you can read an article on ClickZ. There’s a bunch of them.
So, how do we add a visitor to a custom segment with Google Analytics? We use a JavaScript function to set a special cookie on their machine. The function is named __utmSetVar(’v’) and the cookie is named __utmv. We can call this function any where JavaScript can be called. When you use this function replace ‘v’ with some value. This is the value that will be stored in the cookie and will be visible in your reports. Here’s an example.
Let’s say we have a contact form on our site and we ask the visitor to specify their gender. There is a drop down box with the different responses. We can call the the __utmSetVar() function when the value in the drop down box changes. This will set the user-chosen value as a custom segment. After the segment has been set all of the visitor’s activites will be ‘bucketed’ into that segment.
There are a number of ways to view how your custom segments perform. The easiest way is using the Marketing Optimization > Visitor Segment Performace > User-Defined report. This shows the visits, average page views per visit, and goal conversion rate for your custom segments.
You can also cross segment many Google Analytics reports based on your custom segemtns. To do this click on the red chevron at the left side of a report (like the Top Content report). Then choose Cross Segment Performance and User Defined. GA will segment that line item based on your custom segments.
There is one major limitation to the Cross Segmentation functionality. You can only set one custom segment cookie at a time, therefore you can only set one custom segment, per visitor, at a time. Luckily this is pretty easy to get around. Recently, I wanted to track the conversion rate for certain genders and age groups. So I wrote some custom JavaScript that takes the gender data and age data from a form, combines it into a single string, and then sets the custom segment cookie. When the __utmSetVar() function is called it looks like this:
__utmSetVar('male:25-35')
‘male:25-35’ would be the value stored for a ‘male’ in the age group of ’25 to 35′. This value dynamically changes based on the data the user enters into the form.
That’s about it. Questions? Comments? Just want to say hi? Leave a comment below.
where in google analytics to you parse that combined string so you can see reports on gender alone or age range alone?
Thanks! I *knew* there had to be a way to pass more info to Urchin/GA, but I was having troubles finding the technique until I found your site in a google search. For me, I’m tracking an application with its own authentication system (NOT HTTP auth) and I’d like to be able to segment based on user id. This seems like just the thing.
Thanks again,
Justin
Hi Moshe,
You really can’t parse the custom segment variable apart once it’s set. What you can do is use the in-report filter to filter your results. Or you could create profile filters based on the custom segment value.
So, if you had a custom segment that looked like this:
male:18-35
and you wanted a profile based on that information, you r profile filter would be an include filter with the regular expression 18-35.
Hope That helps,
Justin
Thanks for the great tutorial, I’ve now added integrated support for segmentation in to our Drupal Google Analytics module available from http://drupal.org/project/google_analytics
Is it possible to unset the user defined value (for instance when a visitor logs out)?
Hi Rasmus,
Great question. To unset a custom segment you need to delete the _utmv cookie. This can be done with some server level code or with some custom JavaScript.
Thanks for the question,
Justin
Simple but efficient :)
i also segment my data with filters
so i can get more segment for one customer
For exemple i can get the trendings of the males 25-35 of london, and compare them to those of paris
:)
Hi Justin,
Segmentation was a missing feature of Google Analytics. All other enterprise analytics tool were offering this, but now Google is giving it free. You can dissect data much easier (segmentation was possible even before in GA, with custom filters and profiles as you mentioned, but now it is much easier). I am planning to create a series for segments idea. The first segment we have described on Google Analytics Segmentation page is called keywords with conversions. Please have a look.
Feel free to visit our blog and if you have any ideas on what segments could be useful, leave a comment and we will try to write a post on that one.