Show Adsense To Search Visitors Only – On Blogger

Want to make money online with Google Adsense? If so, you better make sure you don’t get smart priced! One of my most successful posts covers how to avoid smart pricing by only serving Adsense to search engine visitors. That post was written for the WordPress platform. In this post, I outline how to do the same on Blogger blogs (although there are severe limitations).

Why Only Show Adsense To Search Visitors?

First, why are we doing this? The main reason for showing Adsense to search visitors only, is to try to avoid smart pricing. I won’t go over smart pricing again (go read the above post in detail), but here’s the brief summary:

Smart Pricing is a penalty Google applies to Adsense accounts that don’t convert well for the advertiser and results in you earning only about 10% of what you’d normally earn per click. Search engine visitors provide targeted traffic for the advertiser, which converts well (no problem). Regular readers and social networks visitors provide untargeted traffic, which doesn’t covert well, increasing your chances of being smart priced (problem).

After reading Grizzly’s recent post on making money online anonymously, I learnt that it’s even more complicated than that. Grizzly, who’s a master of making money online, reveals that when he writes a post his CPC (Cost Per Click) drops for a couple of days:

Whenever I post I get a surge of traffic – the surge is un-targeted (my readers) and my CPC drops for several days until readers tail off. As long as my ad impressions stay above the 3000 barrier my CPC doesn’t drop more than 10 cents a click. If my ad impressions fall below the 3000 barrier I see a 30 cent drop in earnings per click.

Grizzly also says that his CPC dropped when he received a surge of traffic from a forum. It follows that the same would happen when you receive a surge of traffic from the social networks (ie Digg, StumbleUpon, etc).

It may be that this phenomenon is separate to smart pricing, or it may be that it’s actually a part of smart pricing and that smart pricing is far more complex than anyone has guessed.

Either way, showing Adsense to search engine visitors only should ensure that Adsense units are only served to targeted traffic, which should protect your CPC and help you make more money.

Serving Adsense Only To Search Visitors on Blogger

I’ve already covered how to display Adsense units only to search visitors for WordPress and I actively use the method on this blog. However, I also have a few Blogger blogs (and Grizzley’s site is on Blogger), so I started wondering how to show Adsense only to search traffic on Blogger.

With WordPress it’s easy. You can use PHP on the server side to detect where the visitor came from, then decide whether to include the Adsense code. If they came from a search engine, the Adsense code is added to the HTML sent to the browser. If they came from somewhere else, then it’s not.

However, with Blogger, it’s not possible to detect where the user came from on the server side. The only option is to use JavaScript, on the client side, to a) detect where the user came from and b) show the Adsense code or not.

Part A – Detecting Search Engine Visitors

Detecting search engine visitors is relatively easy. We can use JavaScript’s document.referrer to work out where the user came from. Converting the code I used for the PHP in JavaScript, we can do something like:

<script type='text/javascript'>
//<![CDATA[
var ref = document.referrer;
var se = new Array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');
var sevisitor = false;
for (var i = 0; i <= se.length-1; i++) {
	if (ref.indexOf(se[i])!== -1) {
		var expiry = new Date (); 
		expiry.setTime(expiry.getTime() + 3600000); 
		document.cookie = "sevisitor=1; expires=" + expiry + "; path=/; domain=scratch99.com";
		sevisitor = true;
	}
}
//]]>
</script>

Note: In the document.cookie line, you must change “.scratch99.com” to your own domain!

This code detects whether the user arrived from one of a number of search engines and, if so, sets a variable called ‘sevisitor’ to true. It also creates a cookie, so these visitors can be identified if they subsequently navigate to another page (they will no longer appear to have come from a search engine).

We’ll use the variable or cookie later to decide whether we’re going to display Adsense.

So where does this code go? We only need this code once on the page, regardless of how many Adsense units we show, so we’ll put it at the top. The bad news is that it doesn’t work if you try to add it via a Blogger gadget, so we’ll have to add it to the template itself, as follows:

  • In Blogger, go to Layout, then choose Edit HTML
  • Make a backup of your template by clicking Download Full Template
  • Click Expand Widget Templates
  • Search for <title><data:blog.pageTitle/></title> (near the top somewhere)
  • Place the code above on the line immediately below this.
  • Save the template

Your blog should now be setting the variable and the cookie.

Part B – Showing Adsense To Search Visitors

Next we need to detect whether the variable and cookie are set and, if so, show the Adsense unit. To check whether they’re set, we’re going to use the following code:

var results = document.cookie.match ( '(^|;) ?sevisitor=([^;]*)(;|$)' );
if (sevisitor == true || results[2] == 1) {

Put this together with your Adsense code and it should look something like this:

<script type='text/javascript'>
//<![CDATA[
var results = document.cookie.match ( '(^|;) ?sevisitor=([^;]*)(;|$)' );
if (sevisitor == true || results[2] == 1) {
	var adsenseString = "<div style=\"float: left;\">\n";
	adsenseString += "<script type=\"text/javascript\"><!--\n";
	adsenseString += "google_ad_client = \"pub-xxxxxxxxxxxxxxxx\";\n";
	adsenseString += "google_ad_host = \"pub-xxxxxxxxxxxxxxxx\";\n";
	adsenseString += "google_ad_slot = \"xxxxxxxxxx\";\n";
	adsenseString += "google_ad_width = 336;\n";
	adsenseString += "google_ad_height = 280;\n";
	adsenseString += "//-->\n";
	adsenseString += "<\/script>\n";
	adsenseString += "<script type=\"text/javascript\"\n";
	adsenseString += "src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n";
	adsenseString += "<\/script>\n";
	adsenseString += "<\/div>\n";
	document.write(adsenseString);
}
//]]>
</script>

You’ll have to replace the xxxx’s with the appropriate numbers from your Adsense code and you’ll have to change any other details (such as ad width and height if you’re not using a large rectangle).

There’s no need to replace special characters with HTML entities, as mentioned in my post on showing Adsense within the post body. In fact, that won’t work in this case.

What this script does is first check whether the variable or the cookie is set and if so, builds a string containing the Adsense code, then writes it. We have to build a string then write it, because there’s an external script called by the Adsense code. If there wasn’t an external script called, we could just strip the <script> tags and put the code in directly.

Where does this code go? The answer is wherever you want it, but it has to be in the template, as follows:

  • In Blogger, go to Layout, then choose Edit HTML
  • Make a backup of your template by clicking Download Full Template
  • Click Expand Widget Templates
  • Find where you want to put the ad unit and place your code near this.
  • Save the template

Here are some suggestions for where you might like to put the Adsense unit:

  • At the top of the post body: Place it on the line after <data:post.body/> (or <p><data:post.body/></p>).
  • Before the post title: Place it on the line before <b:includable id=’post’ var=’post’>
  • At the top of the sidebar: Place it on the line after <b:section class=’sidebar’ id=’sidebar’ preferred=’yes’>

Remember, according to Google’s Terms Of Service, you can only have 3 Adsense units on a page (plus 3 link units), so make sure you don’t put this in too many places. You don’t want to be banned from Adsense.

Why In The Template?

You might think you could save yourself the trouble of editing the template by using HTML/JavaScript gadgets that can be added via Layout > Page Elements.

Save yourself the time and don’t bother. These gadgets are extremely fussy. CDATA doesn’t work, the code you paste in mysteriously changes, using htmlentities doesn’t help.

And before anyone asks, there is no way this can work with the built in Adsense gadgets. The only way seems to be through the template.

Is It Worth It?

This obviously takes a while to set up and only you can decide whether it’s worth it to you. It really depends on whether you’re likely to get smart priced. I’m not going to bother, as 99 percent of traffic on my Blogger blogs are search engine visitors to start with, so I’m unlikely to get smart priced.

If one of my Blogger blogs morphs into something similar to this blog, with regular readers and social traffic, then I’ll definitely shift all of the Adsense units into the template and show them only to search engine visitors.

I’d highly recommend you do some testing  (remembering it takes about a week for smart pricing to be removed) and base your decision on that. Remember, this is all about making money online.

The IFrame Solution

After writing much of this post, I came across an alternative solution from Rhys, which places Adsense within an IFrame. This gets around the problems mentioned above and should allow you to use the HTML/JavaScript widget.

However, although this is much easier, I’m slightly hesitant to recommend it. It seems to me that when the Adsense bot goes looking at the page that the Adsense unit is displayed on, it will crawl the IFrame, rather than the real page, meaning the ads may not be relevant. However, it seems to work for Rhys, so I’ll leave you to make up your own mind.

Final Thoughts

Google Adsense is one of the best ways to make money online, but you have to make sure that you’re not smart priced. Don’t just believe what I’m saying – go and test it out. It’s definitely worth looking into, because it can help you make extra money.

59 responses on “Show Adsense To Search Visitors Only – On Blogger

  1. Rhys@hide adsense

    Hi Stephen!

    Thanks for the ping.

    Interesting to see your experiments on this. I too discovered the problems of trying to inject code into Blogger /gadgets, and found the only viable solution to be the iFrame.

    Adsense bases its response on the page which invokes it, I.E., the originating page and the ads it serves are relevant to that page. I have never seen irrelevant ads using this code.

    My method uses a very simple and short code-set, and is good for un-geek types.

    Regards – Rhys

    ;-)

    1. Stephen Cronin Post author

      Hi Rhys,

      Thanks for stopping by and commenting.

      I’d have to say your method is much simpler (especially for those un-geek types) and from looking at your site, the ads are relevant. So it seems to work.

      It’s just I would have thought that the Adsense bot would wait until it’s called by a page (ie by the ad unit), then use the referrer information to crawl the page to see what it’s about. The referrer information would contain the URL for the IFrame, not the URL for the page that has the IFrame embedded. I guess the Adsense bot just crawls your site page by page rather than use the referrer.

      Anyway, your method’s much simpler, so I’m happy to recommend it to people, as long as they keep an eye on the relevency (which they should be doing anyway).

      Best of luck Rhys.

  2. Rhys@hide adsense

    Hi Again Stephen!

    I guess the iFrame is perceived by the Adsense server to be like a div or any other [ad] container and therefore would not be part of the actual referrer info utilized by Adsense when determining relevance.

    As you pointed out, the real criteria are relevance and functionality!

    Regards – Rhys

  3. David@SEM Labs

    This is pretty smart. I only use AdSense on one site a CSE, which doesn’t do very well :( so I guess I must be pretty low on the payout hierarchy. I’d also have your script so it shows the ads when there is no referrer myself, but you probably know more about these things.

  4. Jenn@Atlanta real estate

    That’s pretty nice Stephen, this looks pretty simple for rookies like me. I am not currently using adsense but will be soon. I will keep this in mind. Thanks again Stephen! I am turning into an expert just by following your blog!

  5. Mickey Kick

    Adsense become very complicated today. It’s not like before, now we face low bids and even low ctr cause users get used to text ads similar like they forgot to click on banners years ago.

  6. Tony Lee

    Hello All,

    I’d like to share an experiment that I did with adsense. This involves “G” and it’s ability to control PR and the display of pages it indexes based on the users page quality.

    The goal here was to determine how much value google gave my pages that contained my adsense ads based on webmaster tools stats and monitoring page stats with:

    site:mydomain.com
    and
    site:mydomain.com/* <- Displays pages NOT sandboxed

    Here is a short list of what I found:

    -Use only ONE ad per page. (Once I added two or more ads, I noticed a decline in $ per click and an overall decrease in adsense income.)

    -Ensure your content is unique content, and a minimum of 250 words that cover ONLY that subject matter that the page or post is about. I purposely created 3 different types to test this out, using the same subject on each page. Unique, scraped (with some revisions) and a poorly written page. Obviously, the unique page outperformed the others, but the real kicker was that the bad pages dropped from search results, and reappeared when I removed the ads!

    -Blend (color) your ad into your page and bury them deep within the text. Again, my pages with this configuration stayed in search results.

    The bottom line is, google seems to de-value a page that it feels unworthy of its ad, so be careful when laying out your page.

    In my next post, I’ll explain the difference between:

    site:mydomain.com

    and

    site:mydomain.com/*

    I’ll explain why the results are so drastically different between the two, when you view your site using this syntax.

    Anyone else have any “experiment” stories they would like to share? I’d love to hear them!

  7. Roger@Music Industry Jobs

    nice post, i wasn’t aware that this even existed. I’m fairly new and trying to learn all i can but i guess i have a long way to go, thanks for the tip.

  8. Tony Lee

    The effect and explanation on my adsense sandboxed pages.

    The site:mydomain.com verses the site:mydomain.com/* syntax.

    If you recall a few years back “G” had a “tag” that they would
    display when a site owner typed in the syntax: site:mydomain.com.
    The word “supplemental” would appear on page listings
    that “G” felt were not worthy of their main index library.
    (Today we call that “sandboxed”)

    Then suddenly, without notice they (G) dropped the tag.
    At that point, Webmasters had no way of knowing what
    were their “actual” indexed pages or sandboxed pages.

    Then, in comes (hackers) a guy, to create a syntax to
    release not only indexed pages, but supplemental as well.
    Many variations were invented, but lasted only a few days
    or weeks. As soon as one was created, they (G) blocked it.

    site:mydomain.com/kfghyz*, site:mydomain.com/?&w#6* and many
    other variations were created to display ONLY indexed
    pages. Currently and as far as I know, the tag /* at the end
    still works today.

    Although these pages that display using the site:mydomain.com
    syntax DOES show all indexed pages, the site:mydomain.com/* shows
    the TRULY indexed pages that “G” feels worthy enough
    to be, as I call it, the “1st tier”.

    Unfortunately, even if these pages contain the ideal amount
    of unique content, the “2nd tier” pages or sandbox/supplemental
    pages exist, in IMHO, because:

    1.they lack content that **changes***
    2.these pages are not **deep linked** from a quality,
    authoritative, relevant, decent PR site,
    3.they lack **anchor/alt tags**, to include images as well
    4.they are beat out by **similar content/niche** pages
    from other sites that “G” feels are more worthy
    that meet the criteria in items 1-3.

    De-index and Sanboxed Pages-they are different.
    De-indexed and sandboxed are two COMPLETELY different conditions.
    De-indexed means that you (probably by a manual G review) are history,
    toast, gone, kaput. If G de-indexes you, you will know!
    No home page,no site pages, nothing, nada!

    You also have to remember that you are in competition with other sites.
    As their pages rise and fall in rank and quality, yours will also. In theory,
    you doing just a bit of SEO with your site pages in one instance, could
    cause you to rise to the top when others do absolutely nothing.
    By virtue of your small effort and G sandboxing your competitors page,
    you could jump to the top.

    Sandboxed pages on the other hand, can be recovered, your still in good with G.
    (Your pages just don’t have a seat on the 50 yard line of the internet game,
    your somewhere up in the nosebleed section, but don’t sweat it)

    As an example, here are big Gs results:

    site:g**gle.com/* = Results 1 – 10 of about 19,000,000 from g**gle.com/*.
    site:g**gle.com = Results 1 – 10 of about 37,900,000 from g**gle.com
    They even sandbox their own pages!

    Don’t just take my word for it, try testing your keywords with this
    method with both /* and without.

    I’m sure you’ll find your tier one pages ranking better than the tier two pages.

    In any case, you can use this as a guide when implementing adsense ads
    to watch the rise and fall of your pages in the hidden world of the the G**gle Sandbox.

    I hope you find this useful!

  9. Simon@Make Money Online

    Very useful post. smart pricing an adsense can be a serious problem…particulary if a lot of your traffic comes from social sources. Cheers for the info…may put this to use.

  10. Mark@arcade games

    thank you for the information. I have been smart priced with websites already which heavily dropped my earnings. I often now just use 1 or 2 adsense blocks on a page by the way. I remarked that Adsense will then display higher paid ads.

  11. Tony Lee

    Just a quick note….
    I’d like to know if anyone has any other ad (adsense) placement tips they would like to share. My testing efforts were on a two month trial. Perhaps someone has some other experiences, under different circumstances.

    Tony

  12. Jerry@Online Data Backup

    This is some complex stuff… at least I dont have to worry about it much now since I dont have very much traffic and adsense is useless.

    1. Tony Lee

      Sure Steve, no problem.

      This was just one example of what folks can do to optimize their ads, and more importantly, pages in the SERPS that contain adsense ads.

      Stephen has some great stuff here about WP and enhancing your site. If it’s one thing that changes often, it’s surely wordpress!

  13. Ernesto@Motorola Bluetooth audio headset

    I have always wanted to maximize the earning potentials that the blogger platform offers, despite its limited features (as compared to wp). However, I can say that I learned so much from blogging because of blogger.com – I owe a lot to this free blogging platform. And so with your new adsense tips on how to prevent smart pricing, this will surely help more in increasing my adsense earnings from my blogger blogs.

  14. Erik G@Hunting and Fishing

    I had no clue google adsense was that advanced, it really might be why I’m earning such a low CTR. I’m going to try what you said and see if it works. I really appreciate this post!

  15. Shawn @ Adsense Alternative

    I’ve been doing this on WordPress, but once again wasn’t aware that it was possible to do it on Blogger. Thanks. Really useful.

  16. Paul J

    This is a great post.

    In my experience, the visitors I get referred through Google Images do not click ads and really reduce my CTR. If I want to disable ads to those visitors, can I just delete images.google from the above code??

    1. Stephen Cronin Post author

      Hi Paul,

      Yes, you may want to be careful about this. I was under the same impression, but then I came across a post on parsing Adsense which indicated that Google does give permission:

      We do permit minor edits to the AdSense code to place inside the blog posts. Please keep in mind publisher may not alter any portion of the code or manually change the layout of the ads. For instance, publishers may not alter the ad height variable to mask the Ads by Google moniker.

      This change is not the same as the one that Google gave permission for, but it fits into a similar category (or at least the spirit of it).

      However, I have not checked with Google, nor do I take any responsibility for anyone using this technique. I actually don’t need to use it, as my Blogger blogs only get search engine traffic. I really only worked out how to do this as a challenge.

  17. Brandon@Google Money System

    Great stuff , I absolutely hate trying to avoid smart pricing, this will be an absolutely awesome addition to my blog :)

  18. George Packard

    Great thread! It’s only when people share their ideas that I learn more about tweaking my sites.

    Can find this stuff anywhere else….thank you all for sharing!

  19. jermaine@Only Love Poems

    That’s only smart by Google if you think about it. This great so anyone who try to cheat the system won’t get that much back. I’d rather get search results anyways rather than outer search engine traffic for my earnings with adsense.

  20. Nestor

    Thank you Stephen, this worked perfectly on my site. I have a question that will probably help many others. I want to be able to display an image instead of the ads for non-search visitors. In my case, I have a skycraper banner and without the banner the site design is unbalanced. So it would be great to be able to show a design element in that space. It seems like this would be an easy process with the addition of some sort of ELSE command, but I can’t get it to work.

    This is what I have. following this:

    document.write(adsenseString);
    }

    I added:

    ELSE {
    var adsenseString = “\n”;
    var adsenseString = “\n”;
    adsenseString += “\n”;
    }

    but it doesn’t work. Any suggestions (yes I had the full image url)

    Thank you so much. Nestor.

  21. Keith@Assemble Products At Home

    WOW! I never knew there was smart pricing google penalty. Yes it definitely makes sense for google to do that. So I guess that’s why content network is now delivering a quality traffic that converts, many times better than search network.

    Thanks for the codes I can try it.

  22. G money@make money online free

    I like installing the adsence code right into my templates, and forgetting about it. adsence is just a little pleasant surprise at the end of the month

  23. Tom@Song Words

    Thanks for sharing your thoughts man, hope that works better then the plugin I’am using currently (makes trouble all the day). I will try to code it myself even if I’am unexperienced in Coding :-).

  24. John @ ENT Doctor

    I prefer Affiliate Ads then Adsense Ads. It’s about time Google look into making the ads look more like a normal link.

  25. Aluminum Fencing

    I am also not looking for anything that is a scam because that seems to be all that I can find online these times. Please let me know of some websites that any of you have tried and are known to easily work. Thanks in advance and your help would be greatly appreciated.

  26. Ryu

    Thanks. This is nice post. I try it. It works if I search my blog using Internet Explorer. But, when I try with Mozila, the script does not work.

    The same thing is also happen with this web. Try to search “scratch99.com” in google using IE, the adsense appear. But, try to search “scratch99.com” in google using Mozila, the adsense does not appear.

    Anybody know why? Is that mean the script still in Beta?

  27. free software

    Adsense chagned very much. And money are mot the same too. I think the solution is to try something else. For example, try to find sponsors with banners at you site.

  28. Harry

    Will you show me how to prevent visitor from certain countries as well? The main reason i want to do this is to prevent click fraud from countries like indonesia, malaysia, etc

    1. Stephen Cronin Post author

      Hi Harry,

      I’m sure there are ways to do this, but can’t tell you how and I don’t agree with it – I used to live in China and would occasionally come across people blocking everyone in China, which was very frustrating.

  29. Kaushik

    when i am trying to implement this, the ad disappears, but, when i am coming from the google search engine, the ad is not showing up to me. i tried this on blogspot.com free blog. is it not supposed to work there? if yes, what should i write in — “you must change “.scratch99.com” to your own domain” what should be my domain then? just blogspot.com or blogname.blogspot.com?

  30. Udegbunam Chukwudi | StrictlyOnlineBiz

    Please what does the line “expiry.setTime(expiry.getTime() + 3600000);” mean? How do I get the cookie to expire after 5 minutes on the site?
    Thanks

    1. Udegbunam Chukwudi | StrictlyOnlineBiz

      One more thing please, where do I get the value for “google_ad_host = \”pub-xxxxxxxxxxxxxxxx\”? It doesn’t appear anywhere in the regular google adsense code.

      1. Udegbunam Chukwudi | StrictlyOnlineBiz

        The hack works on wordpress but not on blogger blogs and I wonder why. For it to work on wordpress, I had to remove the part about GOOGLE AD HOST.
        Cheers ;-)

  31. Jacob @ My Personal Finance Journey

    Thanks so much for this post. I’m trying to implement it on my site so that a 160×600 adsense block is at the top of my left sidebar. However, Blogger doesn’t seem to be letting me add code to my sidebar template unless it is housed in a Page Element HTML widget.

    Will the code still work if placed in a html/java script widget? If not, is there any way to add code to the sidebar without placing it in a widget?

    Thanks!

  32. Jacob @ My Personal Finance Journey

    OK, so I’ve gotten this to work in that my adsense units are only showing up when I come from a search engine. However, they are only showing up when I land from a search engine on my site’s home page, not specific posts.

    Any one know how to fix this? Thanks!

  33. Jacob @ My Personal Finance Journey

    Got it figured out! I didn’t have my cookie creation first code early enough in my template html for it to be showing up on every page.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Anti-Spam Quiz: