# 页面停留如何获取时间？

对于着陆页、在线教育、在线播放以及阅读类产品来说，页面停留时间是个很重要的指标。我们应该如何获得用户在一个页面上的停留时间呢？

一般来说我们最先想到的是用户离开页面的时刻减去用户进入页面的时刻就能得到用户在页面上的停留时间。在 Session 分析里我们就可以得到基于这个策略计算出来的平均页面停留时长指标。结合维度细分和过滤条件可以找到某一个的平均停留时长（如下图）。

![](/files/-Lvdia4XPrpxzXxGTItX)

但如果你想获得更准确的停留时长，你可能需要一些额外的代码来实现。因为虽然用户进入页面的行为我们很容易捕获，但离开页面可能有很多种形式。例如：

> APP
>
> * 屏幕锁定
> * 进入下一页/返回上一页
> * 推出APP
> * APP切到后台
>
> Web
>
> * 进入屏幕保护
> * 关闭浏览器
> * 页面不位于可见区域（浏览其它Tab、最小化）

具体的策略可以参考如下：

1. 照常获取页面进入时间
2. 当页面不可见或App切到后台时暂停计时器（结算一下）
3. 当跨天时终止计时器（结算）
4. 计时器最长不超过3小时或更符合需求的时长
5. 最终结算时进行上报

{% hint style="info" %}
以上内容没有解答我的问题？[点击我来反馈](https://support.qq.com/products/118522/) 🚀
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arkdocs.analysys.cn/integration/sdk/sdk-faq/page-duration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
