页面浏览量和点击量_如何计算页面浏览量

页面浏览量和点击量

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.

我认为,更好的方法是..我们可以在数据库中保存页面浏览量。 它是可以接受的。 但是,如果许多不同的用户似乎具有相同的IP地址(例如,如果它们来自大型组织),那将不能满足我的要求。 如何重新设计表格以适合这种情况。

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.

每页都有一个计数器。 对于每个用户,请通过Cookie中的ID(会话ID?)来标识他们。

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.

与每个计数器一起,记录最近一段时间(例如30分钟)中带有时间戳的用户ID。 每次点击计数器/页面时,请先检查用户ID列表,然后删除时间戳早于30分钟的用户ID。 然后检查此匹配的当前用户ID是否在用户ID列表中。 如果存在,则什么也不做。 如果不存在,请增加计数器,然后将具有当前时间戳记的当前用户ID添加到该计数器的用户ID列表中。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-count-the-number-of-page-view/

页面浏览量和点击量

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Java后端实现浏览量点击时自增的示例代码: 首先,定义一个实体类用于表示存储在数据库中的浏览量信息,例如: ``` public class PageView { private String url; private int viewCount; // 省略构造方法和Getter/Setter } ``` 然后,在处理请求的Controller中,可以按照如下方式实现浏览量的自增: ``` @RestController public class PageController { @Autowired private PageViewService pageViewService; @GetMapping("/page") public String getPage(@RequestParam String url) { // 查询该页面浏览量信息 PageView pageView = pageViewService.getPageView(url); // 如果该页面浏览量信息不存在,则创建一个新的浏览量记录 if (pageView == null) { pageView = new PageView(url, 0); pageViewService.savePageView(pageView); } // 将页面浏览量加1 pageView.setViewCount(pageView.getViewCount() + 1); pageViewService.updatePageView(pageView); // 返回页面内容 return "Hello, World!"; } } ``` 在上面的代码中,`pageViewService`是一个服务类,用于封装对数据库的操作,例如查询、插入和更新浏览量信息。`getPageView`方法用于根据页面URL查询该页面浏览量信息,`savePageView`方法用于将新的浏览量记录插入到数据库中,`updatePageView`方法用于更新数据库中已有的浏览量记录。 需要注意的是,在实际应用中,为了避免页面刷新时重复计数,可以使用Cookie或者Session等技术记录用户的浏览行为,从而避免重复计数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值