开发者

Determine how many users viewed a page

开发者 https://www.devze.com 2023-01-04 05:28 出处:网络
I am working on a component in C# to record how many unique viewers have viewed my website / page, making certain the same user revisiting, is not recorded twice. What is an efficient method to write

I am working on a component in C# to record how many unique viewers have viewed my website / page, making certain the same user revisiting, is not recorded twice. What is an efficient method to write such a component? Do you track cookies or session objects? Would I record their ip 开发者_如何学编程address (which is not static) or computer name? This information would be stored in a database (as far as I know)

Thanks.


Why reinvent the wheel? Use Google Analytics - it's free, extremely easy to implement, provides more statistics than you could ever want, and can provide (as best as it is possible using cookies) unique visitor stats. If you really need to store the data in a database (why?) then you can use the Google Analytics API to get at it and do what you want with it.


Yes you can record IP address, if you use a traditional Login scheme (if using membership user) this Link can guide you. Check this question on IP which tells you how IP can be gathered. It's not a bad idea if you get the MAC of the host machine so you can easily determine the unique visitor tracking.


People are saying that recording IP is a bad idea because you could have situations with hundreds of people behind the same IP, this is true, however, using IP address will still give you a statistically meaningul number.

If it is core for your application to guarantee unique, then unfortunatly that is not possible to do in a guaranteed way.


Recording the IP address is not a good idea as many people actually use NAT to get from their local network to the Internet. So many people would appear to you as a single person because they all have the same public IP address. If you are on an intranet, this might work but definitely not for a public web site.

A better solution is to write a GUID to a cookie on the user's computer and stored in your database. Then look for that cookie again in the future and compare with the values in the database.


Unique visits by IP address is always a problem, as you could have an organisation with a unique IP but hundreds of people behind that IP.

I think cookies are your best bet.

I assume you have a reason for not using a stats or analytics package?


Both IP addresses and cookies have their tradeoffs. A single user could be hopping from wifi hotspot to wifi hotspot, throwing off your IP metrics. Many users could be behind the same IP address (employer, ISP, proxy, etc.). So IP address would not be entirely accurate.

On the other hand, a single user at a single IP could access your website through multiple browsers or devices, so cookies would not be entirely accurate.

And what of the user that accesses your website from home and from work? One visitor, two (at minimum) unique cookies and IP addresses.

Pick the invalid data that works best for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消