User IDs can be used for reporting purposes, storing the read status of Clips and Stories, followed categories, user preferences and other features. When externalId is omitted or null, the SDK manages a guest identity. With default tracking options, the native SDK persists that guest identity and reuses it on later anonymous initialization. Passing a signed-in user ID selects that user; passing null again returns to the SDK-managed guest identity. Persistence and remote read-state behavior depend on your tracking options.
However, if you have a user account system then you may wish to set your own user IDs within the Storyteller SDK.
The externalId should be an identifier that is unique per user and does not change. Therefore, using something like the user's email address is not a good choice for an externalId, as the user may change it at some point in the future. However, using a unique UUID/GUID would be a good choice as it is guaranteed not to change over time.
In order to supply the externalId to the Storyteller SDK, call the initialize method. This method is Promise-based and will throw an error if initialization fails.
externalId (optional): Your unique user identifier. If null or omitted, the SDK will use a default autogenerated externalId
Important Notes:
When calling StorytellerSdk.initialize with a different externalId than the previous one, per-user local state is reset (including read markers, likes, follow state and custom attributes under the default tracking configuration)
Call StorytellerSdk.initialize as soon as the externalId is known in your app
Never make simultaneous StorytellerSdk.initialize calls - this will result in unexpected behavior. Always await the completion of one initialization before calling it again
Await the Promise for each initialization attempt. isInitialized() is a status snapshot and is not a completion signal for a subsequent user switch.
Apply the new user’s custom attributes, locale and app-managed follows after reinitialization and before reloading or remounting content.
Use a supported ISO language code such as fr, rather than a regional tag such as fr-FR. iOS validates against its ISO language-code list and ignores unsupported values. Both platforms accept null or omission to clear the preference:
// ISO 639-1 (two-letter code)StorytellerSdk.setLocale('fr');// Clear locale preferenceStorytellerSdk.setLocale(null);
You can access information about the current API configuration:
// Get the current API keyconstapiKey:string=StorytellerSdk.currentApiKey();console.log('Current API key:',apiKey);// Check if SDK is initializedconstisInitialized:boolean=StorytellerSdk.isInitialized();console.log('SDK initialized:',isInitialized);
If your app supports login/logout functionality and you need to switch between users, call initialize again with a new externalId when the user changes:
// On logout, return to the SDK-managed guest identity.try{awaitStorytellerSdk.initialize('api-key',null);// Apply guest attributes, then reload or remount your Storyteller views.}catch(error){console.error('Failed to switch user:',error);}// On a later login, initialize with that user's stable identifier.// await StorytellerSdk.initialize('api-key', 'new-user-guid');
Important: Under the default tracking configuration, switching identities resets per-user local state, including:
Read status of Clips and Stories
Followed categories
User preferences
Custom attributes and locale
Apply the new user’s settings after each switch. This local reset does not delete the user’s account or remotely stored activity.
{"slug": "users", "page_title": "Working with Users", "page_url": "Users/", "canonical_url": "/react-native/Users/", "markdown": "# Working with Users\n\nUser IDs can be used for reporting purposes, storing the read status of Clips and Stories, followed categories, user preferences and other features. When `externalId` is omitted or `null`, the SDK manages a guest identity. With default tracking options, the native SDK persists that guest identity and reuses it on later anonymous initialization. Passing a signed-in user ID selects that user; passing `null` again returns to the SDK-managed guest identity. Persistence and remote read-state behavior depend on your [tracking options](Storyteller.md#event-tracking-options).\n\nHowever, if you have a user account system then you may wish to set your own user IDs within the Storyteller SDK.\n\nThe `externalId` should be an identifier that is unique per user and does not change. Therefore, using something like the user's email address is not a good choice for an `externalId`, as the user may change it at some point in the future. However, using a unique UUID/GUID would be a good choice as it is guaranteed not to change over time.\n\n## Initialization\n\nIn order to supply the `externalId` to the Storyteller SDK, call the `initialize` method. This method is Promise-based and will throw an error if initialization fails.\n\n=== \"v11.0.0+\"\n\n ```typescript\n try {\n await StorytellerSdk.initialize('api-key', 'user-guid');\n console.log('SDK initialized successfully');\n } catch (error) {\n console.error('Initialization failed:', error);\n }\n ```\n\n=== \"v10.x\"\n\n ```typescript\n StorytellerSdk.initialize(\n {\n apiKey: 'api-key',\n externalId: 'user-guid',\n },\n (callback: { result: Boolean; message: string }) => {\n console.log(`result: ${callback.result} message: ${callback.message}`);\n }\n );\n ```\n\n**Parameters:**\n\n- `apiKey` (required): Your Storyteller API key\n- `externalId` (optional): Your unique user identifier. If `null` or omitted, the SDK will use a default autogenerated `externalId`\n\n**Important Notes:**\n\n- When calling `StorytellerSdk.initialize` with a different `externalId` than the previous one, per-user local state is reset (including read markers, likes, follow state and custom attributes under the default tracking configuration)\n- Call `StorytellerSdk.initialize` as soon as the `externalId` is known in your app\n- **Never make simultaneous `StorytellerSdk.initialize` calls** - this will result in unexpected behavior. Always await the completion of one initialization before calling it again\n- Await the Promise for each initialization attempt. `isInitialized()` is a status snapshot and is not a completion signal for a subsequent user switch.\n- Apply the new user\u2019s custom attributes, locale and app-managed follows after reinitialization and before reloading or remounting content.\n\n## Setting the User's Locale\n\nYou can set the user's locale to localize content within the SDK:\n\n```typescript\n// Signature: setLocale(locale?: string | null): void\nStorytellerSdk.setLocale('fr');\n```\n\nUse a supported ISO language code such as `fr`, rather than a regional tag such as `fr-FR`. iOS validates against its ISO language-code list and ignores unsupported values. Both platforms accept `null` or omission to clear the preference:\n\n```typescript\n// ISO 639-1 (two-letter code)\nStorytellerSdk.setLocale('fr');\n\n// Clear locale preference\nStorytellerSdk.setLocale(null);\n```\n\n## Current User Information\n\nYou can access information about the current API configuration:\n\n```typescript\n// Get the current API key\nconst apiKey: string = StorytellerSdk.currentApiKey();\nconsole.log('Current API key:', apiKey);\n\n// Check if SDK is initialized\nconst isInitialized: boolean = StorytellerSdk.isInitialized();\nconsole.log('SDK initialized:', isInitialized);\n```\n\n## Changing Users\n\nIf your app supports login/logout functionality and you need to switch between users, call `initialize` again with a new `externalId` when the user changes:\n\n```typescript\n// On logout, return to the SDK-managed guest identity.\ntry {\n await StorytellerSdk.initialize('api-key', null);\n // Apply guest attributes, then reload or remount your Storyteller views.\n} catch (error) {\n console.error('Failed to switch user:', error);\n}\n\n// On a later login, initialize with that user's stable identifier.\n// await StorytellerSdk.initialize('api-key', 'new-user-guid');\n```\n\n**Important:** Under the default tracking configuration, switching identities resets per-user local state, including:\n\n- Read status of Clips and Stories\n- Followed categories\n- User preferences\n- Custom attributes and locale\n\nApply the new user\u2019s settings after each switch. This local reset does not delete the user\u2019s account or remotely stored activity.\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}