3

I am new to Pinpoint and trying to understand how endpoint/endpointId works in Pinpoint semantics. From the aws doc:

When a user starts a session (for example, by launching your mobile app), your mobile or web application can automatically register (or update) an endpoint with Amazon Pinpoint.

Does that mean each time of the app launching, there is a new endpoint/endpointId? Will it register a new endpoint if the current session ends or the user kill and relaunch the app?

Is there a way I can get the endpoint/endpointId in the app programmatically?

pledez
  • 339
  • 1
  • 4
  • 19

1 Answers1

4

Yes, the endpoint is the same for each unique device, email, etc. It needs to be the same so that Amazon knows where to send push notifications, for example, if you run a targeted campaign. If the user kills and relaunches the app, then the same endpoint is used. This goes for both authenticated and unauthenticated users. Thus, I would have reason to believe that if the current session ends (i.e. the user has to re-authenticate), then they have the same endpoint. This makes sense because every device (the device itself) needs a unique identifier. In order to better answer your question, I have personally tested the below and confirmed:

If one user logs out, and another logs in [on the same device], the endpoint ID remains the same. The purpose of the code below registers a user ID with a specific endpoint. You can also modify the code below to print the endpoint ID, as you requested.

At the top of your AppDelegate, put this, assuming you're using Swift and AWS Cognito for user authentication:

        var pinpoint: AWSPinpoint?

... in didFinishLaunching, put this:

        self.pinpoint = AWSPinpoint(configuration:AWSPinpointConfiguration.defaultPinpointConfiguration(launchOptions: launchOptions))
        if let targetingClient = pinpoint?.targetingClient {
                if let username = AppDelegate.defaultUserPool().currentUser()?.username {
                    let endpoint = targetingClient.currentEndpointProfile()
                    // Create a user and set its userId property
                    let user = AWSPinpointEndpointProfileUser()
                    user.userId = username
                    // Assign the user to the endpoint
                    endpoint.user = user
                    // Update the endpoint with the targeting client
                    targetingClient.update(endpoint)
                    print("Assigned user ID \(user.userId ?? "nil") to endpoint \(endpoint.endpointId).\n")
                }
            }
Joshua Wolff
  • 2,687
  • 1
  • 25
  • 42