Users and data¶
Users¶
The SDK works without users: a device without one belongs to an anonymous recipient.
Dart
await plingBuddy.login('user-42'); // the user signed in
await plingBuddy.logout(); // the user signed out
logingives 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.loginwith 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, so the previous user no longer receives its notifications.- 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
initializewithout anexternalIdkeeps 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, and waits at most 10 seconds for the answer:
Dart
await plingBuddy.initialize(Configuration(
applicationId: '<your application id>',
identityTokenProvider: (externalId) => myBackend.plingBuddyToken(externalId),
));
- Throw when you can't get a token right now, for example when your backend answers a 5xx, the network fails or the request times out: the SDK asks again later, and reports
identity_setup_errorto the error listener. - 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,logoutorinitialize. - 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.
- After
dispose(), the provider isn't asked until the next call; see Cleaning up. - Without identity verification, a signed-in user can't be deleted from the app; see Deleting the user.
Recipient data, tags and device properties¶
Dart
await plingBuddy.setRecipientData(const RecipientData(
email: '[email protected]',
country: 'DK', // ISO 3166-1 alpha-2
language: 'da', // or a tag such as 'pt-BR'
timezone: 'Europe/Copenhagen',
metadata: {'plan': 'pro'},
));
await plingBuddy.setTags({'plan': 'pro', 'level': 3, 'beta': true});
await plingBuddy.removeTags(['beta']);
await plingBuddy.setDeviceProperties({'model': 'Pixel 9'});
- A text field (
email,country,language,timezone) left null is unchanged, and''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 withremoveTags.- 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 and not stored.
initializealso takesrecipientDataanddeviceProperties, for data the app has at launch. Of the recipient data, only fields that changed since the last launch are sent.
Notification preference¶
Users can choose in your app whether they want all notifications or only the required ones (receipts, security alerts and the like). Campaigns are marked required or promotional in the dashboard, and a promotional campaign leaves out every user who chose required only.
Dart
await 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. A user the service was never told about gets all notifications.
RecipientData(notificationPreference: ...)sets it too, also throughinitialize. But a preference passed toinitializeis your choice for whoever is signed in at that launch, so it's sent again for the signed-in user at the nextinitializeafter 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
setNotificationPreferenceagain afterlogin. - 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, the SDK reads the recipient's country, language and time zone from the device, instead of the app setting them:
Dart
await plingBuddy.initialize(const Configuration(
applicationId: '<your application id>',
fetchLocaleAndTimezone: true,
));
- 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 as419(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 likeCET. - A field the app sets with
setRecipientDatais 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.