Split Testing Google Adsense The PHP Way

Or “The Poor Man’s Split Testing Method”.

There’s no right or wrong way to do this. Darren Rowse made a post about split testing Google Adsense and showed how to do so using channels and a little javascript.

Like a lot of things, there are other ways of accomplishing the same thing.

Enter PHP, that fancy web scripting language that gives you the ability to do some pretty neat tricks.

The code snippet below allows you to split test your Adsense by day. Instead of having to setup separate channels to split test, just login to your Google Adsense account, create two versions of the Google Adsense code you want to test, paste those two versions into the PHP code shown below, put that PHP code in an include file on your site, and call that include file in your web page. Then, if you want to see how you are doing, go back to your Google Adsense account and look at your results by day.

O.K. maybe that was a lot of stuff to do.

If you have a PHP enabled web site and you are not using PHP includes, tsk, tsk.

All of the even numbered days (even numbered according to PHP) will display one version of your Adsense code while all of the odd numbered days will show another version of your Adsense code.


<?php

if (date("z")%1) {

?>

<!-- Google Adsense #1 goes here -->

<?php

} else {

?>

<!-- Google Adsense #2 goes here -->

<?php

}

?>


The most important part is the “if” statement, the code that checks whether today is an even or an odd numbered day.

In this PHP example the “z” represents the day of the year.

The date(“z”)%2 < 1 checks if today's number modulus 2 is less than one (which asks if today is an even numbered day), then do whatever is between the set of squirly braces - the "{" and "}" - else do whatever is between the next set of squirly braces.

The whatever I am referring to is display your Adsense code.

By the way, there is nothing to prevent your from putting anything between the squirly braces.

There are some limitations to be aware of for sure. Namely, you still need to generate two versions of the Adsense javascript code to include on your web site. Also, if you want to get a better understanding of your results, you will need to download the results and group the data by even or odd day. I don’t even know if Google allows for an easy way to get your Adsense results – I’m not even going to login to find out.

But, for a quick and dirty way of split testing your Adsense results, this PHP code will do the trick.

Extra: You don’t have to just use the day of the year (“w”), you could just as easily use day of the week (“w”), hour of the day (“G”), day of the month (“j”) – or some combination. Whatever your mind can conceive and believe it can … oops, that’s for a different topic 🙂

Comments on this entry are closed.

Previous post:

Next post:

backlinkhub.co | 522: Connection timed out

Error 522 Ray ID: 4dc5d312ba74c524 • 2019-05-25 07:34:32 UTC

Connection timed out

You

Browser

Working
Chicago

Cloudflare

Working
backlinkhub.co

Host

Error

What happened?

The initial connection between Cloudflare's network and the origin web server timed out. As a result, the web page can not be displayed.

What can I do?

If you're a visitor of this website:

Please try again in a few minutes.

If you're the owner of this website:

Contact your hosting provider letting them know your web server is not completing requests. An Error 522 means that the request was able to connect to your web server, but that the request didn't finish. The most likely cause is that something on your server is hogging resources. Additional troubleshooting information here.