用户在 asp.net 页面上停留了多长时间(自定义分析)?

发布于 2024-08-06 16:48:55 字数 427 浏览 3 评论 0原文

我试图想出一种方法来测量用户在 ASP.NET 应用程序中的页面上停留的时间。我将用户 ID、页面名称、页面输入时间和页面离开时间存储在数据库中。每条记录也有自己唯一的 ID,称为 featureuselogid。

目前,我可以使用服务器端的 page_load 函数跟踪用户何时进入页面。我存储用户 ID、页面名称和页面输入时间。

之后我陷入困境,需要一些正确方向的指导。我需要记录用户离开页面的时间。我知道在 javascript 中有一个 window.onbeforeunload 函数,它将涵盖大多数情况(浏览器关闭、链接等)。

但是如何将 featureuselogid 传递给 javascript?如果我能做到这一点,我想我可以从 javascript 进行网络服务调用并使用 pagelefttime 更新记录。

我是否走错了路?

提前干杯。

I am trying to come up with a way to measure how long a user has been on a page in my ASP.NET application. I am storing the userid, pagename, pageenteredtime and pagelefttime in a database. Each record has its own unique id as well, called featureuselogid.

At the moment, I can track when a user comes into the page with the page_load function on the server side. I store the userid, pagename and pageenteredtime.

After that im stuck, and need some guidance in the right direction. I need to record the time the user leaves the page. I know in javascript there is a window.onbeforeunload function, which will cover most cases (browser shutdown, links etc).

But how do I pass the featureuselogid to the javascript? If i can do that, I think I can make a webservice call from the javascript and update the record with the pagelefttime.

Am I going down the wrong path?

Cheers in advance.

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

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

发布评论

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

评论(3

我喜欢麦丽素 2024-08-13 16:48:55

您必须在客户端上运行 Javascript 计时器来定期调用服务器。一旦呼叫未在预期时间被记录,则意味着用户已离开。 Woopra 就是这样做的,而且工作可靠。例如,有时人们会在后台的浏览器中加载一个页面数天,并且没有其他方法可以检测他们是否仍然处于连接状态。

笔记本电脑上的用户拔掉网络电缆、移出 Wifi 区域的覆盖范围等,在很多情况下 onbeforeunload 事件将不再到达服务器。

You will have to run Javascript timer on the client that periodically calls the server. Once the call does not get logged at the expected time, it means that the user has left. Woopra does this, and it works reliably. For instance, sometimes people have a page loaded in a browser in the background for days, and there is no other way of detecting that they are still connected.

Users on laptops pulling the network cable, moving out of the coverage of a Wifi zone, etc etc there are too many scenarios where the onbeforeunload event will not reach a server anymore.

£烟消云散 2024-08-13 16:48:55

只需将 featureuselogid 放入页面的隐藏字段中,并使用唯一的 ID 使其可供 JavaScript 访问,或者设置 JavaScript 变量。

话虽如此,我相信您将能够最可靠地检测 Page_Load。您可以通过测量 Page_Load 事件之间的时间来确定页面之间的时间。您不会关闭浏览器,但在我看来,知道用户何时关闭浏览器并没有多大意义。

Just put the featureuselogid in a hidden field in the page, with a unique ID that will make it accessible to Javascript, or set a javascript variable.

Having said that, I believe that you are going to be able to most reliably detect Page_Load. You can determine the time between pages by measuring the time between Page_Load events. You won't get the browser closure, but IMO knowing when the user closes the browser is not all that meaningful.

悟红尘 2024-08-13 16:48:55

当您在 ASP.net 中呈现页面时,请包含一个 javascript 标记,该标记将变量分配给服务器端脚本的值:

<script language="javascript">
    var JS_featureuselogid = <%= featureuselogid %>;
</script>

稍后在您的 javascript 代码中,您可以引用 JS_featureuselogid 变量并获取在页面期间注入到其中的值建造。

When you render the page in ASP.net, include a javascript tag that assigns a variable to the value of a server side script:

<script language="javascript">
    var JS_featureuselogid = <%= featureuselogid %>;
</script>

Later in your javascript code, you can reference the JS_featureuselogid variable and get the value that was injected into it during page construction.

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