开始使用 App Center 和 Application Insights 分析移动应用Start analyzing your mobile app with App Center and Application Insights

本快速入门将指导你完成将应用的 App Center 实例连接到 Application Insights 的整个过程。This quickstart guides you through connecting your app's App Center instance to Application Insights. 与 App Center 的分析服务提供的工具相比,Application Insights 的功能更为强大,可让你对遥测数据进行更准确的查询、分段、筛选和分析。With Application Insights, you can query, segment, filter, and analyze your telemetry with more powerful tools than are available from the Analytics service of App Center.

先决条件Prerequisites

若要完成本快速入门,你需要:To complete this quickstart, you need:

  • Azure 订阅。An Azure subscription.
  • iOS、Android、Xamarin、通用 Windows 或 React 本机应用。An iOS, Android, Xamarin, Universal Windows, or React Native app.

如果没有 Azure 订阅,请在开始之前创建一个免费帐户。If you don't have an Azure subscription, create a free account before you begin.

使用 App Center 注册Sign up with App Center

首先,创建一个帐户并使用 App Center 注册To begin, create an account and sign up with App Center.

载入到 App CenterOnboard to App Center

在将 Application Insights 用于移动应用之前,需要将应用载入 App CenterBefore you can use Application Insights with your mobile app, you need to onboard your app to App Center. Application Insights 不直接从移动应用接收遥测。Application Insights does not receive telemetry from your mobile app directly. 而是,应用会将自定义事件遥测发送到 App Center。Instead, your app sends custom event telemetry to App Center. 然后,App Center 会在收到事件时,将这些自定义事件的副本连续导出到 Application Insights。Then, App Center continuously exports copies of these custom events into Application Insights as the events are received. (这不适用于 Application Insights JS SDKReact Native 插件,其中遥测直接发送到 Application Insights。)(This does not apply to the Application Insights JS SDK or the React Native plugin where telemetry is sent directly to Application Insights.)

若要载入应用,请按照应用支持的每个平台的 App Center 快速入门进行操作。To onboard your app, follow the App Center quickstart for each platform your app supports. 为每个平台创建单独的 App Center 实例:Create separate App Center instances for each platform:

跟踪应用中的事件Track events in your app

在将应用载入到 App Center 后,需要对其进行修改,以使用 App Center SDK 发送自定义事件遥测。After your app is onboarded to App Center, it needs to be modified to send custom event telemetry using the App Center SDK. 自定义事件是导出到 Application Insights 的唯一一种 App Center 遥测。Custom events are the only type of App Center telemetry that is exported to Application Insights.

若要从 iOS 应用发送自定义事件,请在 App Center SDK 中使用 trackEventtrackEvent:withProperties 方法。To send custom events from iOS apps, use the trackEvent or trackEvent:withProperties methods in the App Center SDK. 了解有关从 iOS 应用跟踪事件的详细信息。Learn more about tracking events from iOS apps.

MSAnalytics.trackEvent("Video clicked")

若要从 Android 应用发送自定义事件,请在 App Center SDK 中使用 trackEvent 方法。To send custom events from Android apps, use the trackEvent method in the App Center SDK. 了解有关从 Android 应用跟踪事件的详细信息。Learn more about tracking events from Android apps.

Analytics.trackEvent("Video clicked")

若要从其他应用平台发送自定义事件,请在其 App Center SDK 中使用 trackEvent 方法。To send custom events from other app platforms, use the trackEvent methods in their App Center SDKs.

若要确保收到自定义事件,请转到 App Center“分析”部分下的“事件”选项卡。To make sure your custom events are being received, go to the Events tab under the Analytics section in App Center. 从应用发送事件后,可能需要等待几分钟才会显示事件。It can take a couple minutes for events to show up from when they're sent from your app.

创建 Application Insights 资源Create an Application Insights resource

在应用发送自定义事件,并且 App Center 收到这些事件后,需要在 Azure 门户中创建 App Center 类型的 Application Insights 资源:Once your app is sending custom events and these events are being received by App Center, you need to create an App Center-type Application Insights resource in the Azure portal:

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 选择“创建资源” > “开发人员工具” > “Application Insights”。Select Create a resource > Developer tools > Application Insights.

    备注

    如果这是你首次创建 Application Insights 资源,可以通过访问创建 Application Insights 资源文档来了解更多信息。If this is your first time creating an Application Insights resource you can learn more by visiting the Create an Application Insights Resource doc.

    随后会显示一个配置对话框。A configuration box will appear. 请使用下表填写输入字段。Use the table below to fill out the input fields.

    设置Settings Value 说明Description
    名称Name 某些全局唯一值,如“myApp-iOS”Some globally unique value, like "myApp-iOS" 标识所监视的应用的名称Name that identifies the app you are monitoring
    资源组Resource Group 一个新资源组或菜单中的一个现有资源组A new resource group, or an existing one from the menu 在其中创建新 Application Insights 资源的资源组The resource group in which to create the new Application Insights resource
    位置Location 菜单中的某个位置A location from the menu 选择离你近的位置或离托管应用的位置近的位置Choose a location near you, or near where your app is hosted
  3. 单击“创建”。Click Create.

如果应用支持多个平台(iOS、Android 等),则最好创建单独的 Application Insights 资源,每个平台使用一个资源。If your app supports multiple platforms (iOS, Android, etc.), it's best to create separate Application Insights resources, one for each platform.

导出到 Application InsightsExport to Application Insights

在“概述”页面上的新 Application Insights 资源中。In your new Application Insights resource on the Overview page. 从资源中复制检测密钥。Copy the instrumentation key from your resource.

在应用的 App Center 实例中,执行以下操作:In the App Center instance for your app:

  1. 在“设置”页上,单击“导出”。On the Settings page, click Export.
  2. 选择“新建导出”,选择“Application Insights”,然后单击“自定义”。Choose New Export, pick Application Insights, then click Customize.
  3. 将 Application Insights 检测密钥粘贴到此框中。Paste your Application Insights instrumentation key into the box.
  4. 同意增加包含 Application Insights 资源的 Azure 订阅的使用量。Consent to increasing the usage of the Azure subscription containing your Application Insights resource. 每个 Application Insights 资源对每月收到的前 1GB 数据是免费的。Each Application Insights resource is free for the first 1 GB of data received per month. 了解有关 Application Insights 定价的详细信息。Learn more about Application Insights pricing.

请务必为应用支持的每个平台重复此过程。Remember to repeat this process for each platform your app supports.

在设置导出后,会将 App Center 收到的每个自定义事件复制到 Application Insights 中。Once export is set up, each custom event received by App Center is copied into Application Insights. 可能需要几分钟的时间才能将事件复制到 Application Insights 中,因此,如果事件未立即显示,请等待一段时间,然后再做进一步的诊断。It can take several minutes for events to reach Application Insights, so if they don't show up immediately, wait a bit before diagnosing further.

为了在首次连接时提供更多的数据,会将 App Center 中最近 48 小时的自定义事件自动导出到 Application Insights。To give you more data when you first connect, the most recent 48 hours of custom events in App Center are automatically exported to Application Insights.

开始监视应用Start monitoring your app

Application Insights 可以查询、分段、筛选和分析来自应用的自定义事件遥测,相比 App Center 提供的分析工具,其功能更为强大。Application Insights can query, segment, filter, and analyze the custom event telemetry from your apps, beyond the analytics tools App Center provides.

  1. 查询自定义事件遥测。Query your custom event telemetry. 在 Application Insights“概述”页上,选择“日志(分析)”。From the Application Insights Overview page, choose Logs (Analytics).

    将打开与 Application Insights 资源关联的 Application Insights 日志(分析)门户。The Application Insights Logs (Analytics) portal associated with your Application Insights resource will open. 通过日志(分析)门户,可以直接使用 Log Analytics 查询语言来查询数据,因此,可以询问有关应用及其用户的任意复杂的问题。The Logs (Analytics) portal lets you directly query your data using the Log Analytics query language, so you can ask arbitrarily complex questions about your app and its users.

    在日志(分析)门户中打开一个新选项卡,然后粘贴以下查询。Open a new tab in the Logs (Analytics) portal, then paste in the following query. 它将返回在过去24小时内从应用发送每个自定义事件的用户数,这些数量按照非重复计数排序。It returns a count of how many distinct users have sent each custom event from your app in the last 24 hours, sorted by these distinct counts.

    customEvents
    | where timestamp >= ago(24h)
    | summarize dcount(user_Id) by name 
    | order by dcount_user_Id desc 
    

    日志(分析)门户

    1. 通过单击文本编辑器中查询的任意位置,选择此查询。Select the query by clicking anywhere on the query in the text editor.
    2. 然后,单击“运行”运行查询。Then click Go to run the query.

    详细了解有关 Application Insights 分析Log Analytics 查询语言的信息。Learn more about Application Insights Analytics and the Log Analytics query language.

  2. 分段和筛选自定义事件遥测。Segment and filter your custom event telemetry. 从 Application Insights“概述”页面上,选择目录中的“用户”。From the Application Insights Overview page, choose Users in the table of contents.

    用户工具图标

    用户工具可显示你的应用中有多少用户点击了某些按钮、访问了某些屏幕或使用 App Center SDK 执行了作为事件进行跟踪的任何其他操作。The Users tool shows how many users of your app clicked certain buttons, visited certain screens, or performed any other action that you are tracking as an event with the App Center SDK. 如果你一直在寻找对 App Center 事件进行分段和筛选的方法,那么用户工具会是一个不错的选择。If you've been looking for a way to segment and filter your App Center events, the Users tool is a great choice.

    用户工具

    例如,通过选择“拆分依据”下拉菜单中的“国家或地区”,来根据地域对使用量进行分段。For example, segment your usage by geography by choosing Country or region in the Split by dropdown menu.

  3. 分析应用中的转换、保留和导航模式。Analyze conversion, retention, and navigation patterns in your app. 从 Application Insights“概述”页面上,选择目录中的“用户流”。From the Application Insights Overview page, choose User Flows in the table of contents.

    用户流工具

    用户流工具直观显示用户在某些起始事件之后发送的事件。The User Flows tool visualizes which events users send after some starting event. 它可用于获取用户浏览应用的整体情况。It's useful for getting an overall picture of how users navigate through your app. 它可以显示许多用户改动应用的地方,或反复执行相同操作的地方。It can also reveal places where many users are churning from your app, or repeating the same actions over and over.

    除了用户流,Application Insights 还提供几种其他用户行为分析工具来回答特定的问题:In addition to User Flows, Application Insights has several other user behavior analytics tools to answer specific questions:

    • 漏斗图,用于分析和监视转换率。Funnels for analyzing and monitoring conversion rates.
    • 保留,用于分析随着时间的推移应用保留用户的情况。Retention for analyzing how well your app retains users over time.
    • 工作簿,用于将可视化效果和文本组合到可共享的报表中。Workbooks for combining visualizations and text into a shareable report.
    • 队列,用于命名和保存特定用户或事件组,以便可以轻松地通过其他分析工具引用它们。Cohorts for naming and saving specific groups of users or events so they can be easily referenced from other analytics tools.

清理资源Clean up resources

如果不希望继续将 Application Insights 和 App Center 一起使用,请关闭 App Center 中的导出并删除 Application Insights 资源。If you do not want to continue using Application Insights with App Center, turn off export in App Center and delete the Application Insights resource. 这将防止 Application Insights 进一步收取此资源的费用。This will prevent you from being charged further by Application Insights for this resource.

要关闭 App Center 中的导出,请执行以下操作:To turn off export in App Center:

  1. 在 App Center 中,转到“设置”,然后选择“导出”。In App Center, go to Settings and choose Export.
  2. 单击想要删除的 Application Insights 导出,然后单击底部的“删除导出”并确认。Click the Application Insights export you want to delete, then click Delete export at the bottom and confirm.

要删除 Application Insights 资源,请执行以下操作:To delete the Application Insights resource:

  1. 在 Azure 门户的左侧菜单中,单击“资源组”,然后选择在其中创建 Application Insights 资源的资源组。In the left-hand menu of the Azure portal, click Resource groups and then choose the resource group in which your Application Insights resource was created.
  2. 打开要删除的 Application Insights 资源。Open the Application Insights resource you want to delete. 然后在该资源的顶部菜单中单击“删除”并确认。Then click Delete in the top menu of the resource and confirm. 这将永久删除导出到 Application Insights 的数据的副本。This will permanently delete the copy of the data that was exported to Application Insights.

后续步骤Next steps