【问题标题】:How to properly configure Amplify Analytics?如何正确配置 Amplify Analytics?
【发布时间】:2020-01-08 16:20:01
【问题描述】:

我需要一些帮助来了解如何在 Amplify 中配置 AWS Pinpoint 分析。我目前正在使用 Amplify 进行身份验证,并在我的 index.js 文件中进行了这样的配置:

export const configureAmplify = () => {
  window.LOG_LEVEL="DEBUG"
  Hub.listen('auth', data => handleAmplifyHubEvent(data))
  Hub.listen('analytics', data => handleAmplifyHubEvent(data))
  Amplify.configure({
    Auth: {
      identityPoolId: "redacted",
      region: "us-west-2",
      userPoolId: "redacted",
      userPoolWebClientId: "redacted",
      mandatorySignIn: false,
      cookieStorage: {
          domain: process.env.NODE_ENV === 'development' ? "localhost" : "redacted",
          path: '/',
          expires: 1,
          secure: false
      }
    }
  })
}

要添加 Analytics,我首先将其添加到我的 configureAmplify() 函数中:

Analytics: {
      disabled: false,
      autoSessionRecord: true,
      AWSPinpoint: {
          appId: 'redacted',
          region: 'us-east-1',
          endpointId: `wgc-default`,
          bufferSize: 1000,
          flushInterval: 5000, // 5s 
          flushSize: 100,
          resendLimit: 5
      }
  }

在用户登录或从我调用的 cookie 存储中刷新时

Analytics.updateEndpoint({
      address: user.attributes.email, // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
      attributes: {
      },
      channelType: 'EMAIL', // The channel type. Valid values: APNS, GCM
      optOut: 'ALL',
      userId: user.attributes.sub,
      userAttributes: {
      }
  })

这样做之后,在我看来,Pinpoint 控制台中的数据并不准确。例如,当前没有应用端点过滤器时显示 44 个会话。如果我通过userAttributes: userId 添加端点过滤器,那么无论我选择哪个 ID,它都会显示与该用户关联的所有 44 个会话。我怀疑这是因为EndpointID 是在启动时建立的,并且不会被updateEndpoint 调用更改。

我还尝试在最初配置 Amplify 时省略 Analytics 键,然后在用户登录后调用 Analytics.configure()。通过这种方法,我可以构造一个特定于用户的 endpointId。但是,我认为这样做意味着我不会捕获任何身份验证事件(登录、注册、身份验证失败),因为直到它们发生之后才会配置分析。

所以我的问题是配置 Amplify Analytics 的正确时机是什么?如何准确捕获会话、身份验证和自定义事件,并通过用户 ID 唯一标识它们?

【问题讨论】:

    标签: aws-amplify aws-pinpoint


    【解决方案1】:

    没有必要分配自定义端点 ID,放大会自动处理它,并且每个设备都会跟踪所有事件。相反,如果您确实需要它,请在登录后使用 userId 更新端点。

    添加 userId 的好处是用户的所有 endpointId 都会自动关联到该 userId,因此当您更新用户的属性时,它将跨端点同步。

    当您使用 Cognito 时,Amazon Cognito 可以自动将用户 ID 和属性添加到您的终端节点。对于终端节点用户 ID 值,Amazon Cognito 分配分配给用户池中用户的子值。要了解如何使用 Amazon Cognito 添加用户,请参阅 Amazon Cognito 开发人员指南中的Using Amazon Pinpoint Analytics with Amazon Cognito User Pools。

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 2023-03-22
      • 2020-12-15
      • 2020-12-16
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 2023-03-23
      • 2017-05-18
      相关资源
      最近更新 更多