[英]Track page view time using NodeJS behind CloudFlare
I want to know how much time user is watching a specific page (Like Google Analytics). 我想知道用户观看特定页面的时间(例如Google Analytics(分析))。
I thought to open a xmlHttpRequest to my server and set timeout to about 30 minutes. 我以为对我的服务器打开一个xmlHttpRequest并将超时设置为大约30分钟。 On the server, listen to request end, and log it on the server.
在服务器上,侦听请求结束,然后将其记录在服务器上。
$(function($.get('/checktime'))) // start tracking on page load
app.use('/checktime',function(req){
var start=new Date()
req.on('end',log)
req.on('disconnect',log)
function log(){
logToServer(new Date()-start) // Time the user spent on the page
}
}) })
The Questions: 问题:
cloudflare
. cloudflare
。 There is any timeout for cloudflare, so the connection will end before the user leave the page? get
or post
? get
或post
来制作XMLHttpRequest有什么不同? Thank you 谢谢
The implementations I have seen lately open a WebSocket (fallback to long polling) and keep sending data ever few seconds to the server on the other end. 我最近看到的实现打开了一个WebSocket(回退到长时间轮询),并且每隔几秒钟就将数据发送到另一端的服务器。 This also gives you the ability to gather more data using javascript and send that up to the logging server as well
这也使您能够使用javascript收集更多数据并将其发送到日志记录服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.