How to count the number of page view

I have seen the question Better way to count total page views?

I think, the better way is.. We can save the number of page views in the database. It is acceptable. But, it is not fulfilling my requirement, if many different users can appear to have the same IP Address (e.g, if they are coming from a Large organization). How to re-design the table to suit for this scenario.

Can anyone help me to design the table with sample data.

A brief idea:

For each page, there is a counter. For each user, identify them by an ID (session ID?) in the cookie.

Along with each counter, record the user IDs with time stamps in the last a period of time (say, 30 mins). Each time a counter/page is hit, first check the user ID lists, delete those with timestamps older than 30 mins. Then check whether the current user ID for this hit is in the user ID list. If it exists, do nothing. If it does not exist, increase the counter and add the current user ID with the current timestamp to the user ID list for this counter.

Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *