Receive-Email-when-Google-directs-visitors-to-your-site

by MD on 2009/09/20

Below is the php code using which you can receive a email when Google directs a visitor to your website. Using this you will also come to know serch keywords used i.e. what exactly visitors searched when he/she was redirected to your site. If you are using WordPress self-hosted blog, then you can put this code somewhere in header.php or footer.php file of your current theme.

<?php
    // Script to email you when Google refers traffic to your site.
    $name = "Your Name";
    // add your name here
    $email_address = "abc@xyz.com";
    // add your email address here
    $keywords = "";
    $referrer = $_SERVER['HTTP_REFERER'];
    if ((
    stristr($referrer, "google")) && (stristr($referrer, "search")) ) {
        parse_str($referrer, $output);
        $keywords = $output['q'];
        $email_message = "Hi $name, A visitor just arrived to your site after searching for '$keywords'. ($referrer)";
        mail ("$email_address", "Google referred a visitor", "$email_message");
    }
?>

You may also like:

Leave a Comment

Previous post:

Next post: