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 u开发者_如何学运维sers. 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?
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
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.
精彩评论