views:

139

answers:

4

I want to log unique visits to a particular page on my site. What is a pretty accurate yet simple way to do this? Simply by IP? Suggestions?

Let me clarify a bit:

I have a list of articles on my site. Every article is actually the same page like article.aspx. However the content is different based on thee article being viewed. I want to track unique views of a particular article.

Thanks!

+1  A: 

Cookies. Check for a unique cookie value. If it already exists, the user has already visited your site. If not, track the unique visit and assign the cookie.

Optionally, you can also use the expiration date on a cookie to make sure it only happens once every n-th second/minute/hour/day, etc.

MK_Dev
+1  A: 

Use a combination of cookies and IP addresses. If you use only cookies then a user (or robot) with cookies turned off can run up your page views. If you use only IP then you block all computers on a proxy.

Lucas McCoy
+2  A: 

All approaches will have their drawbacks. Cookies may not be enabled in the browser, IP addresses may be duplicated due to NAT (I know at our work, all traffic to the outside world looks like it's coming from one IP address) or reused due to DHCP.

It depends on what you're going to use the information for. If you want to know how many unique people are viewing your site, that's incredibly difficult since many people may use one browser or IP address.

I would think most people are interested in how many useful accesses are made. This means that, even if the same IP address comes back one week later, that should count again.

We've used that exact system (and made sure our clients realize it's an imperfect one). Store the IP addresses and first and last date of access in a table.

If it's a newly added IP address, add one hit and store IP/dates. If it's an already existing IP, update the last date. Do a nightly sweep to remove IP's whose last date is older than 7 days or whose first date is older than 14 days (both configurable).

That way you catch the useful accesses:

  • people who visit continuously are assumed to have a useful access every two weeks.
  • people who visit then disappear for a year and visit again have had two useful accesses.
  • people who visit once have had one useful access.

As long as the inadequacies are understood, they can be managed.

paxdiablo
+2  A: 

Why not use an analytics package like Google Analytics?

metanaito
Bingo. Don't reinvent the wheel unless necessary.
ceejayoz