views:

83

answers:

3

I'm planning on storing the number of times an article / page has been viewed in a database. This is so that I can have a list of "most popular posts / articles" in Wordpress.

This was a good thread for similar question: http://stackoverflow.com/questions/943967/how-view-count-is-best-implemented

My question is: A person may view an article multiple times on the same day / week.

What is the industry best practice for counting the number of times an article is read by the same person?

And is there a way to solve multiple users being behind same IP Address?

Update

I'm not after the coding techniques for counting article / post viewes (session, cookies IP address, CGI etc).

I'm just wondering what logic is best to use for counting articles read by the same person over time?

+1  A: 

For anonymous viewing, you can associate an IP address with an individual. For non-anonymous usage, you can use the credentials of a person to make sure that multiple viewings of the same page by the same credentials (i.e., individual) do not result in multiple increments to your view counts.

Michael Goldshteyn
Users are anonymous, so I most probsbly will have to use IP address. What about the issue of users being in a large company / school having only one IP address?
Steven
If I understand your issue correctly; grabbing the environmental variables would likely be your only choice. As you mentioned, an IP address would work as long as visitors weren't using a proxy. Once I had the variables, i would use some conditional logic to parse and make an educated guess. CGI also has the IP address on the local machine.
fergNab
For multiple users on a single IP (e.g., NAT) you're SOL with this method.
Michael Goldshteyn
And that's what I'm asking for. What is the best educationalt guess for counting? I've never done it before, so I'm looking for some pointers.
Steven
@Michael: What does SOL stand for?
Steven
@Steven: Depending how much effort you want to put in, there are a number of ways to distinguish browsers sharing an IP: https://panopticlick.eff.org/. Only an approximation, of course - fundamentally you can't tell the difference between two different people, and one person using two machines.
Steve Jessop
@Steve - Thanks. Distinguishing multiple users behind same IP address is not vital, just nice to have. Therefore it kind of boils down to how I want to count them. Maybe using sessions, where info is stored in session until user leaves page.
Steven
SOL - Sorry out of luck
Michael Goldshteyn
A: 

I recommend grabbing all the CGI environment variables like: these from the visitor, parsing them and adding them to a database. This will provide you with a better idea of return visitors.

fergNab
If I was doing CGI scripting that would be a good way. But I'm using PHP.
Steven
@Steven You get all that information in [`$_SERVER`](http://php.net/manual/en/reserved.variables.server.php).
lonesomeday
Steven, look at this: http://www.phphelp.com/tutorial/common-php-tasks-and-questions.php?page=4
fergNab
@ferg: Thanks, nice to know.
Steven
+1  A: 

This can be a really complex problem to solve depending on what you are trying to do. I would suggest fist looking at google analytics or piwik which is some php application you install and use like google analytics.

If you need an in house solution then most likely you have to leverage cookies. There are two types of cookies. A simple cookie can be dropped when user is on page foo.com and the application is trying to set a cookie on foo.com. Another type of cookie is when you are viewing foo.com but another application is trying to create a cookie for bar.com. This is called a 3rd party cookie which sometimes is blocked. This is how services like google analytics track users.

There are other ways to find unique users. You can use ip address, browser signature, etc... The problem with these solutions are that many companies, universities, or other large companies are usually behind one ip address. You don't want to count a whole department as one person.

There other ways you can track users but these are advanced. (localStorage, flash, cache).

I would advise to use Google Analytics first. If this is not enough then you can pursue other options.

Amir Raminfar
Yes, it's an complex issue. I already use Google Analytics. I'm just making a plugin to display 'most popular posts' in Wordpress.
Steven
I thought wordpress already has that plugin. I don't know wordpress enough to know though.
Amir Raminfar
Wordpress has many plugins for this. But I don't know what logic they use. I've seen many just adding 1 to the counter every time it's loaded. That's not a good solution.
Steven