How To Easily Hide Client-side Content from Google Web/Mobile Preview Bot
I’m really liking the new Preview option on Google Mobile Search, and I reckon it will be used far more than preview in regular web search. But there’s a small problem. Well actually a couple of problems, but here’s the solution to one:
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf('google web preview') == -1){
showContent();// whatever content you want to hide from Preview Bot
}
The above wont run showCntent() to Google’s PreviewBot. Why might you want to do this? Well I like to run surveys on some sites to gather qualitative feedback. I tend to use 4QSurvey.com for this (free, easy to set up, and gives great insight). The last thing you want is PreviewBot showing your website with the lightbox questionnaire, so it’s easy to block out. This is the code I use to load 4QSurvey asynchornously:
<script type="text/javascript">
(function(){
var UA = navigator.userAgent.toLowerCase();
if(UA.indexOf('google web preview') == -1){
var survey=document.createElement('script');
survey.src = "http://4qinvite.4q.iperceptions.com/1.aspx?sdfc=[your code]&lID=1&loc=4Q-WEB2";
survey.type = 'text/javascript';
survey.async = true;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(survey, s);
}
})();
</script>
The above will not block loading, and ensure PreviewBot doesn’t show a site preview with pop-up. To learn more about PreviewBot see Google’s Web Preview docs. The UA used for PreviewBot is “Google Web Preview (Mozilla/5.0 (en-us) AppleWebKit/525.13 (KHTML, like Gecko; Google Web Preview) Version/3.1 Safari/525.13)”.
Well Richard, long time no hear, the preview is not something i would of even thought of re google previewing a script etc, what about making the preview show what you want?
What do you make of big Gs current so called shake up aimed at content farms and the like, i always assummed that the search algo had some type of content quality weighting, yet it seems that the borderline gibberish that is the world of auto content is effecting the results.
Comment by Derek — March 9, 2011 @ 12:16 pm
Hi Richard
We run a lot of surveys for our clients, and we also noticed that the popups show on some of the previews. Your trick is really neat, so I will hurry to start the first implementation
Comment by Jesper Jørgensen — April 5, 2011 @ 11:10 am
where are you at at the moment?
your updates are missed?
just subscribed to see if you have any new links for really really good search engines apart from the usual..
is there any more coming on stream in the future?
kind regards
denise
Comment by denise — May 5, 2011 @ 4:49 am
Is it possible to go even further? To use preview as a “teaser”, which says “visit the real page for the good stuff”.
That is worth a few thoughts, I say.
Comment by Sanovnik — July 3, 2011 @ 9:11 pm
Missing the regular updates, but a great post as always. I’m going to look into the previews on my sites and check they are showing correctly. This is going to be really important for getting the best click through rates.
Comment by Jon Tiffany — November 14, 2011 @ 5:20 pm
This is the exact code I was looking for! I’ve discovered that when you work in web design you have to run a lot of reports, and making sure that they don’t interfere with Google’s preview results is absolutely key.
Comment by Rory — May 14, 2012 @ 6:40 pm
Thanks for the great trick Richard, will come in handy.
Comment by Jesper Damtoft — November 5, 2012 @ 5:16 pm
Been searching for a trick like this. I’ve noticed that this post is a bit old, does it still work?
Comment by Mark — April 6, 2013 @ 1:28 pm
Yep – still works.
Comment by Richard Hearne — April 10, 2013 @ 6:29 am
Thanks for a quick response, Richard. I’ll share this with my production department right away. Have a nice day
Comment by Mark — April 10, 2013 @ 8:54 am
Thanks for the trick,
it seemed to work right away, and saved me a lot of trouble figuring it out another way.
Thanks
Comment by Simon — May 21, 2013 @ 12:56 pm