views:

65

answers:

4

I'm looking for a way to track the number of visits to a page, without counting duplicates (like someone hitting refresh several times) and I'd like to figure out the best way to do it without keeping track of every single IP address to view the page. Perhaps a cookie? Any other suggestions?

+3  A: 

Either use Webalizer to analyse your logfiles or use Google Analytics to track those metrics for you or - if you are looking for an extendable and self hosted solution, try Piwik:

Piwik is a downloadable, open source (GPL licensed) real time web analytics software program. It provides you with detailed reports on your website visitors: the search engines and keywords they used, the language they speak, your popular pages… and so much more.

In any case, there is no reason to reinvent the wheel here. Also, the software mentioned above is only a tiny fraction of web analysis tools out there.

Gordon
Yeah, I use google analytics for just analyzing my traffic, but I'm actually trying to count traffic for my users, so i can show them a rough count of their own content's traffic. That's why I just want a number to stick in my MySQL database... hopefully just one number each, and not making room for all the IP's
RobHardgoo
@RobHardgoo ok, well if you dont mind having a full analytics software running, have a look at Piwik then. That would give you a foundation to build on, so you dont have to start from scratch.
Gordon
A: 

Cookies are a good way to achieve this, however you have to keep in mind that users could have disabled cookies... When a user visits your page, just check if your cookie is already present, if not, count++ :)

Tapdingo
What should I do if they disable cookies but try to be counted several times?
RobHardgoo
If this a problem i guess you have to use the IP-address approach... However a client could change their IP address as well...
Tapdingo
A: 

A cookie will fit. Just at each page view you check if it is set. If so, don't count it. Otherwise, count it and set the cookie.

You will have problems with people not having cookies enabled or cleaning them out after each visit. You should pair this approach with PHP sessions: instead of doing the process on each page view, do it only once, on session start. This will at least avoid counting visits within a single session.

All this is you want to store everything client-side. If you were server-side, you could use IP addresses, or pair them with the user agent string.

Or, just use google analytics...

Palantir
I guess a session would at least prevent it from being duplicated too frequently, right? Like a two hour session...
RobHardgoo
Yes, it depends on your session length. But if the browser is set to clean session cookies on exit, then you will get duplicates.
Palantir
A: 

You mentioned in one of the other comments that you are already using Google Analytics, so you should be able to do the following:

Create a custom report with "Page" as a Dimension and "Unique Visitors" as a metric. This will tell you how many unique Visitors there were for all of your pages for whatever time frame.

Crayon Violent