Stop diluting your Google Adsense and Analytics when browsing your own sNews site

Stop diluting your Google Adsense and Analytics when browsing your own sNews site

OK, we all know that clicking your own Adsense ads is bad news, so why risk it? You can prevent accidentally clicking them on your sNews installation easy enough... by simply not showing them when you're logged in, you don't need to see your own ads anyways, or run up your page impression count.

You can do this same little trick to hide yourself from Google Analytics, and save yourself having to set up filters for your own IPs.

In your index.php, where you want to display your Google code (or any code that you want only the browsing public to see, and not yourself), simply wrap it like this;

<?php 
if(!_ADMIN) { //not logged in so let's display the code
?>

<script type="text/javascript"><!--
google_ad_client = "pub-000000000000000000";
/* 468x60, created 12/15/08 */
google_ad_slot = "00000000000";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<?php 
} // all done
?>

If you want to use PHP and your IP address to always avoid showing you Adsense or keep you out of Analytics stats, you can use the following instead, be sure to replace the 111.111.111.111 with your own IP address;

<?php 
if($_SERVER['REMOTE_ADDR'] != '111.111.111.111') { //not you, so let's display the code
?>
your google code here...
<?php 
} // all done
?>

That basically says "show this to everyone except those logged in as an Admin". This way you won't dilute your Google Analytics or accidentally click your own Adsense ads.

Tags

 

You might like

Comments


Thanks Matt, implemented this today for 2 IPs. Before I couldn because my Provider was using dynamic IPS, but now I've changed and have a static one. Thanks for the little tweak.


Thanks for the code. Works nice.


(optional, not publicly displayed) (optional)

Copyleft 2002 - 2014 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top