Working with Users#
Storyteller personalises content, tracking, and follow state per end user. The Flutter SDK mirrors the native capabilities exposed by the iOS and Android libraries.
Associate a user during initialisation#
Provide an externalId when calling Storyteller.initialize. This identifier usually maps to your own user record.
final result = await Storyteller.initialize(
'YOUR_API_KEY',
externalId: currentUser.id,
eventTrackingOptions: EventTrackingOptions(
enablePersonalization: true,
enableAdTracking: false,
),
);
EventTrackingOptions lets you toggle individual tracking features (for example, to meet privacy requirements) without changing your server configuration.
Update custom attributes#
Use key/value attributes to pass additional segmentation information into Storyteller. Attributes are persisted natively and automatically applied to subsequent sessions.
await Storyteller.setCustomAttribute('subscription-tier', 'gold');
await Storyteller.setCustomAttribute('favorite-team', 'city-fc');
final attributes = await Storyteller.customAttributes();
debugPrint('Current attributes: $attributes');
await Storyteller.removeCustomAttribute('favorite-team');
Handle locale changes#
If your app allows users to switch language independently from the device, inform Storyteller by overriding the locale:
await Storyteller.setLocale('fr-FR');
Follow categories explicitly#
Manipulate follow state in response to profile changes, onboarding, or saved preferences:
await Storyteller.addFollowedCategories(['travel', 'music']);
final isSportsFollowed = await Storyteller.isCategoryFollowed('sports');
if (!isSportsFollowed) {
await Storyteller.addFollowedCategory('sports');
}
await Storyteller.removeFollowedCategory('travel');
final followed = await Storyteller.followedCategories();