Skip to main content

Push API

Use the following methods to get, register, or clear the push token on the device: For details on the Web Push API please check out this page.

registerToken

Stores the push token locally and registers it with the contact profile, enabling push notifications.

EngagementCloud.push.registerToken(token)
  • token refers to the string value of the push token.

getToken

Retrieves the currently registered push token.

EngagementCloud.push.getToken().getOrNull()

clearToken

Clears the push token from local storage and removes it from the contact profile, disabling push notifications.

EngagementCloud.push.clearToken()

Understanding Token Lifecycle

StageDescription
AcquisitionPush provider issues token (FCM/HMS/APNs/Browser subscription)
RegistrationregisterToken stores the token locally and adds it to the contact profile
RotationProvider may rotate tokens periodically
ClearingclearToken removes the token from the contact profile

Following Best Practices

  • Register tokens immediately upon receipt. The SDK queues events before enable is called.
  • Implement callbacks to handle token rotations from push providers.
  • Avoid unnecessary registerToken calls. The SDK ignores unchanged tokens.
  • Call clearToken only when a user revokes push notifications consent. Otherwise, keep the token for win-back campaigns.

Handling Errors

EngagementCloud.push.registerToken(token).onFailure { e -> logger.warn("Push token failed", e) }