How To Hide Adsense From Social Traffic
Read on to find out How To Hide Adsense From Social Traffic from Stumbledupon, Digg, Technorati, Etc. The secret is to add a little JavaScript around your Ads, so that they will only be displayed if the visitor comes from a search engine. To see this in action, visit this site via search engine and an Adsense ad will replace the banner on top of this post
There is plenty of authority for hiding your ads from social traffic so you can increase your adsense CTR (from Grizzly’s Make Money Online Blog) and not have a lot of “views” that won’t ever get clicked. Here’s a direct quote from Vic Franqui; “One last thing – if you get a lot of social media traffic don’t run adsense. Only use adsense if you draw targeted search engine traffic”.
- How It’s Done.
So now you can run Adsense even if you get masses of Social traffic – If you run a WordPress blog you can use the ozh who sees ads plugin, but there is no easy plugin for Blogger or your normal website, so I have made up some JavaScript to use anywhere you want to show your ad to search traffic.
- Wrap the ad in an “iframe”
Some ads like Amazon have the code already wrapped in an iframe, so all you need do is wrap this (green) Script, around your ad code (red). The script detects if the referrer is Google, Yahoo, etc and displays the ad.
<script type="text/javascript">
<!––
var myArray = [];
myArray[0]= '/search?';
myArray[1]= '.yahoo.';
myArray[2]= 'search.';
myArray[3]= '/search/';
myArray[4]= 'images.google.';
for(var i=0;
i<5;
i++) {
if (document.referrer.indexOf(myArray[i]) > -1)
{
//––>
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=youraccount-20&o=1&p=26&l=ur1&category=computers_accesories&banner=1SKRXV416ZYVKCEGXQR2&f=ifr" width="468" height="60" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>');
}}
</script>
Substitute your ad code for the code in red above. This will work with any code that is completely wrapped in an iframe.
- Display Google Adsense
This can be a problem because Blogger, for instance, will overide some scripts you include. The answer is to source the Adsense code from an outside file. Pop your Adsense ad in a plain html file (adsense.htm); upload it to some place you can access; and call it as the source (src) of an iframe -
<script type="text/javascript">
<!––
var myArray = [];
myArray[0]= '/search?';
myArray[1]= '.yahoo.';
myArray[2]= 'search.';
myArray[3]= '/search/';
myArray[4]= 'images.google.';
for(var i=0;
i<5;
i++) {
if (document.referrer.indexOf(myArray[i]) > -1)
{
//––>
document.write('<iframe scrolling="no" style="width:125px;height:125px;" frameborder="0" src="http://YourSite.com/adsense.htm" marginheight="0" marginwidth="0"></iframe>');
}}
</script>
Edit the above URL (dark red text) to point to where you uploaded your adsense.htm file, and adjust the width, height to match your Adsense ad
- Just Copy and Paste
There you go – paste one of the above sets of script into your web page wherever you want the ad to appear. With Blogger, use an HTML/JavaScript Gadget, or else paste it directly into the HTML template in your header if you prefer.
- Try it and See for Yourself…..
Click on Site Synergy with Keyword Coherence for my Key Word Coherence site and you will see no ads, but Google (or Yahoo) for keywordcoherence and click on the SERP link to that same site and you will see that a banner ad in the header from Amazon and a Google ad in the side bar have appeared, because the referrer was a search engine.
- Tips to the Wise….
Be sure to edit the iframe dimensions to match your ad and check that your edit program paste function didn’t put left and right quotes into the script instead of plain quotes. Get that right and you will have learned how to hide Adsense from social traffic!
Update – PHP Alternative
- If you prefer to code this trick using PHP then do this:
Insert this code where you want the ad to appear
<?php include ('incl_adsense.php'); ?>
- where incl_adsense is this file:
<?php
function searchengine(){
$ref = $_SERVER['HTTP_REFERER'];
$SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
}
if (function_exists('searchengine')) {
if (searchengine()) {
echo "<script type=\"text/javascript\"><!--
google_ad_client = \"pub-yourcodexxxxxxx\";
/* Banner468x60 11/05 */
google_ad_slot = \"xxxxxxx0212\";
google_ad_width = 468;
google_ad_height = 60;
//--&rt;
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>";
} }
?>
- Save Bandwidth:
I find that all these ‘plugins’ tend to slow WordPress down too much at loading, so there is a good case for using this PHP alternative rather than a plugin to hide Adsense from social traffic
- Please notice that where the Google ad script is included in PHP you need to ‘Escape’ all the double quotes – like this: script=”ad text” must be edited to read script=\”ad text\” and change any ’slanted’ quotes like ‘ and “ to vertical quotes like these ” ‘
Update on the Update
This post is getting way too complicated. I have been asked to upgrade these codes to display an alternative ad to social traffic, so I have made a new post over on my Teaching Blog


