跟踪独特的页面浏览量

发布于 2024-08-06 04:13:32 字数 273 浏览 5 评论 0原文

跟踪特定页面的页面浏览量(特别是唯一的)的最佳方法是什么?

示例:论坛中的主题、视频网站中的视频、问答脚本 (SO) 中的问题。

目前,我对尝试计算视图数的每一行采用简单的“视图”列的方法,但是,我知道这不是最有效的方法。

对于独特的视图,我有一个单独的表,其中包含包含“QuestionID”和“UserID”的行。当用户访问问题/页面时,我的代码尝试在视图表中查找包含“UserID”和“QuestionID”的行,如果找不到,则会添加一行,然后增加问题中问题的视图值“问题”表。

What is the best method of tracking page views (uniques specially) for a certain page?

Example: Threads in a forum, Videos in a video website, questions in a Q/A script(SO).

Currently, I'm taking the approach of just a simple "Views" column for each row I'm trying to count the views for, however, I know this is not the most efficient way.

And for unique views, I have a separate table that holds a row with the "QuestionID" and "UserID". When a user visits a question/page, my code attempts find a row in the views table with the "UserID" and "QuestionID", if it can't, it adds a row, then increments the Views value of the Question in the "Questions" table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如日中天 2024-08-13 04:13:32

您的存储解决方案似乎是跟踪用户的最佳方式。这些表没有冗余数据,并且多对多关系由其自己的表表示。

另请注意:
对于匿名用户,您需要记录他们的 IP 地址,并且您可以使用 COUNT() sql 函数以这种方式获取唯一访问者的数量,但即使 IP 地址本身也不是“唯一”的。

your solution for storage seems to be the best way to track for users. The tables don't have redundant data and your many to many relationship is represented by its own table.

On another note:
For anonymous users you would need to record their IP address, and the you can use the COUNT() sql function to get the number of unique visitors that way, but even and IP address not "unique" per se.

嘿咻 2024-08-13 04:13:32

首先,当您有一个存储 userid-quesitonid 对的表时,这意味着您可以对它们进行计数,我认为添加视图列违反了规范化规则。

另一件事是,如果您没有实现 cookie 解决方案,我可以根据需要按 F5 任意次数,如果没有,则向表中添加一行。

当谈到IP地址解决方案时,这根本不是一个解决方案,它会把人们挡在路由器后面。

我想到(现在也在实施)一个解决方案,检查 cookie、sessionIds、注册用户的数据库表,如果没有找到,则向表中添加一行。 Itr 还记录 SessionID 和 IP 地址,但并不真正依赖它们。

First of all when you have a table that stores userid-quesitonid pairs, it means you can count them, adding a views column is against the rules of normalisation I suppose.

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

when it comes to ip address solution, which is far form being a solution at all, it will blcok people behind routers.

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

月下凄凉 2024-08-13 04:13:32

如果您使用 ASP.NET MEmbership 和匿名用户的匿名提供程序,则只要您执行 Profile.Save(),每个匿名用户都会在 aspnet_Users 表中创建一行。在这种情况下,您可以跟踪查看特定页面的匿名用户和注册用户。您所需要做的就是记录 aspnet_user 的 UserID 和 QuestionID。

但是,我强烈建议您不要在数据库级别执行此操作,因为它可能会破坏您的数据库。如果您有 10,000 个问题、1,000 个注册用户和 100,000 个匿名用户,并假设每个用户平均访问 10 个问题,那么跟踪表中最终会有 100 万行。相当有一些负担。

此外,在跟踪表上执行 SELECT COUNT() 会对数据库造成相当大的负载,尤其是您几乎在论坛上的每个页面视图中都执行此操作。最好是在问题表中针对每个问题保留一个总计数器。每当您有唯一用户查看页面时,您只需增加计数器即可。

也不要从跟踪表创建与用户表的 FK 关系。您将需要清理 aspnet_users 表,因为随着时间的推移,它会堆积大量匿名用户,这些用户很可能永远不会回来。因此,跟踪页面只需包含 userID 字段,而无需 FK。此外,随着时间的推移,您将不得不清理跟踪表,并且它将不断获得数百万行。这就是为什么 TotalView 计数器需要位于问题表中,并且永远不要使用 SELECT COUNT() 来计算显示页面时的视图数。

这能回答你的问题吗?

If you are using ASP.NET MEmbership and the Anonymous Provider for anonymous users, then each anonymous user gets a row created in aspnet_Users table as soon as you say Profile.Save(). In that case, you can track both anon and registered users viewing certain Page. All you need to do is record the aspnet_user's UserID and the QuestionID.

However, I strongly discourage doing this at database level since it can blow up your database. If you have 10,000 questions and 1,000 registered users and 100,000 anonymous users, and assuming each user visits 10 questions on an average, then you end up having 1M rows in the tracking table. Quite some load.

Moreover, doing a SELECT COUNT() on the tracking table is quite some load on the database, especially you are doing this almost every page view on your forum. Best is to keep a total counter at the Question table against each question. Whenever you get a unique user looking at a page, you just increase the counter.

Also don't create a FK relationship to the user table from the tracking table. You will need to cleanup the aspnet_users table as it piles up a lot of anonymous users over time who will most likely never come back. So, the tracking page needs to just have the userID field, and no FK. Moreover, you will have to cleanup the tracking table over time as well as it will keep getting millions of rows. That's why the TotalView counter needs to be at the Question table and never use SELECT COUNT() to calculate the number of views while displaying the page.

Does this answer your question?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文