(I copied this question from stackoverflow.com, maybe someone here has the answer?)

I was wondering if its possible with Google Analytics to send real-time HTTP notifications to say PHP when a user visits my website. If not, I am curious about any real-time notifications that Google Analytics can send to me when a user visits my site. Thanks!

5 Answers 5


I don't believe that Google Analytics has any real-time analytics. In fact, if you set your scope to the current day, you can see that it takes quite a while to collate all of your hits to your account for analysis, likely because they've got massive distributed writes going on, and only occasional aggregation.

An article on TechCrunch does hold out some hope that real-time analysis MAY be coming to Google Analytics, but I wouldn't hold my breath :)


You should check out chartbeat.com. (It does cost though, $9.95 for most sites, so if you need it free, then chartbeat isnt for you. Unless you only need it for a bit, then you could use the free trial and then cancel...)

They have real-time analytics and they have an API you can use to access the data. They don't have a way to send a notification to you though. You would have to poll them checking for new visitors.


2 options I know of:

  1. Piwik: Open source real time analytics. I don't use this, but I have a friend who does and he really likes it. It does look pretty nice and with something like this you can do all sorts of other things with the data (such as your own real time stats on the website).

  2. Custom: You can easily add a database table where you insert a record every time you get a page hit. You can also store a session id or some other unique string for each user so you can group them or detect if it's a new vs returning visitor. You can also add additional functionality using AJAX to record how long they've been on the page.

    I've done similar functionality on sites that were getting 100k+ hits per day and haven't noticed any extra load, but I kept the table really simple with only a primary key. If you want to get immediate results/numbers on the table, you'll probably need some keys, although you could also have a script that moves the data from the flat table into a table that combines the data into something more useful (hits per user, length of visit, etc).

    With this type of solution, you could also add functionality that would allow you to communicate with the visitor while their on the website by sending them a message.


You can use this api http://www.google.com/analytics/apps/about?app_id=61001

or follow from analytics web page, they have Real Time (Beta) version running, right now, perhaps you may find how to use analytics api.


If you want is just a one off notification, you could do something like add a small notifier for the page. I do that sometimes but usually shut it off soon after, because it can generate a pile of email. Use sparingly.

You specifically mentioned PHP, so I'm including code:

// add ip addresses you don't care about here
$no_mail = array(
$to_email = '[email protected]';
if (!in_array($_SERVER['REMOTE_ADDR'], $no_mail)):
    $body = $url . "\n\n". print_r($_SERVER, true);
        $headers = 'From: [email protected]' . "\n" .
        'Reply-To: [email protected]' . "\n" .
        'X-Mailer: PHP/' . phpversion() . "\n";
        'Email from '. url . $_SERVER['REMOTE_ADDR'],
        , $headers) or die("<!-- error with email -->");
    print "<!-- notification sent -->";
    print "<!-- no notification sent -->";

This is in no way a comprehensive solution. You could so a similar thing by just running a tail on your logs and grepping for information about the pages you care about.

  • Hmm, I wonder why this was downvoted. Anyway this is actually a question from stackoverflow.com
    – delete
    Commented Jul 14, 2010 at 23:39
  • I expect people see source code and they get offended. Meh. It's about tools. Sometimes there's code involved for webmasters. I'm happy with the answer and don't mind downvotes.
    – artlung
    Commented Jul 15, 2010 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.