szehau's weblog

Life, Internet, Software, Gadgets, Programming and Investments

Avoid additional Adsense impression from publisher

It is always a problem for Adsense publishers that always visit their own websites for testing purpose – Google Adsense will report additional Ad impression. The statistic at Google Adsense’s report becomes inaccurate and might affect the overall earning especially when publisher does a lot of testing on his/her own sites. When impression is increased, page CTR (click through rate) will be decreased and as well as eCPM (effective cost per 1000 impression).

Here is the trick to solve the problem:

  1. Create a page (e.g. adsenseCookie.php) that create a cookie where its expiration date is set to a specific date (e.g. 1 day, 1 month or 1 year from now)
  2. In your page’s source code, check whether the cookie is set. If it is, display an image that is same size with the Adsense’s Ad (e.g. 300×250 pixels). If the cookie is not set, display the Adsense code.
  3. When you want to do a testing on your site, simply execute the page adsenseCookie.php once. Then, your website will show you an static image instead of Adsense (Set the cookie’s expiration date to a longer one so that no need to execute adsenseCookie.php every time you want to do testing on your site).
  4. .

Here is an example code for PHP (adsense size 300×250):

Set cookie page


<?php setcookie('TestCookie', 'ForAdsense', time () + 365 * 24 * 3600 ); ?>

Display Adsense code or Image


<?php
if (isset($_COOKIE['TestCookie']) &&
  $_COOKIE['TestCookie'] == 'ForAdsense') {
?>
<img src="adsenseImage300x250.gif" width="300" height="250" />
<?php
} else {
?>
<script type="text/javascript"><!--
google_ad_client = "pub-XXXXXXXXXXXXXXXX";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_channel ="";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
}
?>

About Sze Hau

Geek. Love programming. Coffee addicted. Married with a child. Working towards financial freedom.

Email News Letter

Sign up to receive updates daily and to hear what's going on with us

More Posts

5 Essential Things You Need To Have At Your Home During The COVID-19 Pandemic

June 1, 2021 22:15 By Sze Hau

LED Downlight

Troubleshooting A Flickering LED Downlight

February 13, 2016 00:29 By Sze Hau

Repair A Broken iPhone Lightning Cable

January 30, 2016 00:54 By Sze Hau

Blog Network

  • Personal Fincance Personal Finance – Personal Money Tips, Stock Investment, Small Business and Make Money Online
  • Snippet IT Information technology news, ideas and experiences and opinions