Upcoming LunaMetrics Seminars
Boston, Oct 6-10 Chicago, Oct 20-24 Seattle, Nov 3-7 New York City, Nov 17-21

Bounce rate and the _setVar(‘…’); — what is the relationship?

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″);
fakeTracker._setVar(‘/eyes=blue’);
var pageTracker = _gat._getTracker(“UA-xxxxxxx-y”);
pageTracker._trackPageview();

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.

Sorry.

http://www.lunametrics.com/blog/2008/09/12/wrong-picture-2/

6 Responses to “Bounce rate and the _setVar(‘…’); — what is the relationship?”

Marco Cilia says:

and what about avoid trackpageview() only for pages containing setvar?

Robbin and her ideas! :-)

I think the best description of the relationship between “Bounce rate and the _setVar(’…’);” is Pinky and the Brain. They both want to conquer the world, but since they mess up one with the other, things just don’t work… :-(

John says:

Marco,

I’m not sure what you mean. The call to _trackPageview() should appear on every page that you want to track in GA.

Although there might be cases where you want to use _setVar on a landing page and do not want to track it with _trackPageview(), I’m not coming up with any thing reasonable.

Xjiard says:

I tried the solution you mentioned. Unfortunately, though the bounce rate was corrected, the _setVars I used no longer tracked. Here’s the generated code (with domain and ID obscured):

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”));

var fakeTracker = _gat._getTracker(“UA-1″);
fakeTracker._setDomainName(“.domain.com”);
fakeTracker._setVar(“Payment Method: “);

var pageTracker = _gat._getTracker(“UA-#######-#”);
pageTracker._setDomainName(“.domain.com”);
pageTracker._trackPageview();

Perhaps I didn’t understand your explanation above? I’m thinking that before the setVar is set to the fakeTracker instead of the pageTracker, when the _trackPageview method is called on the pageTracker, it doesn’t read the variables set for the fakeTracker. Any way around this?

John Henson says:

xjiard,

What you have looks right to me.

Both _setDomainNames are set to exactly the same string – good.

the fakeTracker._setVar comes before the pageTracker._trackPageview – good.

Doublecheck your code in the page and make sure you have straight quotes and not directional quotes. Load the page in question, and make sure you do not have any JavaScript errors.

Go into your Google Analytics to the Top Content report and look for the URL of that page, and make sure it shows up for a time period after you made the change.

I’m thinking that before the setVar is set to the fakeTracker instead of the pageTracker, when the _trackPageview method is called on the pageTracker.Google Analytics to the Top Content report and look for the URL of that page, and make sure it shows up for a time period after you made the change.