Skip to content

Users and data

Users

The SDK works without users: a device without one belongs to an anonymous recipient (see Concepts).

Kotlin
PlingBuddy.login("user-42")   // the user signed in
PlingBuddy.logout()           // the user signed out
  • login gives the anonymous recipient the external id, or, when another recipient already has it (the user signed in on another device first), moves the device to that recipient.
  • login with another user moves the device to that user's recipient, and forgets the previous user's data. Logging out moves the device to a new anonymous recipient.
  • When the app knows its user at launch, pass it to initialize(..., externalId = "user-42"), so the first request already names the user.
  • The SDK remembers the user, so initialize without an externalId keeps it.

Identity verification

If the application has identity verification turned on, give Configuration an identityTokenProvider that gets a token for the user from your own backend. The SDK asks it whenever it needs a token:

Kotlin
PlingBuddy.initialize(this, Configuration(
    applicationId = "<your application id>",
    identityTokenProvider = IdentityTokenProvider { externalId ->
        myBackend.plingBuddyToken(externalId)
    },
))
  • identityToken is a suspend function. Throw when you can't get a token right now, for example while your backend is unreachable: the SDK asks again later.
  • Return null only when there's no token for this user. After the service refused a request for identity, that stops the sync until the next login, logout or initialize.
  • You can also pass a token to login("user-42", identityToken = token).
  • Tokens are kept in memory only, so after a relaunch the SDK asks the provider again.

Recipient data, tags and device properties

Kotlin
PlingBuddy.setRecipientData(RecipientData(
    email = "[email protected]",
    country = "DK",               // ISO 3166-1 alpha-2
    language = "da",              // or a tag such as "pt-BR"
    timezone = "Europe/Copenhagen",
    metadata = mapOf("plan" to "pro"),
))
PlingBuddy.setTags(mapOf("plan" to "pro", "level" to 3, "beta" to true))
PlingBuddy.removeTags(listOf("beta"))
PlingBuddy.setDeviceProperties(mapOf("model" to Build.MODEL))
  • A text field (email, country, language, timezone) left null is unchanged, and an empty string clears it.
  • metadata, tags and device properties are merged into what the service has, so a key that's left out isn't removed; remove a tag with removeTags.
  • Data is checked when it's passed in: at most 100 tags, keys of 1 to 64 characters, text values of at most 255 characters, a valid email, a two-letter country. Invalid data is reported to the error listener and not stored.
  • initialize also takes recipientData and deviceProperties, for data the app has at launch. Of the recipient data, only fields that changed since the last launch are sent.

Notification preference

Let users choose between all notifications and only the required ones (see Concepts):

Kotlin
PlingBuddy.setNotificationPreference(NotificationPreference.REQUIRED)
  • It belongs to the user, like tags: when they're signed in on several devices, the last choice sent from any of them applies.
  • RecipientData(notificationPreference = ...) sets it too, also through initialize. But a preference passed to initialize is your choice for whoever is signed in at that launch, so it's sent again for the signed-in user at the next initialize after a login.
  • Signing in from anonymous doesn't send the device's choice, so a user who already exists keeps theirs. To apply the choice made before signing in, call setNotificationPreference again after login.
  • The SDK doesn't read the preference back from the service, so keep the value your settings screen shows yourself.

Country, language and time zone

With fetchLocaleAndTimezone = true in the configuration, the SDK reads the recipient's country, language and time zone from the device, instead of the app setting them.

  • Country: the region of the device's language and region settings, such as DK, sent as the device reports it. The service ignores a region that isn't a country, such as 419 (Latin America).
  • Language: the first language in the device's settings, or the one the user chose for this app, as a tag such as da-DK. The service keeps only the language, da, since the country covers the region.
  • Time zone: the full IANA name, such as Europe/Copenhagen, never an abbreviation like CET.
  • A field the app sets with setRecipientData is sent as given; only the others are filled in from the device. Clearing an app-set field gives it back to the device's value.
  • They're sent with every update, so a new time zone after travelling, or a changed language, reaches the service the next time the app starts.
  • Turning it off again stops sending them but doesn't clear what was sent.
  • It's off by default. Turned on, the SDK collects this data itself; see Privacy.