Hey Folks,

A webmaster is always curious to know about the visitors on his website such as the number of visits, pageviews etc. Another important thing which needs to be taken care of is when do the Googlebot or crawler visits your website. Albeit, this information can be collected from Google’s webmaster tools but in some cases we need to know instantly when the google bot visits  your website.

So for that insert the following PHP code on your webpage. You can insert this code on the index page and it can be inserted anywhere on the page, may be in the header or footer. This code simply detects the term “Googlebot” in the useragent supplied and then shoots an email to the specified email address. You can also extend that code to store the information to the database and can analyze afterwards.

Just a note, anyone can easily fake the useragent to pretend as Google bot and can send mass mail to your email address. So its a best practice to do some validation before you implement this script, you can try inserting the IP of the user in the database with corresponding timestamp.

This script is not limited to only Googlebot, you can replace the useragent “Googlebot” with Yahoo, MSN etc if you are interested in knowing when their crawler(s) visit.

Next time Googlebot visits your website, you will be pinged to welcome it.

Hope you learnt something new.

Stay Digified !!

Sachin Khosla.

Share this post: