April 17th, 2010 → 10:26 am
by Robert Kingston
// 10 Comments

I’ve always wanted to improve the profitability of my AdSense sites, but only until recently, have I been using Google Website Optimiser to find the most profitable ad placements. I encountered many errors, hopefully many of which I can help you to avoid.
You need to create a GWO Multivariate experiment (makes GWO/GA integration a breeze and allows you to modify the ads, site-wide for consistency).
In order to segment the different variations in GA, you’ll need to add a couple of lines to your GA code:
if(typeof(utmx) == 'function'){ try {
pageTracker._setVar(utmx('combination'));
}catch(err){}}
Like so:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-YYYYYYY-X");
if(typeof(utmx) == 'function'){ try {
pageTracker._setVar(utmx('combination'));
}catch(err){}}
pageTracker._trackPageview();
} catch(err) {}
</script>
Note the order that trackPageview and setVar are called in. Also note that I’m using setVar and not setCustomVar – You can’t easily use custom variables with AdSense metrics at this stage.
This is the part I struggled with. In order to change the location of your AdSense code, you must only put part of the AdSense code within the section code. Placing this code anywhere else resulted in GWO stripping the AdSense variables out (like google_ad_slot and google_ad_width).
I.e. Section code highlighted by stars.
<script type="text/javascript"><!--
google_ad_client = "pub-111111111111111111";
/* Name */
google_ad_slot = "11111111";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script>utmx_section("Insert your section name here")</script>
<span class="alignright">
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span>
</noscript>
I haven’t gone this far yet, but I hope to try this out soon. My thinking is that you will have to define javascript variables in the site’s header and use those variables in specific AdSense code – the code that allows you to change the colours etc.
Once that’s done, you’ll be free to start testing and you’ll see cool results like this in GA:
Show it to your friends:
Tweet
Gavin Doolan
1 year ago
I’m pretty certain you can use custom variables now. You can segment Adsense reports via Advanced Segments. So you can create an advanced segment based on your custom variable and apply it to Adsense reports in GA to see the impact. This won’t impact your bounce rate either _setVar() was changed a while ago to be a non-interaction hit meaning it shouldn’t impact your bounce rate.
http://code.google.com/apis/analytics/docs/concepts/gaConceptsOverview.html#gifRequestClassification
Hope that helps.
Dave
1 year ago
I was under the impression that you shouldn’t mess with Google’s adsense code. Even splitting it up for use with GWO could be a reason to have your account banned. Of course, if you’re a premium publisher they give you access to their API which allows you to change all the variables.
Did you ever take this post one step further and test colors, sizes, etc. like you talk about in step 5?
Rob Kingston
1 year ago
Hi Dave,
I’m not sure about the details of the AdSense policies, but it sounds like they don’t want you to manipulate the look of the ad block to game the system. Changing things like position of the ad, colours of elements and size (as long as it’s in the parameters they give you) should be fine. Again, I’m no legal buff, so it may be worth checking out.
Re: Step 5. I haven’t done that yet – haven’t had time yet. My solution, I envision will involve some simple Ajax with Jquery (and yes – it’s really simple).
If you’re interested, I’ll code it up, run some tests and make a post about it.
Dave
1 year ago
Super interested!
It’s tough to even get in contact with the adsense team to ask them. I’ve seem an “official” A/B test that uses a simple if/then javascript routine to split test adsense, but never anything like what you’re talking about. O spent all day Thursday reading up on optimizing adsense CTR with GWO and GA but there aren’t many people even talking about it.
Rob Kingston
12 months ago
Hey Dave,
I’ve been testing it, but it looks like it’s not working so well. I believe in order to make Ajax work with AdSense we need to have access to Ajax for Adsense:
http://code.google.com/apis/afa/
I’ve signed up in the hope that I’ll be accepted into the program.
In the meantime, the only other way I can see this working is through loading different Iframes or split testing Google Ad Manager slots that are filled with different AdSense Ads:
https://www.google.com/intl/en_US/dfp/info/welcome.html
I’ll see if I can whack something together when I have a moment (hopefully sometime this week).
Rob Kingston
12 months ago
Regardless, I don’t think they’re ideal solutions…
Dave
12 months ago
The only thing I could think of is manually creating a ton of ad units and then configuring a GWO page but that is far too manual of a process, not to mention pretty code-heavy.
I can’t quite wrap me head around getting this to work across a whole site too (I’m using wordpress) without the user experience being messed-up. Adsense units flying around with every page load would be like walking through a haunted mansion with furniture flying about!
Like I said before, thanks for taking whacks at it. There isn’t much info on the web about this sort of thing. You’d think Google would put something together since it’s for the benefit of them as well.
Rob Kingston
12 months ago
Dave! I think I’ve done it.
It turns out serving AdSense through Google’s own Ad Manager tool lets you use Google Website Optimizer on it.
I’ve yet to fully integrate it, test it (want to make sure revenue is reported through Analytics still) and post the solution.
Would you mind if I emailed you a link to it? (should be in my WordPress database)
PS. You WOULD think Google would help us test this stuff more thoroughly. I mean how else do you provide a consistent user experience (i.e. ads not showing every which way during a visitor’s session and repeat sessions). That’s been a major flaw of testing with the current setup.
PSS. There is one more solution involving Iframes which I might also explain in my post (if it works).
Dave
12 months ago
Absolutely! I’m still scouring the web for info pertaining to modifying adsense code. I’ve found where I can ask adsense policy clarifications, but the solution you’re hinting at sounds legit.
Kelly
10 months ago
Hi Rob I’d love to hear what solution you came up with using doubleclick ads. Personally I find iframes a great solution since I can use php statements in my template to exclude it from showing on certain pages (contact,privay policy, etc) and it’s automatic insertion. By the way regarding the policy on modifying adsense code this may be of interest(and also getting full targeting with iframes)
“Please note that you are free to add HTML code or javascript in front or
below the AdSense ad code as long as you do you change the ad code itself.”
From http://geoland.org/2007/01/adsense-in-iframe/