[英]Architecture: Javascript event tracking in browser
I want to make a custom tracking system for web events.我想为 web 事件制作一个自定义跟踪系统。 I have looked into multiple per-excsiting systems, but I want something terribly simple - yet very accurate.
我研究了多个令人兴奋的系统,但我想要一些非常简单但非常准确的东西。
I want to be able to track the following:我希望能够跟踪以下内容:
or:或者:
My first initial thought was to do a simple javascript reporting back to the server, but what happens if the user closes the window?我最初的想法是做一个简单的 javascript 报告给服务器,但是如果用户关闭 window 会发生什么? How do I know they stopped viewing?
我怎么知道他们停止观看? And how can I get accurate measurements down to 1/10th of a second?
我怎样才能获得精确到 1/10 秒的测量结果? So I thought of a websocket solution, as it know when a user has discounted.
所以我想到了一个 websocket 解决方案,因为它知道用户何时打折。 I ended up with Socket.io, but I want to make sure there is no better or smarter way to achieve this?
我最终得到了 Socket.io,但我想确保没有更好或更智能的方法来实现这一目标?
How would you approach his challenge?你会如何应对他的挑战? What is the smartest way to engineer this?
设计这个的最聪明的方法是什么?
A Websocket connection which reports back to the server frequently was my first thought as well, but if you send 10 messages every second, even that might be too much for a websocket, especially when connectivity isn't top-notch.经常向服务器报告的 Websocket 连接也是我的第一个想法,但是如果您每秒发送 10 条消息,那么对于 websocket 来说,这可能太多了,尤其是在连接性不是一流的情况下。
Since the server doesn't require the information absolutely immediately, consider batching requests instead - save/update the information into Local Storage every 0.1 seconds, but don't send it to the server then - instead, every 30 or 60 seconds, or on pageload, take the current data in Local Storage and send it to the server, and clear Local Storage so that the next request a minute from now doesn't send duplicate data.由于服务器不需要绝对立即获得信息,因此请考虑批量请求 - 每 0.1 秒将信息保存/更新到本地存储中,但不要将其发送到服务器 - 相反,每 30 或 60 秒,或页面加载,获取本地存储中的当前数据并将其发送到服务器,并清除本地存储,以便一分钟后的下一个请求不会发送重复数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.