{"id":83,"date":"2006-12-13T23:13:53","date_gmt":"2006-12-14T06:13:53","guid":{"rendered":"http:\/\/www.1keydata.com\/blog\/2006\/12\/adsense-testing-with-php.html"},"modified":"2012-12-11T23:42:07","modified_gmt":"2012-12-12T06:42:07","slug":"adsense-testing-with-php","status":"publish","type":"post","link":"https:\/\/www.1keydata.com\/blog\/adsense-testing-with-php.html","title":{"rendered":"Adsense testing with PHP"},"content":{"rendered":"<p>One advice people always give for webmasters in the Google Adsense program is to test ad placement, color scheme, etc. A common test is the A\/B test. There are several articles talking about how to set up such a test using either Javascript or PHP, and they invariably involve the use of a random number generator to determine whether a visitor would fall under the control group or the test group. Even Google&#8217;s official Adsense blog <a target=\"adsense_blog\" href=\"http:\/\/adsense.blogspot.com\/2006\/08\/abcs-of-ab-testing.html\">talks about it<\/a>.<\/p>\n<p><!--more-->If you want to make sure visitors to your site have a consistent user experience (for example, if you are testing whether it&#8217;s better to use a 728&#215;90 Leaderboard or a 468&#215;60 Banner, you want to ensure that users who see the Leaderboard ad initially will always see a Leaderboard ad as they navigate through the site), the random number method alone won&#8217;t work because it&#8217;s not possible to ensure all pages for that particular user fall under the same test bucket.<\/p>\n<p>How can this be accomplished? The one constant during a visitor&#8217;s visit to a site is his\/her IP address. So, we can use this information to determine which bucket a particular visitor falls under. To do this, include the following code at the top of every PHP file:<\/p>\n<p>&lt;?php<\/p>\n<p>$ip =$_SERVER[&#8216;REMOTE_ADDR&#8217;];<br \/>\n$last_ip = explode(&#8220;.&#8221;, $ip);<br \/>\n$even_odd = $last_ip[3] % 2;<\/p>\n<p>?&gt;<\/p>\n<p>The above code divides all visitor into two equal buckets ($even_odd = 0 and $even_odd = 1) based on the last number of visitor&#8217;s IP address. This determination will last through user&#8217;s visit to the site.<\/p>\n<p>At the place where Adsense code would be inserted, use the following code:<\/p>\n<p>&lt;?php<br \/>\nif ($even_odd &gt; 0) {<br \/>\n?&gt;<br \/>\n## First Adsense code<br \/>\n&lt;?php<br \/>\n} else {<br \/>\n?&gt;<br \/>\n## Second Adsense code<br \/>\n&lt;?php<br \/>\n}<br \/>\n?&gt;<\/p>\n<p>The above assumes that the testing occurs in a single place on the page. However, even if this is not the case, you can still use the same principle.<\/p>\n<p>Remember to use different channels to track the performance of the two blocks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explains how you can test Adsense ad performance using PHP.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[87,88,89],"_links":{"self":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/83"}],"collection":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":1,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.1keydata.com\/blog\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}