Bounce Rate And The _setVar('...') -- What Is The Relationship?

September 12, 2008
By John Henson

What is the relationship between Bounce Rate and the User Defined Segment in GA?

A. Beauty and the Beast?

B. Abbot and Costello?

C. Jekyll and Hyde?

D. Kermit and Miss Piggy?

First let’s take a look at what is wrong with this picture:

This is the simplest example I could think of.  A single visit to a site, generating a single pageview. But take a closer look at the bounce rate.

A bounce is a visit that only contains one pageview — they land on your website and leave without viewing a second page.  That is exactly what we have here. Yet the bounce rate is 0.00% (It should be 100%).

This is what can happen when the User Defined Segment (pageTracker._setVar(‘…..’);) is set on a landing page.

(The User Defined Segment allows you to track a specific characteristic about a visitor.  For example, you call pageTracker._setVar(‘/status=member’); after a visitor logs into your site. )

When the _setVar method is called:
1. It creates or modified a cookie on the visitor’s computer with the value inside the parenthesis.
2. Having just done this, it’s very excited and immediately wants to call home and tell GA about this new piece of data it has.

The problem is that a correctly tagged page will normally also have _trackPageview(); on it as well (the workhorse of GA).  When you also have a _setVar(‘..’); on the page, the JavaScript is now communicating with GA twice for only one pageview.

1. The overeager _setVar(); method that wants to tell GA about this great new piece of visitor data and

2. the _trackPageview(); method that tells GA what page is being viewed.

When this happens on a landing page, GA looks at all of this and sees two interactions and thinks “Well, this visitor talked to me more than once, so they are not a bounce. . .”

To avoid this, what we need to do is write the cookie with the _setVar(‘…’); information, but without calling home to GA afterward with the news.  This can be done by creating another tracker object and associating it with a non-existent account.

var fakeTracker = _gat._getTracker(“UA-1”);
var pageTracker = _gat._getTracker(“UA-xxxxxxx-y”);

In this example, after fakeTracker._setVar(‘…’); creates the cookie with the value of ‘/eyes=blue’, it calls home to GA and tells it that it has this new information about a visitor to the site associated with UA-1.  And GA says “huh?, UA-1?, I don’t know where this goes”.

Milliseconds later when the _trackPageview method executes (presumably associated with the correct UA number this time) it re-fetches the value from the cookie that setVar created and sends it to GA along with the pageview information.  As far as GA knows, this was the first time that any information associated with your account was sent in (and it included the User Defined Segment information since that is just part of what _trackPageview does anyway).

By using this method, you can easily create your User Defined Segment Variable on a landing page without causing the bounce rate issue we started out with.

Other Considerations

1. Any settings you do with the pageTracker object must also be done with the fakeTracker object

If you use: pageTracker._setDomainName(‘…’);
also use fakeTracker._setDomainName(‘…’);
If you use: pageTracker._setAllowLinker(true);
also use fakeTracker._setAllowLinker(true);

2. If you are using _setVar(‘…’); to track a click on a link that leaves your site, there is no _trackPageview(); that will be executed afterwards to send that information to Google.

In this case you want to make sure you just use pageTracker._setVar(‘…’); And Not fakeTracker._setVar(‘…’);

And the answer to the question at the top of this post?

I have no idea, Robbin just wanted me to capture your attention.