web blazonry web development scripts and tutorials Get best price on LG G3, Silk White 32GB (AT&T)
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       Resources   




PHP Name Generators
  Wu-Name
  U.S. Name
  Baby Name

Bookmark and Share




PHP: How to Test Google AdSense Ads (and Improve Your Revenue)

Improve your Google AdSense revenue by using this simple, free PHP code to quickly test different ads and identify the better paying ones.

Note: This is version 1 of testing AdSense. I created a new, updated article on testing Google ads because Google changed how they implement ads. Everything in this original article (below) still works. You can also go to the updated article (version 2).

Why Test AdSense Ads?

Change the settings your Google AdSense ads and you are likely to increase your revenue and click-thru rates. Google lets you vary many settings including colors of links, borders, text, backgrounds, as well as ad sizes and shapes. Furthermore, you have lots of choices about where to place the ads on your pages.

You could run one type of ad for a few weeks, then modify it, run the changes for a few more weeks, and then compare results. That takes too long for me. I wrote this script for myself. It lets you test different formats simultaneously and start getting side-by-side results the same day.

This article is written specifically for Google AdSense. You likely can modify it for other ad programs. To use it with other ad networks, focus on the the general approach explained here because it will likely apply to other advertisers.

Notable Differences Between Version 1 (This Article) and Version 2

The Nature of the Testing Code: Version 1 (this article) uses an older format of implementing Google ads. Version 2 uses the new format of implementing Google AdSense ads. Both formats work, but Google no longer provides the option to generate the old version of the ad code that is used and explained on this page 1. AdSense help has an overview of the new system.

What is Tested: Version 1 tests an ad with a border versus an ad with no border. Version 2 tests different positions for your ad and content.

How to Test Ads

Select Two Different Ads

For our example, we will test an ad block with a border vs. an ad block without a border. This page has a white background, so when I say “no border” I set the color of the border to white (RGB value of FFFFFF). To make your border disappear, set your border color to match your page’s background color.

Take a quick look at the two ads formats we are evaluating in our code before we get too deep into the explanation. Only the border color is different. Everything else remains the same so we do not confuse and confound the test. (The channel ID assigned by AdSense changes, but that is not part of the appearance of the ad. It is for your tracking purposes discussed below.)

Here, we are testing border vs. no border. You could just as easily vary the color of the links, or color of the URLs, or size of the ad.

Building the Ad Testing Code

Log into your AdSense account and create 2 custom channels for your site. One channel for each format you are going to test. (Adsense help explains how to set up custom channels.)

In your web page, generate a random number of 0 or 1. We use this number to serve up one of two AdSense ads. When the number 1 is generated, display an ad with no border, else display the ad with a blue border.

<?php
   srand(time());
   $random = (rand()%2);
?>

In your AdSense account, generate the AdSense code for the first channel. Our first channel has no (a white) border. Paste it in to your web page code. Then, back in AdSense, generate the code for your second channel, selecting the appropriate custom channel and setting the border color. You will build something like the following:

To make it easier to see below, the border color we are varying is in bold text.

<?php
   if($random == 1)
   //test with white border (no border)
   {
?>
   <script type="text/javascript"><!--
   google_ad_client = "pub-2911253224693209";
   google_ad_width = 336;
   google_ad_height = 280;
   google_ad_format = "336x280_as";
   google_ad_type = "text";
   google_ad_channel ="2621593367";
   google_color_border = "FFFFFF";
   google_color_bg = "FFFFFF";
   google_color_link = "0000CC";
   google_color_url = "FFCC00";
   google_color_text = "000000";
   //--></script>
   <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
   </script>
<?php
   }
   else
   //test blue border around ads
   {
?>
   <script type="text/javascript"><!--
   google_ad_client = "pub-2911253224693209";
   google_ad_width = 336;
   google_ad_height = 280;
   google_ad_format = "336x280_as";
   google_ad_type = "text";
   google_ad_channel ="5760339755";
   google_color_border = "336699";
   google_color_bg = "FFFFFF";
   google_color_link = "0000CC";
   google_color_url = "FFCC00";
   google_color_text = "000000";
   //--></script>
   <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
   </script>
<?php
   }
?>

Let the ads run. In your reports you will see roughly equal numbers of each ad being served up. When you determine which format is better, try changing another setting to see what will give you even better click-thrus and revenue.

Download the code source  (adtest.txt)

View page with both ads showing so you can see the differences.


How To Run More Sophisticated Tests of AdSense Formats

Just like we tested two different border colors, we could have varied another setting. For example, if you want to see whether black link titles perform better than blue, set one color:
   google_color_link = "003366";
and a second color:
   google_color_link = "000000";

You can run a more complex test, with, say, three options for a single variable. Modify the random number generating portion of the code to generate a 0, 1 or 2. You should test only one variable at a time (holding all other variables constant). If you test too many variables, you do not know what is performing better.

When you get more comfortable with custom channels and with testing various ad formats, you can get more sophisticated with your tests and how you use my little PHP script.

The type of test we just did is called an “A/B test.”  If you are beefing up your dev skills or your resume, A/B testing is worth learning. In fact, I will write it up in a future tutorial.

AdSense Terms and Conditions require “not modifying the JavaScript or other programming provided to You by Google in any way.” The above ad test does not modify Google’s code. We are simply randomly serving up one of two scripts. When you look at the HTML source for each format that PHP generates, the scripts are exactly what AdSense generates. We have not modified Google JavaScript or programming in any way.



Ad Testing Code Version 2

Version 2 provides code, examples and an explanation for how to test the performance of your ads with different positions for your ad and content.


 

Newest Pages
Test Google Ads Ver. 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources
 
 

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.