My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google Analytics

Custom Visitor Segments

This document provides setup and usage instructions for custom user segments.

  1. Overview
  2. Setting Up Custom Visitor Segments
  1. Usage Guidelines
  2. How Visitor Segment Values are Applied

Overview

Google Analytics provides a number of pre-defined segments for your visitors, such as geographic region and language preference. You can create custom segments based on your website needs. Once these are working, you can see the break-down of visitors based on custom segments by choosing the custom segment dimension in the Analytics reports. For example, you might want to segment visitors according to the following:

  • members vs non-members on a site that has a member login
  • gender (based on the user providing you data)
  • income brackets

Setting Up Custom Visitor Segments

To create a custom visitor segment, call the _setVar() method in your web page. You can attach this call to a form widget, within the tracking code, or within a link to a page. Most typically, custom segments are set by client-side or server-side logic that sets the variable depending on the page being visited, or as a result of a selection on the part of the visitor, such as logging in.

The following example shows two code snippets, where the first is a series of links to sections of a pet store website, and the second shows the custom user segment that gets set when a user selects a given link.

<!-- Links to different sections of the site -->
<ul id="mainMenu">
  <li><a href="/home/dogSupplies.html">Dog</a></li>
  <li><a href="/home/catSupplies.html">Cat</a></li>
  <li><a href="/home/fishSupplies.html">Fish</a></li>
  <li><a href="/home/birdSupplies.html">Bird</a></li>
</ul>
<!-- Resulting page that sets a custom segment -->
<html>
<head>
</head>
<body>

Website Content

<script type="text/javascript">
function getUserPref() {
var pathName = window.location.pathname;
var startSlice = pathName.lastIndexOf('/') + 1;
var endSlice = pathName.lastIndexOf('.');
var pageName = pathName.slice(startSlice, endSlice);
var endPageSlice = pageName.indexOf('Supplies');
var petPreference = pageName.slice(0, endPageSlice);
var userType = petPreference + ' Lover';
return userType; } </script> <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-xxxxx-x");
pageTracker._setVar(getUserPref());
pageTracker._trackPageview(); } catch(err) {} </script> </body> </html>

Back to Top

Usage Guidelines

When custom visitor segmentation is working correctly on your site, a visitor cookie called __utmv is set to the selected value on the visitor's browser. This first-party cookie persists for 2 years unless it is over-written with a new value. (For more information on cookies in Google Analytics, see Cookies and Google Analytics.)

Customized visitor segments were designed for a specific type of use. To get the most out of using customized visitor segments, consider the following:

  • The custom user segment feature is designed to track infrequently changing visitor data.
    Think of the customized visitor segment as a way to define a relatively "permanent" demographic for your visitors. In general, custom user segments are most useful for session-wide user information. For example, an appropriate use of customized visitor segmentation would be to differentiate site members from non-members, or to track a selection made by your visitors that would not be updated frequently, such as age or income bracket. It would not be a good practice to design user segments for values that are prone to change, such as for tracking trends in visitor preferences for your products or services.

    For example, if your home page automatically sets the _setVar() value to "Non-member" and the login success page sets the value to "Member," two GIF requests are made, each with the respective value. (Note: Since this type of implementation sets and resets the custom segment values in a given session, it is an example of how NOT to implement customized visitor segments for member/non-members.)

  • For visitor session calculations, the value chosen is the first association of the session.

    If a change is made to the custom visitor segment value, the value attributed to the session is the first associated value for that user's session.
    For example, if a user visits your page and chooses "Bird Lover" from the menu in the example above and then later in the same session returns to the page and chooses "Dog Lover" from the menu, the data for that user's session will be assigned to the "Bird Lover" segment. Thus, the User Defined report under the Visitors menu would apply goal conversion and pages per visit metrics for that user under the "Bird Lover" segment because that is the value first associated with the given session. For the subsequent user session, the visitor session would be attributed to the "Dog Lover" segment, since would be the new value for the __utmv cookie, and the first associated value for the next session.

  • For page view calculations, the value chosen is the most recently defined value.

    If no _setVar() method sets the custom user segment for a given page, the value defined in the __utmv cookie determines which custom segment is applied to the page view. (This value might exist from a previous session or had been set from a previous page view.) However, if a change is made to the custom visitor segment value in the middle of a session, the value attributed to that page and any following pages is the most recently defined value. Using the same scenario, if the user first selects "Bird Lover," visits 4 pages, and then on page 6 of the session chooses "Dog Lover," and visits 4 more pages, the content reports will show 5 pages associated with "Bird Lover" and 5 pages associated with "Dog Lover," even though the user's session would be attributed to "Bird Lover."

Back to Top

How Visitor Segment Values are Applied

The following illustration shows a detailed break-down of how a custom visitor segment is applied to both user session and page view calculations across 3 sessions from a single visitor. Each session is described below.

Session 1

  1. The user begins the session with Page 1.
  2. Cookies are read and no __utmv value is applied to the session because none has been found and no _setVar() method is called on this page.
  3. On Page 2, the user selects "Bird Lover" from the menu and the __utmv cookie value is set to "Bird Lover." A GIF request also supplies the "Bird Lover" string via the _utmcc parameter.
  4. The user visits another page and then exits.
  5. The user session count for "Bird Lover" is incremented and 3 unique page views are attributed to the "Bird Lover" segment as well. The first page view is counted as part of the "Bird Lover" session as well, because no conflicting values were defined for that page.

Session 2

The user begins the session with Page 1. The __utmv cookie is read and the session data is attributed to "Bird Lover." Additionally, because the customized user segment value for that user was not altered on any pages for the session, all page 5 views in the session are attributed to the "Bird Lover" segment.

Session 3

On page 2 of the third session, the customized user segment for the user is changed to "Dog Lover." However, the session data for the user is still applied to "Bird Lover" because it is the first association for the session, as defined in the __utmv cookie. While the data for Page 1 is attributed to "Bird Lover," all subsequent pages for the session are attributed to "Dog Lover."


Back to Top