How to Show Adsense Ads Only to Search Traffic! (and less annoying to your regular readers)
Over the years, I’ve realized showing ads to only search traffic is a pretty good idea, especially if you don’t want to bombard your regular readers with a whole bunch of ads.
You can also not show ads to image traffic as they don’t convert well most of the time.
But let me give you a simple javascript example that uses cookies to only show Adsense ads to your search engine visitors coming from either Google, Yahoo, Bing, Ask, or MSN. You can easily add more search engines if you want to by modifying the code.
Another thing I am doing is to show ads for about 60 seconds using cookies until they expire. (after visitors enter the site from a search engine) I think that is a good feature to implement. You don’t want to show ads just to the landing page to your search engine traffic, you want to keep showing it while they browse other parts of your site because search engine visitors are most likely to be interested/click on ads.
Now that we got the theory/concept out of the way, let me show you how to make your Adsense ads behave so they don’t annoy the hell out of their readers.
This can be great for either sites that are performing poorly (low CTRs, mostly image traffic) or quality sites you don’t want to bombard with ads. I don’t use this for my main site Zedomax.com but I use it for my other sites where my web traffic is high but my CTR is low. Using this code, I was able to bring the CTR up on those high-trafficked sites while improving regular user experience by showing ads only to search traffic visitors.
First Code
Put this code somewhere in your header file.
Second Code
Put this code where you are going to show the ad:
First Code Explained
Let me explain the code a bit. Basically the first part of the code will save a cookie to the user's computer if they come from image search or regular search. The cookie is set to expire in 60 seconds so that there's enough time for your Adsense ad exposure while search engine visitors are visiting your site and ads don't show after those 60 seconds to not annoy your new visitors so much. But you can change the value to shorter/longer if you want to.
This first code should be in your header file such as header.php so you can detect where your visitors are coming from, no matter which page they enter from.
Second Code Explained
The second code is the actual adsense code written in javascript, you will have to replace the google_ad_client and google_ad_slot value with yours. Change the pub-xxxxxxxxxx and yyyyyyyyy to the one you see when you generate your Adsense code. Don't touch the quote characters as that will mess it up, copy exactly and only change the variables I told you to change!
Does my code change the Adsense code and violate ToS?
No, my code doesn't change the Adsense code at all, it just translates it into javascript. The actual output code is exactly the same as code provided from Google. You can actually use PHP to do the same but the reason I use javascript is because my blogs use Wordpress Super Cache, which caches the PHP code. When PHP code is cached, it will cache the detection function also. In essence, PHP code used with Super Cache won't work because it will stay on the last PHP if statement.
In short, javascript works well along most platforms because it's processed in real-time by the browser. So that is why I used javascript here.
What you can get from this?
If you are reluctant to put more ads on your website, you can use this code to only show ads to search engine traffic. That way, you don't drive away your loyal readers.
For sites with low Adsense CTRs, it might be a good idea to show ads to only search traffic as your CTR will skyrocket if you do. Poor CTRs can be mostly from lack of content or image search traffic, both which don't convert well into overall revenue. Especially for those of you who get a lot of traffic, having low CTR can be bad, as it can lower your overall Adsense earnings due saturating overall CTRs.
Credits
I didn't create this code all myself, I built on top of the code created by Stephen Cronin over at Scratch99.com. Thanks for the code Stephen.
What I added is the additional cookie code plus expiration so your ads stay around for a minute before disappearing.









May 24th, 2010 at 8:00 pm
Interesting tip. Please i’d love to know how to make this code show ads for 5 minutes. I can’t seem to locate where you have 60 seconds in the code. all i see is expiry.setTime(expiry.getTime() + 60000);. Is that in milliseconds?
Hoping to get a quick response from you. Cheers
May 26th, 2010 at 2:33 am
Yes, miliseconds!