views:

25

answers:

2

I use my webserver's logs to count visits to my website.

The software "Webalizer 2" displays these data in plain form with some diagrams.

But now I want to count visits by a special group of users separately. I have premium users and standard users. For premium users I want to have a separate statistics page so that I can see how many premium users' hits there are.

How can I achieve that?

In my PHP script files, I detect the status as follows:

<?php
if ($_SESSION['status'] == 'premium') {
  // do something here
}
?>

The easiest way would - of course - be to have a MySQL update statement there to increment the premium users' counter.

But that would also be a lot of database traffic. So I would prefer another solution.

I thought I could show a 1x1 pixels .gif image to the premium users. Then I could check the webserver's statistics for the file "counter.gif". BUT: I guess the client will cache the graphics file so my results won't be correct, right?

Do you have an idea how to implement such a counter?

+3  A: 

There are many solutions to this problem...

If you use a 1x1 pixel gif and are worried about caching, do something like this:

<img src="counter.gif?t=<?php echo time(); ?>" alt="" />

But then you'd still have to have some tool on the backend to track, and then analyze this data.


Alternatively Google Analytics has created simple ways to do this. Assuming you're already using their tracking code, you can add a Custom Variable. See more here:

http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#visitorLevel

philfreo
+1 for Analytics. It doesn't sound like OP is currently using it, but this might be the perfect excuse to start. I used to run something like Webalizer on my server logs, and I'm very glad I made the switch to Analytics.
grossvogel
Yes, exactly, I haven't been using Google Analytics so far. But the approach with the time parameter is a good one. Thank you very much!
+1  A: 

An alternative to a database solution, could be something like adding a query string to the url for the premium users like:

?user=premium

And register the different urls with for example Google Analytics, but I don't know if your site structure allows for that.

jeroen
Thank you, this is possible, of course. But it seems to be a very complex or time-consuming way.