您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure Application Insights 为 Web 应用程序进行用户留存情况分析User retention analysis for web applications with Application Insights

Azure Application Insights 中的“留存情况”功能可以帮助分析有多少用户回归到应用,以及他们以何频率执行特定的任务或达成目标。The retention feature in Azure Application Insights helps you analyze how many users return to your app, and how often they perform particular tasks or achieve goals. 例如,如果运行游戏网站,则可以会在输掉游戏后回归到网站的用户数与在获胜后回归的用户数进行比较。For example, if you run a game site, you could compare the numbers of users who return to the site after losing a game with the number who return after winning. 此信息有助于改进用户体验和业务策略。This knowledge can help you improve both your user experience and your business strategy.

开始体验Get started

如果在 Application Insights 门户的“留存情况”工具中没有看到数据,请了解如何开始使用“使用情况”工具If you don't yet see data in the retention tool in the Application Insights portal, learn how to get started with the usage tools.

留存情况工具The Retention tool


  1. 工具栏便于用户创建新的留存情况报表、打开现有留存情况报表、保存当前留存情况报表或将其另存为其他形式、还原已保存报表的更改、刷新报表数据、通过电子邮件或直接链接共享报表以及访问文档页。The toolbar allows users to create new retention reports, open existing retention reports, save current retention report or save as, revert changes made to saved reports, refresh data on the report, share report via email or direct link, and access the documentation page.
  2. 默认情况下,留存情况显示执行了任意操作,然后在一段时间后返回并执行其他任意操作的所有用户。By default, retention shows all users who did anything then came back and did anything else over a period. 可以选择事件的不同组合,将关注范围缩小为仅关注特定用户活动。You can select different combination of events to narrow the focus on specific user activities.
  3. 添加一个或多个基于属性的筛选器。Add one or more filters on properties. 例如,可以关注特定国家或地区中的用户。For example, you can focus on users in a particular country or region. 在设置筛选器后单击“更新”。Click Update after setting the filters.
  4. 整体留存情况图表显示选定时间段内用户留存情况的摘要。The overall retention chart shows a summary of user retention across the selected time period.
  5. 网格根据 2 号图标处的查询生成器显示保留的用户数。The grid shows the number of users retained according to the query builder in #2. 每行都表示在所显示的时间段内执行了任意事件的一群用户。Each row represents a cohort of users who performed any event in the time period shown. 行中的每个单元格显示了该用户群中有多少人在之后的某个时间段内至少回归了一次。Each cell in the row shows how many of that cohort returned at least once in a later period. 某些用户可能在多个时间段内都回归过。Some users may return in more than one period.
  6. 见解卡中显示了排名前 5 的启动事件和排名前 5 的返回事件,帮助用户更好地了解留存情况报表。The insights cards show top five initiating events, and top five returned events to give users a better understanding of their retention report.


用户可将鼠标悬停在留存情况工具的单元格上,以访问分析按钮和解释单元格含义的工具提示。Users can hover over cells on the retention tool to access the analytics button and tool tips explaining what the cell means. “分析”按钮可让用户使用预填充的查询来生成“分析”工具,以便从单元格生成用户。The Analytics button takes users to the Analytics tool with a pre-populated query to generate users from the cell.

使用业务事件跟踪留存情况Use business events to track retention

若要获得最有用的留存情况分析,请对表示重要业务活动的事件进行度量。To get the most useful retention analysis, measure events that represent significant business activities.

例如,许多用户可能会打开应用中的页面,但是却不玩页面中显示的游戏。For example, many users might open a page in your app without playing the game that it displays. 因此,仅仅跟踪页面查看数将无法准确估计有多少人在玩过该游戏后又回来玩该游戏。Tracking just the page views would therefore provide an inaccurate estimate of how many people return to play the game after enjoying it previously. 为了清晰了解回归玩家,应用应当在用户实际玩游戏时发送一个自定义事件。To get a clear picture of returning players, your app should send a custom event when a user actually plays.

一种较好的做法是编写表示关键业务操作的自定义事件,并使用这些事件进行留存情况分析。It's good practice to code custom events that represent key business actions, and use these for your retention analysis. 要捕获游戏结果,需要编写一行代码来向 Application Insights 发送一个自定义事件。To capture the game outcome, you need to write a line of code to send a custom event to Application Insights. 如果采用网页代码或 Node.JS 编写该事件,则它类似于以下内容:If you write it in the web page code or in Node.JS, it looks like this:

    appinsights.trackEvent("won game");

如果采用 ASP.NET 服务器代码,则如下所示:Or in ASP.NET server code:

   telemetry.TrackEvent("won game");

详细了解如何编写自定义事件Learn more about writing custom events.

后续步骤Next steps