Get notified when Googlebot visits the page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
faglork

Get notified when Googlebot visits the page

Post by faglork »

Hi all,

sometimes you just need to know when Googlebot (or any other bot) visits your pages.
In most cases you are interested in a special page - e.g. you might want to know whether the Goog visits your News Overviev regularly or not at all. Wouldn't it be a great idea if the page would simply send you an email when Googlebot visited?

It just takes a simple UDT:

Code: Select all

$ua = $_SERVER["HTTP_USER_AGENT"];
if(eregi("Googlebot",$ua)) 
  { 
   $server = $_SERVER["SERVER_NAME"];
   $filepath = $_SERVER["REQUEST_URI"];
   $url = "http://".$server.$filepath;
   $today = date("F j, Y, g:i a");
   $subject = "Googlebot detected on $server";
   $msg = "$today - Google crawled $url";
   $to = "me@here.com";

   mail("$to", "$subject", "$msg"); 
 } 
  • - name the UDT as you like, e.g. "botcheck"
  • - substitute "Googlebot" with the name (i.e. the string that identifies the bot) of the bot you want to monitor
  • - change $to, $msg and $subject to suit
  • - put {botcheck} on the page you want to monitor
There you go ...

If you want to monitor many pages, put it into the template(s) or into the footer.

Have fun!
Alex
Last edited by faglork on Thu Feb 28, 2008 11:00 pm, edited 1 time in total.
Post Reply

Return to “Tips and Tricks”