将 Amazon Pinpoint 分析与 Amazon Cognito 用户池结合使用 - Amazon Cognito
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

将 Amazon Pinpoint 分析与 Amazon Cognito 用户池结合使用

Amazon Pinpoint 用户群体与 Amazon Pinpoint 集成,为 Amazon Cognito 用户群体提供分析并丰富 Amazon Pinpoint 活动的用户数据。Amazon Pinpoint 提供分析和有针对性的市场活动,以使用推送通知推动用户与移动应用程序的交互。通过 Amazon Cognito 用户池中的 Amazon Pinpoint 分析支持,您可以在 Amazon Pinpoint 控制台中跟踪用户池注册、登录、失败的身份验证、日活跃用户(DAU)和月活跃用户(MAU)。您可以深入查看不同日期范围或属性的数据,例如设备平台、设备区域设置和应用程序版本。

您还可以为应用程序设置自定义属性。然后可以使用这些属性在 Amazon Pinpoint 上对用户进行细分,并向他们发送有针对性的推送通知。如果您在 Amazon Cognito 控制台的 Analytics(分析)选项卡中选择 Share user attribute data with Amazon Pinpoint(与 Amazon Pinpoint 分享用户属性数据),Amazon Pinpoint 将会为用户电子邮件地址和电话号码创建其他端点。

当您使用 Amazon Cognito 控制台在用户群体中激活 Amazon Pinpoint 分析时,您还会创建一个服务相关角色,Amazon Cognito 在向 Amazon Pinpoint 发出针对用户群体的 API 请求时代入该角色。添加分析配置的 IAM 主体必须具有 CreateServiceLinkedRole 权限。该服务相关角色为 AWSServiceRoleForAmazonCognitoIdp。有关更多信息,请参阅对 Amazon Cognito 使用服务相关角色

当您在 Amazon Cognito API 中向应用程序客户端应用 AnalyticsConfiguration 时,您可以为 Amazon Pinpoint 分配自定义 IAM 角色和外部 ID 来代入该角色。此角色必须信任 cognito-idp 服务主体,如果角色信任策略需要外部 ID,则它必须与您的 AnalyticsConfiguration 相匹配。您必须针对 Amazon Pinpoint 项目向该角色授予 cognito-idp:Describe* 权限和以下权限。

  • mobiletargeting:UpdateEndpoint

  • mobiletargeting:PutEvents

Amazon Cognito 和 Amazon Pinpoint 区域可用性

下表显示了符合以下条件之一的 Amazon Cognito 与 Amazon Pinpoint 之间的 Amazon Web Services 区域 映射。

  • 您只能在美国东部(弗吉尼亚州北部)(us-east-1)区域使用 Amazon Pinpoint 项目。

  • 您可以在相同的区域或者在美国东部(弗吉尼亚州北部)(us-east-1)区域使用 Amazon Pinpoint 项目

默认情况下,Amazon Cognito 只能向位于相同 Amazon Web Services 区域 中的 Amazon Pinpoint 项目发送分析。此规则的例外情况是下表中的区域,以及 Amazon Pinpoint 不可用的区域。

Amazon Pinpoint 未在以下区域推出。这些地区的 Amazon Cognito 用户群体不支持分析。

  • Europe (Milan)

  • 中东(巴林)

  • 亚太地区(大阪)

  • 以色列(特拉维夫)

  • 非洲(开普敦)

  • 亚太地区(雅加达)

表中显示了您构建 Amazon Cognito 用户群体的区域与 Amazon Pinpoint 中对应区域的关系。您必须在可用区域中配置 Amazon Pinpoint 项目,才能将其与 Amazon Cognito 集成。

Amazon Cognito 用户群体区域 Amazon Pinpoint 项目所在区域

ap-northeast-1

us-east-1

ap-northeast-2

us-east-1

ap-south-1

us-east-1、ap-sou1

ap-southeast-1

us-east-1

ap-southeast-2

us-east-1、ap-southeast-2

ca-central-1

us-east-1

eu-central-1

us-east-1、eu-central-1

eu-west-1

us-east-1、eu-west-1

eu-west-2

us-east-1

us-east-1

us-east-1

us-east-2

us-east-1

us-west-2

us-east-1、us-west-2

区域映射示例

  • 如果您在 ap-northest-1 中创建用户群体,则可以在 us-east-1 中创建您的 Amazon Pinpoint 项目。

  • 如果您在 ap-south-1 中创建用户群体,则可以在 us-east-1 或 ap-south-1 中创建您的 Amazon Pinpoint 项目。

注意

对于上表以外的所有 Amazon Web Services 区域,Amazon Cognito 只能使用与您的用户群体位于同一区域的 Amazon Pinpoint 项目。如果 Amazon Pinpoint 在您构建用户群体的区域中不可用且未在表中列出,那么 Amazon Cognito 在该区域不支持 Amazon Pinpoint 分析。有关详细的 Amazon Web Services 区域 信息,请参阅 Amazon Pinpoint 端点和配额

指定 Amazon Pinpoint 分析设置(Amazon Web Services Management Console)

您可以配置 Amazon Cognito 用户群体以向 Amazon Pinpoint 发送分析数据。Amazon Cognito 仅为本地用户将分析数据发送到 Amazon Pinpoint。将您的用户群体配置为与 Amazon Pinpoint 项目关联后,您必须在 API 请求中包含 AnalyticsMetadata。有关更多信息,请参阅将您的应用程序与 Amazon Pinpoint 集成

指定分析设置
  1. 转到 Amazon Cognito 控制台。系统可能会提示您输入 Amazon 凭证。

  2. 选择 User Pools(用户群体)并从列表中选择一个现有的用户群体。

  3. 选择 App integration(应用程序集成)选项卡。

  4. App clients and analytics(应用程序客户端和分析)下,从列表中选择现有的 App client name(应用程序客户端名称)。

  5. Pinpoint analytics(Pinpoint 分析)下,选择 Enable(启用)。

  6. 选择 Pinpoint Region(Pinpoint 区域)。

  7. 选择 Amazon Pinpoint project(Amazon Pinpoint 项目)或者选择 Create Amazon Pinpoint project(创建 Amazon Pinpoint 项目)。

    注意

    Amazon Pinpoint 项目 ID 是 Amazon Pinpoint 项目特有的由 32 个字符组成的字符串。它在 Amazon Pinpoint 控制台中列出。

    您可以将多个 Amazon Cognito 应用程序映射到单个 Amazon Pinpoint 项目。但是,每个 Amazon Cognito 应用程序只能映射到一个 Amazon Pinpoint 项目。

    在 Amazon Pinpoint 中,每个项目都应该是单个应用程序。例如,如果游戏开发员有两款游戏,每款游戏应该是单独的 Amazon Pinpoint 项目,即使这两款游戏使用同一 Amazon Cognito 用户池。有关 Amazon Pinpoint 项目的更多信息,请参阅在 Amazon Pinpoint 中创建项目

  8. User data sharing(用户数据共享)下,如果您希望 Amazon Cognito 发送电子邮件地址和电话号码到 Amazon Pinpoint 并为用户创建额外的端点,则选择 Share user data with Amazon Pinpoint(与 Amazon Pinpoint 共享用户数据)。用户验证其电子邮件地址和电话号码后,Amazon Cognito 只在它们可用于用户账户时才会与 Amazon Pinpoint 共享。

    注意

    端点唯一地标识可以使用 Amazon Pinpoint 向其发送推送通知的用户设备。有关端点的更多信息,请参阅《Amazon Pinpoint 开发人员指南》中的添加端点

  9. 选择保存更改

指定 Amazon Pinpoint 分析设置(Amazon CLI 和 Amazon API)

使用以下命令为您的用户池指定 Amazon Pinpoint 分析设置。

在创建应用程序时为用户池的现有客户端应用程序指定分析设置
为用户池的现有客户端应用程序更新分析设置
注意

在您使用ApplicationArn时,Amazon Cognito 支持区域内集成

将您的应用程序与 Amazon Pinpoint 集成

您可以在用户群体 API 中针对 Amazon Cognito 本地用户将分析元数据发布到 Amazon Pinpoint。

本地用户

注册了账户或在您的用户群体中创建的用户,而不是通过第三方身份提供者 (IdP) 登录的用户。

用户群体 API

您可以使用具有自定义用户界面 (UI) 的应用程序,将其与 Amazon SDK 集成的操作。您无法为通过托管 UI 登录的联合身份用户或本地用户传递分析元数据。有关用户群体 API 操作的列表,请参阅 Amazon Cognito API 参考

在您将用户群体配置为发布到活动后,Amazon Cognito 会将以下 API 操作的元数据传递给 Amazon Pinpoint。

  • AdminInitiateAuth

  • AdminRespondToAuthChallenge

  • ConfirmForgotPassword

  • ConfirmSignUp

  • ForgotPassword

  • InitiateAuth

  • ResendConfirmationCode

  • RespondToAuthChallenge

  • SignUp

要将有关用户会话的元数据传递到 Amazon Pinpoint 活动,请在 API 请求的 AnalyticsMetadata 参数中包含 AnalyticsEndpointId 值。有关 JavaScript 示例,请参阅 Amazon 知识中心 中的为什么 Amazon Cognito 用户群体分析未显示在 Amazon Pinpoint 控制面板上?

配置用户池分析

使用 Amazon Pinpoint 分析,您可以跟踪 Amazon Cognito 用户池的注册、登录、失败的身份验证、日活跃用户(DAU)和月活跃用户(MAU)。您还可以使用 Amazon Mobile SDK for Android 或 Amazon Mobile SDK for iOS 设置特定于您的应用程序的用户属性。然后可以使用这些属性在 Amazon Pinpoint 中对用户进行细分,并向他们发送有针对性的推送通知。

应用程序集成选项卡的应用程序客户端和分析下,您可以导航到现有应用程序客户端或创建新的应用程序客户端。在应用程序客户端的配置中,您可以指定要与应用程序结合使用的 Amazon Pinpoint 项目。有关更多信息,请参阅将 Amazon Pinpoint 分析与 Amazon Cognito 用户池结合使用

注意

Amazon Pinpoint 在北美、欧洲、亚洲和大洋洲的多个Amazon区域中均已推出。Amazon Pinpoint 区域包括 Amazon Pinpoint API。如果 Amazon Cognito 支持 Amazon Pinpoint 区域,Amazon Cognito 会将事件发送到同一 Amazon Pinpoint 区域中的 Amazon Pinpoint 项目。如果区域受 Amazon Pinpoint 支持,Amazon Cognito 将支持在 us-east-1 中发送事件。有关 Amazon Pinpoint 区域的详细信息,请参阅 Amazon Pinpoint 端点和配额将 Amazon Pinpoint 分析与 Amazon Cognito 用户池结合使用

添加分析和市场活动
  1. 选择添加分析和活动

  2. 从列表中选择 Cognito app client (Cognito 应用程序客户端)

  3. 要将 Amazon Cognito 应用程序映射到 Amazon Pinpoint 项目,请从列表中选择该 Amazon Pinpoint 项目。

    注意

    Amazon Pinpoint 项目 ID 是 Amazon Pinpoint 项目特有的由 32 个字符组成的字符串。它在 Amazon Pinpoint 控制台中列出。

    您可以将多个 Amazon Cognito 应用程序映射到单个 Amazon Pinpoint 项目。但是,每个 Amazon Cognito 应用程序只能映射到一个 Amazon Pinpoint 项目。

    在 Amazon Pinpoint 中,每个项目都应该是单个应用程序。例如,如果游戏开发员有两款游戏,每款游戏应该是单独的 Amazon Pinpoint 项目,即使这两款游戏使用同一 Amazon Cognito 用户池。

  4. 如果您希望 Amazon Cognito 向 Amazon Pinpoint 发送电子邮件地址和电话号码,以便为用户创建额外的端点,请选择 Share user attribute data with Amazon Pinpoint (与 Amazon Pinpoint 共享用户属性数据)

    注意

    端点唯一地标识可以使用 Amazon Pinpoint 向其发送推送通知的用户设备。有关端点的更多信息,请参阅《Amazon Pinpoint 开发人员指南》中的 Adding endpoints to Amazon Pinpoint(向 Amazon Pinpoint 添加端点)。

  5. 输入您已经创建的 IAM 角色,或者选择 Create new role (创建新角色) 以在 IAM 控制台中创建一个新角色。

  6. 选择保存更改

  7. 要指定额外的应用程序映射,请选择添加应用程序映射

  8. 选择 Save changes(保存更改)。