Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

(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!

share|improve this question

5 Answers 5

up vote 7 down vote accepted

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 :)

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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:

<?php
// add ip addresses you don't care about here
$no_mail = array(
    '24.254.148.80',
    '67.145.115.105',
    '207.46.149.50',
);
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI';
$to_email = 'me@example.com';
if (!in_array($_SERVER['REMOTE_ADDR'], $no_mail)):
    $body = $url . "\n\n". print_r($_SERVER, true);
        $headers = 'From: webmaster@example.com' . "\n" .
        'Reply-To: webmaster@example.com' . "\n" .
        'X-Mailer: PHP/' . phpversion() . "\n";
    mail($to_email,
        'Email from '. url . $_SERVER['REMOTE_ADDR'],
        $body
        , $headers) or die("<!-- error with email -->");
    print "<!-- notification sent -->";
else:
    print "<!-- no notification sent -->";
endif;
?>

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.

share|improve this answer
    
Hmm, I wonder why this was downvoted. Anyway this is actually a question from stackoverflow.com –  delete Jul 14 '10 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 Jul 15 '10 at 9:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.