0

I need some help understanding how to configure AWS Pinpoint analytics in Amplify. I'm currently using Amplify for Auth and have it configured like this in my index.js file:

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
      }
    }
  })
}

To add Analytics, I started by adding this to my configureAmplify() function:

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

Upon user sign-in or refresh from cookie storage I called

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: {
      }
  })

After doing this, it seems to me that the data in the Pinpoint console is not accurate. For example, there are currently 44 sessions displayed when no endpoint filter is applied. If I add an endpoint filter by userAttributes: userId then no matter which ID I select, it shows all 44 sessions associated with that user. I suspect that is because the EndpointID is established at startup, and is not changed by the updateEndpoint call.

I have also tried omitting the Analytics key when I initially configure Amplify, and then calling Analytics.configure() after the user is signed in. With this approach, I can construct a user-specific endpointId. However, I think that doing it this way will mean that I don't capture any of the Authentication events (sign-in, sign-up, auth failure), because Analytics is not configured until after they occur.

So my question is what is the proper timing for configuring Amplify Analytics? How can I accurately capture session, auth and custom events, AND uniquely identify them by user id?

genestd
  • 384
  • 3
  • 16

1 Answers1

0

It's not necessary to assign a custom endpoint id, amplify will handle it automatically and all events will be tracked per device. Instead, if you really need it, update the endpoint with the userId after sign-in.

The advantage of adding the userId is that all the endpointIds of a user are automatically associated to that userId, thus when you update a user's attribute, it will be synchronized across the endpoints.

As you are using Cognito, Amazon Cognito can add user IDs and attributes to your endpoints automatically. For the endpoint user ID value, Amazon Cognito assigns the sub value that's assigned to the user in the user pool. To learn about adding users with Amazon Cognito, see Using Amazon Pinpoint Analytics with Amazon Cognito User Pools in the Amazon Cognito Developer Guide.

A.Infante
  • 423
  • 4
  • 4