Tracking unique page views

What is the best way to track pageviews (specific to a specific page) for a specific page?

Example: Threads in a forum, videos on a video site, questions in a Q / A script (SO).

I am currently approaching a simple "Views" column for every row I am trying to count, but I know this is not the most efficient way.

And for unique views, I have a separate table containing a row with "QuestionID" and "UserID". When a user visits a question / page, my code tries to find a row in the view table with "UserID" and "QuestionID", if it can't, it adds a row and then increments the question's "Views" value to the Questions table.

+2


source to share


3 answers


Your storage solution seems to be the best tracking method for users. There is no redundant data in the tables, and your many-to-many relationship is represented by your own table.



On the other hand: For anonymous users, you will need to write down your IP address and you can use the sql () function to get the number of unique visitors this way, but even the IP address is not "unique" as such.

+1


source


First of all, when you have a table that stores userid-quesitonid pairs, that means you can count them by adding a view column against the normalization rules I suppose.

Another thing is that I can F5 as much as I want if you don't implement a cookie solution, if not then add a row to the table.



when it comes to an ip address solution which is a distant form is a solution in general, it will block people behind routers.

I'm thinking of (also implementing right now) a solution that checks for cookies, sessionIds, DB table for logged in users and, if not found, adds a row to the table. Itr also records SessionID and IP addresses anyway, but doesn't really rely on them.

+1


source


If you are using ASP.NET MEmbership and the anonymous provider for anonymous users, each anonymous user gets a row created in the aspnet_Users table as soon as you say Profile.Save (). In this case, you can track both anonymous and registered users viewing a specific page. All you have to do is write down the aspnet_user UserID and QuestionID.

However, I strongly discourage doing this at the database level, as it can blow up your database. If you have 10,000 questions and 1,000 registered users and 100,000 anonymous users, and if each user visits 10 questions on average, you end up with 1M rows in the tracking table. A little load is enough.

Also, doing SELECT COUNT () on the watch table is quite loading into the database, especially you do it on almost every pageview on your forum. It is best to keep a counter in the question table for each question. Whenever you get a unique user looking at the page, you just increment the counter.

Also, don't create an FK relationship to the users table from the tracking table. You will need to clear the aspnet_users table, as it will over time close many anonymous users who will most likely never return. Thus, the tracking page should only have a userID and FK field. In addition, you will have to clear the tracking table over time and also keep getting millions of rows. This is why the TotalView counter must be in the Question table and never use SELECT COUNT () to calculate the number of views when the page is displayed.

Does this answer your question?

0


source







All Articles