The ROI Revolution Blog

« What's New with Google Website Optimizer? | Main | Tracking a Section with Google Analytics »

Installing Website Optimizer if you use Google Analytics

September 17, 2008


hands-geo.jpg Ok, so back when I declared that Google Website Optimizer and Google Analytics represented 'A Perfect Marriage', I was overlooking some of the early bumps the newlyweds would experience before they lived happily ever after.

That being said, there are some things to look out for if you are using Google Analytics and are considering Google Website Optimizer as your testing platform of choice. Or maybe you have already noticed some strange things trying to use them together?

Here are the things to look out for:
1. Are you using urchin.js or ga.js?
2a. Are you setting _udn="something" (for urchin.js) or _setDomainName('something') (for ga.js)?
2b. Are you setting _uhash="off" (for urchin.js) or _setAllowHash(false) (for ga.js)?
3. If you are using urchin.js, are you tracking Ecommerce?

As long as you've got the above four things accounted for, everything should work fine. So I'm going to address each one in detail so that you know exactly what to do.

Before we get into the actual implementation, I'd like to go over the scripts that Google Website Optimizer and Google Analytics use, just so that we're on the same page.

gwo-codes.jpg For Google Website Optimizer
Google Website Optimizer uses up to four different scripts:

The Control Script (GWO-CS)
This is the longer Google Website Optimizer script that goes at the top of your test page. I've labeled it as script #1. I'll refer to this as GWO-CS.

The Section Scripts (GWO-SS)
These scripts are only used for multivariate experiments. They go around sections of your pages that you are testing. We won't be changing these at all. I've labeled this as #2 in the diagram.

The Test Page Tracking Script (GWO-TS)
This is the Google Website Optimizer script that goes at the bottom of your test page. I'll refer to this as GWO-TS, and it is #3 in the digram.

The Conversion Script - also known as the Conversion Page Tracking Script (GWO-CONV)
This is the Google Website Optimizer script that goes at the bottom of your conversion page. I'll refer to it as GWO-CONV, and it's all by itself as #4 in the diagram.

The Google Analytics Tracking Code (GATC)
This is your Google Analytics code, including any modifications you may have made to it. There is an urhin.js version and a ga.js version. You will need to look at this code to see if you need to make changes to the Google Website Optimizer scripts.

Now that I've identified the scripts we are dealing with, let's address each item on my list from the beginning of this article, and I'll show you how to deal with each scenario.

urchin-vs-ga.jpg 1. Are you using urchin.js or ga.js?

If you are using urchin.js:

You can go ahead and move on to Item #2 as there is nothing more you need to do here. The only thing I would recommend is that you include the GWO-TS and GWO-CONV after the GATC script on the test and conversion page, respectively. Also, if you are using Ecommerce, see item 3.

If you are using ga.js:

In this case you will have some changes to make. Thankfully, they are pretty easy. First things first, make sure the GWO-TS comes after the GATC.

Then, change the GWO-TS so that it uses ga.js. If you're original GWOTS looks like this:



Change it to:

Please note that these changes will only work if this code comes after the GATC with the ga.js call.

You'll also have to change the GWO-CONV on your conversion page. It's just like the GWO-TS, but you have to change the word 'test' to the word 'goal' in the _trackPageview function, like this:

Change it to:

That's it! Now just check items 2a and 2b to make sure you don't need to change the GWO-CS and you'll be good to go!

nerd-glasses.jpg
2a. Are you setting _udn="something" (for urchin.js) or _setDomainName('something') (for ga.js)?
2b. Are you setting _uhash="off" (for urchin.js) or _setAllowHash(false) (for ga.js)?

I've grouped these two together, because the solution for each is very similar. Regardless of whether you are using urchin.js or ga.js, you'll need to watch out for the above lines of code. If one or both of these apply to your GATC, then you'll need to add some code before the GWO-CS on your test page.

If you have either _udn="none" or _udn="domainname.com" in your GATC, or if you use pageTracker._setDomainName('something'), add the following bit of code before the GWO-CS:



You have to change "enter_value_here" to whatever your value for _udn or _setDomainName is. This will make sure the cookies for GWO and GA play nice with each other.

The same applies if you set _uhash="off" or _setAllowHash(false). If you do either of these, use the following code:



Finally, if you have both of these things, you need to do both, like this:



Notice that regardless of whether you are using urchin.js or ga.js, you'll use the urchin.js variables before the GWO-CS. This is true as of 9/18/2008, but will most likely change in the future.

If you are using ga.js, you may need to add a line or two to the newer GWO-TS and the GWO-CONV:



Basically, these values will need to match what's being used in your GATC, only for optimizerTracker. ecommerce-tree.jpg 3. If you are using urchin.js, are you tracking Ecommerce?

I'm not going to go into too much detail, but I'll try and cover the basics. To try and make it as simple as possible, in order for GWO to not interfere with Ecommerce tracking for urchin.js - everything needs to be in the following order:

1. Hidden GA Ecommerce form
2. GATC
3. __utmSetTrans() function.
4. GWO-CONV

If the GWO-CONV comes before the __utmSetTrans() function, then the transaction data gets sent to the wrong account number. If you've been having trouble with your Ecommerce data when trying to use GWO, having the wrong order is most likely the reason.

I hope you've found these tips helpful. Feel free to leave a comment if you've benefited from this advice or have any questions - I read all comments and try to respond promptly to each one. If you are still having trouble using Google Website Optimizer, feel free to contact us about our Support Plans, or consider attending one of our Online or In-Person training seminars. Our next live training is in Alexandria, Virginia on December 4th, 2008. Hope to see you there!

Interested in learning more about Google Analytics?
Attend our LIVE Google Analytics Seminars for Success training in Atlanta, GA Wednesday, April 14th, 2010 and Thursday, April 15th, 2010 or get the latest tips and tricks sent to you via our free, twice-monthly Google Analytics newsletter.

Comments

Bjorn van der Neut said:

Hello,
one thing what i dont get is:
"Or maybe you have already noticed some strange things trying to use them together?"

what strange things happen? Is it really nessassary for me to change all thoses values? Or only If you want 100% diving into your analytics?

Bye
Bjorn

September 19, 2008 2:41 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Bjorn:

I probably should have been more clear. By 'strange things', I really meant 'not working at all' or 'not reporting any conversions whatsoever', although I've seen many different kinds of problems arise from using incorrect code.

The whole reason you need to make these changes is that Google Website Optimizer actually uses Google Analytics cookies in order to work properly. If there is a conflict between the cookies Google Website Optimizer is using and the cookies that Google Analytics is using, you will often find that your experiments do not report correctly within Google Website Optimizer, if at all.

I absolutely recommend that you make code changes if you want the best data you can get. But don't take my word for it - you can find Google's official recommendation here concerning the use of ga.js. Also, there is a little help file from Google here that talks a little about _udn and _uhash, along with two other variables, but doesn't mention _setDomainName and _setAllowHash.

Hope that helps and thanks for reading!

September 19, 2008 8:13 AM

Michael Altman said:

I have also noticed that if you change the session timeout with GA, you also need to do that with the GWO tracking and conversion scripts.

Michael

September 19, 2008 9:55 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Michael:

That's absolutely true. Changing the timeout will affect setup the same way as setting the domain name or changing the hash parameter. There is also another variable called _utcp which can affect setup, but the timeout and _utcp are used much less frequently that the others. Thanks for pointing this out!

September 19, 2008 10:00 AM

EnjoyLifePlay.com - Secret Amazon Discounts said:

Excellent post Shawn. Really helps in clarifying how to implement the integration of these two very powerful tools. I hadn't even realised that the GWO script could use the ga.js javascript function. Thanks again!

September 30, 2008 8:27 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

Thanks for the compliment! This article ended up being more complicated than I originally intended, but there really are a lot of things to think about in order to make sure that the two codes work together correctly.

October 1, 2008 7:48 AM

SEO Services said:

Nice Post. Thanks for sharing this information with us.

October 10, 2008 4:52 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@SEO:

Thanks. I hope you found it useful.

October 10, 2008 8:04 AM

Chris Goward said:

Well written and helpful, as always, Shawn!

Look forward to seeing you guys again at Google HQ soon.

Chris

October 16, 2008 7:05 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Chris:

Thanks for the compliment. We'll definitely see you there!

October 17, 2008 7:40 AM

Sanjay Kanade said:

Isn't the _initData call needed before track call? Other samples that I saw include this call.

Another thing, this was working till I put in an adwords conversion script too in the goal page. This broke the website optimizer which is reporting no clicks. Any ideas?

Thanks,
Sanjay

November 11, 2008 12:45 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Sanjay:

._initData is now a depracated function that is no longer needed, although it won't hurt anything if it's there.

AdWords conversion tracker script should not interfere with Google Website Optimizer if everything is set up correctly. The two scripts do not share any variables or resources and should not affect each other in any way. It is possible that the position of your Google Analytics code will have an effect on your data, or that something else on the goal page is broken, causing the Google Website Optimizer code not to fire. Hope that helps!

November 17, 2008 8:03 AM

Ben said:

Thanks for the great info Shawn. Regarding number 3. Are you familiar with the information given here: https://www.google.com/support/websiteoptimizer/bin/answer.py?answer=93176&topic=14314

Does your solution mean we no longer need to use what is explained on this page?

November 24, 2008 3:01 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Ben:

I am familiar with that information. The information on that page is simply one method of making sure that the transaction data gets attributed to the correct account. It's one way of making sure that code is firing in the correct order, and it should work fine.

November 24, 2008 3:38 PM

Aiptek said:

Another thing, this was working till I put in an adwords conversion script too in the goal page. This broke the website optimizer which is reporting no clicks. Any ideas?

February 5, 2009 10:25 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Aiptek:

It's hard to say without seeing the actual code, but AdWords Conversion Tracker, when installed properly, will not interfere with any Google Website Optimzier code on the page.

February 5, 2009 10:46 AM

Mark said:

Hi Shawn,

That's a really great and well explained tutorial, I'm curios though, what changes need to be made now that google is using ga.js for website optimiser?

Do we still need the:


_udn = "enter_value_here";

at the top of the test page?

and if doing an A/B split test does it need to go on both pages?

are there any other changes to your original tutorial that need to be made now that google is using ga.js as standard for website optimizer?

Regards
Mark

February 25, 2009 11:51 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Mark: For now you still need to use the _udn variable at the top of the test page before the Control Script, although this may change in time. I'm not entirely clear on your question about A/B tests, but the _udn variable only goes on the original page before the Control Script. The two tracking scripts will also need to be modified, most likely using ._setDomainName now that Google Website Optimizer is using ga.js.

All other instructions in this article are up to date as of 2/27/09.

February 27, 2009 12:58 PM

Rodney said:

This seems WAY too complicated for me.

My site uses Goal Conversion but not the ecommerce stuff.

I no longer get Goal Conversion data in Google Analytics from Adwords traffic since using Website Optimzer (Goal Conversion data from all other traffic has been unaffected.)

Do I then need to use the system you mention above to change my code?

Or will the one on the link below do as well?

https://www.google.com/support/websiteoptimizer/bin/answer.py?answer=93176&topic=14314

March 11, 2009 3:42 AM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Rodney:

It's really tough to tell without seeing the code. If your goal conversion data is broken, this is most likely a separate issue. This usually happens when the Google Analytics code has been removed from pages, but to tell you the truth it could be a lot of things.

I would double check and make sure that both the GWO and GA codes are on the correct pages and that the GWO code comes after the GA code. I don't think the fixes in this article would affect goal conversion reporting at all, so there must be something that was removed or changed on the page.

March 17, 2009 10:55 AM

Jaco said:

Here is a fun one...

My question, did I do this right.

Page1.html is being tested,
the conversion page for that page is page2.html

Well... I needed to test page2.html as well, at the same time. (cannot use a redirect in between 1&2)

Page3.html is the conversion page for page2.html and is not being tested, only tracked with GA, as are the first2 pages.

Here is the GWO-TS script from page1.html

if(typeof(_gat)!='object')document.write(' (document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js">')

try {
var firstTracker = _gat._getTracker("UA-xxxxxx-1");
firstTracker._initData();
firstTracker._trackPageview();
var secondTracker = _gat._getTracker("UA-xxxxxx-5");
secondTracker._initData();
secondTracker._trackPageview("/1704330029/test");
}catch(err){}
}catch(err){}

Here is the combined GWO-TS an GWO-CONV script from page2.html


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 firstTracker = _gat._getTracker("UA-xxxxxx-1");
firstTracker._initData();
firstTracker._trackPageview();
var secondTracker = _gat._getTracker("UA-xxxxxx-5");
secondTracker._initData();
secondTracker._trackPageview("/1704330029/goal");
var thirdTracker = _gat._getTracker("UA-xxxxxx-5");
thirdTracker._initData();
thirdTracker._trackPageview("/2814405478/test");
}catch(err){}

I hope you can help verify.
Thanks in advance.


April 14, 2009 4:01 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Jaco:

By itself, the code is formatted properly, although I would question the validity of the second test, since there is a variable first page sending traffic into it.

That being said, the code looks ok - I would, however, think twice about testing two pages in the same funnel at once.

April 14, 2009 4:08 PM

Dan said:

Hi - great post. However, how do I know if I am using Urchin or GA in the first place? Thanks.

April 18, 2009 2:29 PM

Shawn Purtell, Google Analytics Support Tech Author Profile Page said:

@Dan:

There are a number of tools out there that can help you see what kinds of things are running on your website, including Google Analytics and Urchin. I would recommend either WASP or Ghostery, two Firefox add-ons that can help you with this. You can find out more about these and other tools for this here.

April 20, 2009 9:12 AM

Post Your Comments

Feedback Form