Archive for October, 2009

Segmenting Traffic using User Defined Variables

Friday, October 2nd, 2009

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

These labels are often called Custom Segments. Data can be seen in User Defined report under the visitor’s report section.

How to set User Defined Variables?

Let’s say that we want to add a label of “customers” to any visitor who reaches the shopping cart’s receipt page. In order to do this, we would add an additional line of code to the Google Analytics Code on the receipt page.

<script> 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>

One more use of User Defined Variables is to exclude our own traffic.

For example, let’s say that we want to exclude entire company’s traffic from appearing in reports, and company uses dynamic IP addresses.

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

Next, you we 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, we can then apply a filter with the following specifications to profile, and our internal traffic will be excluded:

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