Storyteller.sharedInstance is the SDK singleton. You use it to initialize the SDK, set the global delegate, theme, and privacy options, and open Stories or Clips from your own code. Storyteller.User is a second singleton that stores user attributes and followed categories. The SDK creates both when the script or package loads.
true while a Story player or Clips player that the SDK opened covers your page. It stays true when the user moves from one player to another inside a player. When your page calls an open method or openDeepLink for the other player, the SDK closes the open player first, so the value is briefly false. A StorytellerClipsPlayerView or StorytellerEmbeddedClipsPlayerView on your page doesn't make it true.
true when the Story or Clips player is muted. While a player plays, the value is the sound state the user hears, including a mute that the browser forces. Before any player opens, the value is true. After a player closes, the value keeps that player's last state.
The SDK doesn't notify you when the value changes.
The global callbacks for Stories, Clips, analytics, sharing, ads, in-app links, category follows, and players opening and closing. Assigning an object replaces all eight callbacks, so a callback that you leave out is cleared. Reading the property returns a new object that holds the current callbacks, so you can spread it to add one callback and keep the others:
Since: 10.0.0 moved the delegate to the shared instance. 11.1.0 added getBottomBannerAdConfig, categoryFollowActionTaken, onPlayerPresented, and onPlayerDismissed
The global theme for every view. Pass a UiTheme or a plain object with optional light and dark themes. IUiTheme is the shape of UiTheme; the SDK doesn't export it by name. A view's configuration.theme overrides the global theme for that view.
Note
Each initialize call replaces the global theme with a default UiTheme. Set theme after initialize resolves, and set it again after a later initialize call, such as a user change.
The resolved global Theme for the current color scheme. IStorytellerTheme is the shape of Theme; the SDK doesn't export it by name. The SDK picks the light or dark theme from theme, fills unset values with SDK defaults, and rebuilds it when the system color scheme changes. The value exists after initialize runs or after you assign theme.
The UiStyle of the global theme. Its value is always UiStyle.auto, so the global theme follows the system color scheme. The SDK also uses it for the players it creates when an open method or a hash URL finds no matching view on the page. Set a view's style with configuration.uiStyle.
Reading the property returns the effective values. When enableFunctionalCookies is false, enablePersonalization and enableStorytellerTracking read as false. Set the options before initialize when enableRemoteViewingStore must apply to the stored user ID.
Sets the API host for SDK requests in place of the default Storyteller API host. The SDK removes a trailing / and stores the value in local storage under Storyteller.customInstanceHost. The property has no getter, and no task guide covers it.
The API key from the latest initialize call. Before that call, it returns the key stored in local storage from an earlier page load, or null when no key is stored.
Sets the current user. The SDK stores a SHA-256 hash of the ID. A new ID resets the user data stored in the browser, including user attributes
null
Clears the user ID and resets the stored user data
Omitted
Keeps the stored user ID. The SDK creates a random ID when none is stored, or when apiKey differs from the previous key
When eventTrackingOptions.enableRemoteViewingStore is false, the SDK deletes the stored user ID and ignores externalId.
The call behaves as follows:
Concurrent calls with the same apiKey and externalId return the same promise. A call with different values waits for the active call to settle, then runs
After a successful call, later calls apply the new user and resolve without a new Settings request. With logging enabled, the SDK logs Storyteller has already been initialized. Reusing the existing instance.
The string Storyteller couldn't be initialized because no API key was provided.
The Settings request returns HTTP 401 or 404
An Error whose message starts with InvalidApiKeyError
The Settings request returns HTTP 408
An Error whose message starts with NetworkTimeoutError
Any other Settings failure, including an empty response
An Error whose message starts with NetworkError
Saving the user ID fails, or the request for the user's viewing history fails
The error from that step. The SDK doesn't send sdkInitialized
The error classes are not exported. Check the message prefix to tell them apart.
try{awaitStoryteller.sharedInstance.initialize('demo-api-key',{externalId:'user-id',});}catch(error){console.error('Storyteller could not start.',error);}
Since: 11.0.0 shares one startup between concurrent matching calls
Returns the number of available Clips in a collection.
Parameter
Type
Required
Default
Description
collectionId
string
Yes
None
Clips collection ID
Waits: until an initialize call succeeds. The promise stays pending until then
Rejects: with Error('Collection is required to load Clips count') for an empty ID, and when the request fails or the response is empty or has no numeric count
The open methods show the Story player or the Clips player from your code. They share this behavior:
The SDK looks for the content in the views on the page. It uses only views with URLs enabled, which means the player.disableUrls or clipPlayer.disableUrls theme property is false.
When a view has the content, the SDK sets location.hash to that view's player URL, such as #top-stories/story-id.
Otherwise, the SDK loads the content from the API and opens it in a player it creates, at #stories/... or #clips/....
The promise resolves once the SDK has opened the player by setting location.hash. It rejects when the SDK cannot load the content or the content does not exist.
The rejection value can be an Error or a string. Handle every rejection:
try{awaitStoryteller.sharedInstance.openStory('story-id');}catch(error){console.error('The Story could not be opened.',error);}
Call the open methods after initialize resolves. See Basename for the hash URL format.
Returns: false when the URL isn't a supported Storyteller link, and nothing opens. true once the SDK has found the content and opened the player route; the player then renders
Rejects: when the content can't be loaded, when a Clip category URL has no collection ID, and when a Story or Page URL names a category that doesn't contain the Story
The events of this opening carry options.context in place of the context configured on the view that opens the content. When you leave out context, the events carry the view's configured context. Events from a player that the SDK creates, because no view on the page has the content, carry none. The SDK passes context only to your callbacks.
To check a URL without opening it, call parseDeepLink.
Clip or Clip category to show first. clipId takes priority when you pass both. When the destination is missing or not found, the first Clip in the collection opens
openedReason
OpenedReason.deepLink
No
None
The OpenedReason of the first Clip's openedClip event. OpenedReason.deepLink is the only accepted value
Without openedReason, the first Clip reports openedReason: deepLink, unless the open lands on a Category (destination.categoryId): then it reports categoryListTap. Pass Storyteller.OpenedReason.deepLink to make a Category open report deepLink too. openDeepLink always reports deepLink.
destination.initialFeed takes a ClipFeed: 'forYou', the default, or 'following'. 'following' opens the Following tab of a collection that has the For You and Following tabs. The SDK ignores it and logs a warning when you also pass clipId or categoryId. A collection without the tabs opens For You and logs a warning.
Rejects: when the collection cannot be loaded
Since: 10.7.0 made the method async and added destination. 11.1.0 added destination.initialFeed
Opens the Clips player for a collection at the Clip with this external ID. When no view on the page has the Clip, the SDK loads collection pages until it finds the Clip, up to 100 pages.
Parameter
Type
Required
Default
Description
collectionId
string
Yes
None
Clips collection ID
externalId
string
Yes
None
Clip external ID
Rejects: when the collection cannot be loaded, or with a string message when the collection does not contain the Clip
Closes the open Story player or Clips player, and any StorytellerClipsPlayerView on your page. It has no effect when neither is showing. The dismissedStory or dismissedClip event reports DismissedReason.instanceMethod. When you pass a reason, the event also reports it in customDismissedReason. A StorytellerEmbeddedClipsPlayerView ignores this call.
Parameter
Type
Required
Default
Description
animated
boolean
Yes
None
true plays the close animation
reason
string
No
None
Your reason for closing the player, reported as customDismissedReason. The SDK ignores an empty or whitespace-only string. Don't include personal data
Storyteller.User stores user attributes for personalization and audience targeting. The SDK keeps them in local storage and adds them to its content requests. It also manages the categories that the user follows.
Storyteller.User also has a public parseUserAttributesToQueryStringAlphabetically(): string method. The SDK calls it to build the user attribute query string for its content requests, so you don't need to call it.
Stores one attribute. An existing value for the key is replaced.
Parameter
Type
Required
Default
Description
key
string
Yes
None
Attribute name
value
string
Yes
None
Attribute value
Returns: true when the attribute is stored. undefined when eventTrackingOptions.enablePersonalization is false: the SDK does not store the attribute and logs a warning, which shows when logging is enabled. -1 when the SDK stored the attribute but reading it back returns no value
Throws: Error('Key and value are required when setting user attributes') when key or value is empty
Replaces all custom attributes in one update. Stored keys that attributes leaves out are removed, and {} removes them all. The locale from setLocale stays unless attributes includes stLocale. When the new set equals the stored set, the SDK doesn't store it again, so open Stories don't reload.
Parameter
Type
Required
Default
Description
attributes
Record<string, string>
Yes
None
The complete set of attributes. A plain object, or one made with Object.create(null), whose keys and values are non-empty strings
Throws: an Error, before anything changes, when attributes isn't a plain object, when a key or value is empty or a value isn't a string, or when a key is __proto__
Personalization off: when eventTrackingOptions.enablePersonalization is false, the SDK checks the input, stores nothing, and logs a warning
The IDs of the categories that the user follows. With app-managed following, the IDs keep the order in which the user followed them. Returns [] when eventTrackingOptions.enablePersonalization is false. Reading it doesn't make a request.
Follows categories when your tenant uses app-managed following. IDs match without regard to case. IDs that the user already follows are skipped without a request. For the other IDs, the SDK looks up each category's type from Storyteller and skips IDs that Storyteller doesn't return.
Parameter
Type
Required
Default
Description
categoryIds
string[]
Yes
None
Category external IDs
Waits: until an initialize call succeeds. The promise stays pending until then
No change: the promise resolves without changes with Storyteller-managed following, when eventTrackingOptions.enablePersonalization is false, and when the user changes or personalization is turned off before the call runs
Rejects: with a TypeError when the input is not category ID strings. When the category lookup fails, with an Error whose message starts with NetworkError, NetworkTimeoutError, or InvalidApiKeyError, the same errors that initialize uses. The followed categories don't change when the promise rejects
Unfollows categories when your tenant uses app-managed following. IDs match without regard to case. The SDK changes the follows on the device and doesn't make a request.
Parameter
Type
Required
Default
Description
categoryIds
string[]
Yes
None
Category external IDs
Waits: until an initialize call succeeds. The promise stays pending until then
No change: the promise resolves without changes with Storyteller-managed following, when eventTrackingOptions.enablePersonalization is false, and when the user changes or personalization is turned off before the call runs
Rejects: with a TypeError when the input is not category ID strings
Replaces the whole set of followed categories when your tenant uses app-managed following. The SDK looks up the categories from Storyteller and drops IDs that Storyteller doesn't return. An empty array clears the followed categories without a request.
Parameter
Type
Required
Default
Description
categoryIds
string[]
Yes
None
The complete list of category external IDs that the user follows
Waits: until an initialize call succeeds. The promise stays pending until then
No change: the promise resolves without changes with Storyteller-managed following, when eventTrackingOptions.enablePersonalization is false, and when the user changes or personalization is turned off before the call runs
Rejects: with a TypeError when the input is not category ID strings, and with the addFollowedCategories errors when the lookup fails. The previous followed categories remain when the promise rejects
{"slug": "reference-storyteller", "page_title": "Storyteller Instance", "page_url": "reference/storyteller/", "canonical_url": "/web/reference/storyteller/", "markdown": "# Storyteller instance\n\n`Storyteller.sharedInstance` is the SDK singleton. You use it to initialize the SDK, set the global delegate, theme, and privacy options, and open Stories or Clips from your own code. `Storyteller.User` is a second singleton that stores user attributes and followed categories. The SDK creates both when the script or package loads.\n\n## Members at a glance\n\n`Storyteller.sharedInstance` has these properties:\n\n| Property | Type | Access |\n| --- | --- | --- |\n| [`version`](#version) | `string` | Read |\n| [`isInitialized`](#isinitialized) | `boolean` | Read-only |\n| [`isPlayerVisible`](#isplayervisible) (deprecated) | `boolean` | Read-only |\n| [`isPresentingContent`](#ispresentingcontent) | `boolean` | Read-only |\n| [`isPlayerMuted`](#isplayermuted) | `boolean` | Read-only |\n| [`delegate`](#delegate) | `IStorytellerDelegate` | Read and write |\n| [`theme`](#theme) | `Subset<IUiTheme>` | Read and write |\n| [`currentTheme`](#currenttheme) | `IStorytellerTheme` | Read-only |\n| [`uiStyle`](#uistyle) | `UiStyle` | Read-only |\n| [`eventTrackingOptions`](#eventtrackingoptions) | `StorytellerEventTrackingOptions` | Read and write |\n| [`customInstanceHost`](#custominstancehost) | `string` | Write-only |\n| [`currentApiKey`](#currentapikey) | `string` or `null` | Read-only |\n\nIt has these methods:\n\n| Method | Returns |\n| --- | --- |\n| [`initialize(apiKey, userInput?)`](#initialize) | `Promise<void>` |\n| [`getStoriesCount(categoryIds)`](#getstoriescount) | `Promise<number>` |\n| [`getClipsCount(collectionId)`](#getclipscount) | `Promise<number>` |\n| [`openDeepLink(url, options?)`](#opendeeplink) | `Promise<boolean>` |\n| [`openStory(id)`](#openstory) | `Promise<void>` |\n| [`openStoryByExternalId(externalId)`](#openstorybyexternalid) | `Promise<void>` |\n| [`openPage(pageId)`](#openpage) | `Promise<void>` |\n| [`openCategory(categoryId, storyId?)`](#opencategory) | `Promise<void>` |\n| [`openCollection(collectionId, destination?, openedReason?)`](#opencollection) | `Promise<void>` |\n| [`openClipByExternalId(collectionId, externalId)`](#openclipbyexternalid) | `Promise<void>` |\n| [`dismissPlayer(animated, reason?)`](#dismissplayer) | `void` |\n| [`disablePlayback()`](#disableplayback) | `void` |\n| [`enablePlayback()`](#enableplayback) | `void` |\n| [`enableLogging()`](#enablelogging) | `void` |\n\n[Deprecated members](#deprecated-members) and a note on [internal members](#internal-members) are at the end of [Methods](#methods).\n\n## Properties\n\nThese properties are on `Storyteller.sharedInstance`.\n\n### `version`\n\n```typescript\nversion: string\n```\n\nThe SDK version, such as `'11.1.0'`. See [Use additional SDK methods](../AdditionalMethods.md#version).\n\n### `isInitialized`\n\n```typescript\nget isInitialized(): boolean\n```\n\n`true` after an [`initialize`](#initialize) call succeeds. Once `true`, it stays `true` for the rest of the page session, including while a later `initialize` call runs.\n\n- **Since**: 10.0.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#isinitialized)\n\n### `isPlayerVisible`\n\n```typescript\nget isPlayerVisible(): boolean\n```\n\nDeprecated in 11.1.0. Use [`isPresentingContent`](#ispresentingcontent) instead.\n\nReturns the same value as `isPresentingContent`. A `StorytellerClipsPlayerView` or `StorytellerEmbeddedClipsPlayerView` on your page doesn't make it `true`.\n\n- **Since**: 10.0.0. Since 11.1.0, it returns the value of `isPresentingContent`\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#isplayervisible)\n\n### `isPresentingContent`\n\n```typescript\nget isPresentingContent(): boolean\n```\n\n`true` while a Story player or Clips player that the SDK opened covers your page. It stays `true` when the user moves from one player to another inside a player. When your page calls an `open` method or `openDeepLink` for the other player, the SDK closes the open player first, so the value is briefly `false`. A `StorytellerClipsPlayerView` or `StorytellerEmbeddedClipsPlayerView` on your page doesn't make it `true`.\n\nWhen the value changes, the SDK calls the global delegate's [`onPlayerPresented`](callbacks.md#storyteller-delegate-onplayerpresented) or [`onPlayerDismissed`](callbacks.md#storyteller-delegate-onplayerdismissed).\n\n- **Since**: 11.1.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#ispresentingcontent)\n\n### `isPlayerMuted`\n\n```typescript\nget isPlayerMuted(): boolean\n```\n\n`true` when the Story or Clips player is muted. While a player plays, the value is the sound state the user hears, including a mute that the browser forces. Before any player opens, the value is `true`. After a player closes, the value keeps that player's last state.\n\nThe SDK doesn't notify you when the value changes.\n\n- **Since**: 11.1.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#isplayermuted)\n\n### `delegate`\n\n```typescript\nget delegate(): IStorytellerDelegate\nset delegate(delegateObj: IStorytellerDelegate)\n```\n\nThe global callbacks for Stories, Clips, analytics, sharing, ads, in-app links, category follows, and players opening and closing. Assigning an object replaces all eight callbacks, so a callback that you leave out is cleared. Reading the property returns a new object that holds the current callbacks, so you can spread it to add one callback and keep the others:\n\n```typescript\nStoryteller.sharedInstance.delegate = {\n ...Storyteller.sharedInstance.delegate,\n onPlayerPresented: () => {\n document.querySelector('video')?.pause();\n },\n};\n```\n\n- **Type**: [`IStorytellerDelegate`](callbacks.md#istorytellerdelegate)\n- **Since**: 10.0.0 moved the delegate to the shared instance. 11.1.0 added `getBottomBannerAdConfig`, `categoryFollowActionTaken`, `onPlayerPresented`, and `onPlayerDismissed`\n- **Guide**: [Handle global callbacks](../StorytellerDelegate.md#how-to-use)\n\n### `theme`\n\n```typescript\nget theme(): Subset<IUiTheme>\nset theme(theme: Subset<IUiTheme>)\n```\n\nThe global theme for every view. Pass a [`UiTheme`](types.md#uitheme) or a plain object with optional `light` and `dark` themes. `IUiTheme` is the shape of `UiTheme`; the SDK doesn't export it by name. A view's [`configuration.theme`](views.md#ilistconfiguration) overrides the global theme for that view.\n\n!!! note\n\n Each `initialize` call replaces the global theme with a default `UiTheme`. Set `theme` after `initialize` resolves, and set it again after a later `initialize` call, such as a user change.\n\n```typescript\nawait Storyteller.sharedInstance.initialize('demo-api-key');\n\nStoryteller.sharedInstance.theme = new Storyteller.UiTheme({\n light: { colors: { primary: '#1C62EB' } },\n});\n```\n\n- **Guide**: [Customize themes](../Themes.md)\n\n### `currentTheme`\n\n```typescript\nget currentTheme(): IStorytellerTheme\n```\n\nThe resolved global [`Theme`](types.md#theme) for the current color scheme. `IStorytellerTheme` is the shape of `Theme`; the SDK doesn't export it by name. The SDK picks the `light` or `dark` theme from `theme`, fills unset values with SDK defaults, and rebuilds it when the system color scheme changes. The value exists after `initialize` runs or after you assign `theme`.\n\n### `uiStyle`\n\n```typescript\nget uiStyle(): UiStyle\n```\n\nThe [`UiStyle`](types.md#uistyle) of the global theme. Its value is always `UiStyle.auto`, so the global theme follows the system color scheme. The SDK also uses it for the players it creates when an [open method](#open-methods) or a hash URL finds no matching view on the page. Set a view's style with [`configuration.uiStyle`](views.md#ilistconfiguration).\n\n### `eventTrackingOptions`\n\n```typescript\nget eventTrackingOptions(): StorytellerEventTrackingOptions\nset eventTrackingOptions(newOptions: Partial<StorytellerEventTrackingOptions>)\n```\n\nThe privacy and tracking options. Every option defaults to `true`, and `disabledFunctionalFeatures` defaults to `[]`.\n\nAssigning an object replaces every option: a field that you leave out returns to its default. To change one option, spread the current value:\n\n```typescript\nStoryteller.sharedInstance.eventTrackingOptions = {\n ...Storyteller.sharedInstance.eventTrackingOptions,\n enableAdTracking: false,\n};\n```\n\nReading the property returns the effective values. When `enableFunctionalCookies` is `false`, `enablePersonalization` and `enableStorytellerTracking` read as `false`. Set the options before `initialize` when `enableRemoteViewingStore` must apply to the stored user ID.\n\n- **Type**: [`StorytellerEventTrackingOptions`](types.md#storytellereventtrackingoptions)\n- **Since**: 10.7.0. `enableAdTracking` was added in 10.9.0 and `enableFullVideoAnalytics` in 10.11.0\n- **Guide**: [Control privacy and tracking](../PrivacyAndTracking.md)\n\n### `customInstanceHost`\n\n```typescript\nset customInstanceHost(customInstanceHost: string)\n```\n\nSets the API host for SDK requests in place of the default Storyteller API host. The SDK removes a trailing `/` and stores the value in local storage under `Storyteller.customInstanceHost`. The property has no getter, and no task guide covers it.\n\n- **Since**: 8.0.0\n\n### `currentApiKey`\n\n```typescript\nget currentApiKey(): string | null\n```\n\nThe API key from the latest `initialize` call. Before that call, it returns the key stored in local storage from an earlier page load, or `null` when no key is stored.\n\n## Methods\n\nThese methods are on `Storyteller.sharedInstance`.\n\n### `initialize`\n\n```typescript\ninitialize(apiKey: string, userInput?: UserInput): Promise<void>\n```\n\nStarts the SDK for an API key and user. Create views after the promise resolves.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `apiKey` | `string` | Yes | None | Your Storyteller Web SDK API key |\n| `userInput` | `UserInput` | No | `{}` | User options. Pass a plain object such as `{ externalId: 'user-id' }` |\n\n`UserInput` has one optional field, `externalId`:\n\n```typescript\nclass UserInput {\n constructor(public externalId?: string | null) {}\n}\n```\n\n| `externalId` value | Result |\n| --- | --- |\n| A string | Sets the current user. The SDK stores a SHA-256 hash of the ID. A new ID resets the user data stored in the browser, including user attributes |\n| `null` | Clears the user ID and resets the stored user data |\n| Omitted | Keeps the stored user ID. The SDK creates a random ID when none is stored, or when `apiKey` differs from the previous key |\n\nWhen `eventTrackingOptions.enableRemoteViewingStore` is `false`, the SDK deletes the stored user ID and ignores `externalId`.\n\nThe call behaves as follows:\n\n- Concurrent calls with the same `apiKey` and `externalId` return the same promise. A call with different values waits for the active call to settle, then runs\n- After a successful call, later calls apply the new user and resolve without a new Settings request. With logging enabled, the SDK logs `Storyteller has already been initialized. Reusing the existing instance.`\n- The SDK records the [`sdkInitialized` activity event](../Analytics.md#sdk-initialization) after the Settings request succeeds or fails\n\nThe promise rejects with these values:\n\n| Condition | Rejection value |\n| --- | --- |\n| `apiKey` is empty and the SDK is not initialized | The string `Storyteller couldn't be initialized because no API key was provided.` |\n| The Settings request returns HTTP 401 or 404 | An `Error` whose message starts with `InvalidApiKeyError` |\n| The Settings request returns HTTP 408 | An `Error` whose message starts with `NetworkTimeoutError` |\n| Any other Settings failure, including an empty response | An `Error` whose message starts with `NetworkError` |\n| Saving the user ID fails, or the request for the user's viewing history fails | The error from that step. The SDK doesn't send `sdkInitialized` |\n\nThe error classes are not exported. Check the message prefix to tell them apart.\n\n```typescript\ntry {\n await Storyteller.sharedInstance.initialize('demo-api-key', {\n externalId: 'user-id',\n });\n} catch (error) {\n console.error('Storyteller could not start.', error);\n}\n```\n\n- **Since**: 11.0.0 shares one startup between concurrent matching calls\n- **Guides**: [Show your first Story row](../Quickstart.md#initialize-storyteller), [Handle initialization errors](../Quickstart.md#handle-initialization-errors), [Identify and personalize users](../Users.md#setting-a-user-id)\n\n### `getStoriesCount`\n\n```typescript\ngetStoriesCount(categoryIds: string[]): Promise<number>\n```\n\nReturns the number of available Stories in the given categories. The SDK sends one count request per category and adds the results.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryIds` | `string[]` | Yes | None | Story category IDs |\n\n- **Returns**: the total count. An empty array resolves to `0` at once, without a request\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **Rejects**: when a count request fails, or a response is empty or has no numeric count\n- **Since**: 10.13.16\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#getstoriescount)\n\n### `getClipsCount`\n\n```typescript\ngetClipsCount(collectionId: string): Promise<number>\n```\n\nReturns the number of available Clips in a collection.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `collectionId` | `string` | Yes | None | Clips collection ID |\n\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **Rejects**: with `Error('Collection is required to load Clips count')` for an empty ID, and when the request fails or the response is empty or has no numeric count\n- **Since**: 10.13.16\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#getclipscount)\n\n### Open methods\n\nThe open methods show the Story player or the Clips player from your code. They share this behavior:\n\n1. The SDK looks for the content in the views on the page. It uses only views with URLs enabled, which means the [`player.disableUrls`](../Themes.md#player) or [`clipPlayer.disableUrls`](../Themes.md#clip-player) theme property is `false`.\n2. When a view has the content, the SDK sets `location.hash` to that view's player URL, such as `#top-stories/story-id`.\n3. Otherwise, the SDK loads the content from the API and opens it in a player it creates, at `#stories/...` or `#clips/...`.\n4. The promise resolves once the SDK has opened the player by setting `location.hash`. It rejects when the SDK cannot load the content or the content does not exist.\n\nThe rejection value can be an `Error` or a string. Handle every rejection:\n\n```typescript\ntry {\n await Storyteller.sharedInstance.openStory('story-id');\n} catch (error) {\n console.error('The Story could not be opened.', error);\n}\n```\n\nCall the open methods after `initialize` resolves. See [Basename](../StorytellerListView.md#basename) for the hash URL format.\n\n### `openDeepLink`\n\n```typescript\nopenDeepLink(url: string, options?: OpenDeepLinkOptions): Promise<boolean>\n```\n\nOpens the Story, Page, category, Clip, or collection that a Storyteller content URL points to.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `url` | `string` | Yes | None | A Storyteller content URL, or a player hash such as `#clips/collection-id`. See [supported URL formats](../OpenPlayer.md#supported-url-formats) |\n| `options` | [`OpenDeepLinkOptions`](types.md#opendeeplinkoptions) | No | None | `context` to report in the events of this opening |\n\n- **Returns**: `false` when the URL isn't a supported Storyteller link, and nothing opens. `true` once the SDK has found the content and opened the player route; the player then renders\n- **Rejects**: when the content can't be loaded, when a Clip category URL has no collection ID, and when a Story or Page URL names a category that doesn't contain the Story\n- **Since**: 11.1.0\n- **Guides**: [Open a content URL](../OpenPlayer.md#open-a-content-url), [Use additional SDK methods](../AdditionalMethods.md#opendeeplink)\n\nThe events of this opening carry `options.context` in place of the context configured on the view that opens the content. When you leave out `context`, the events carry the view's configured context. Events from a player that the SDK creates, because no view on the page has the content, carry none. The SDK passes context only to your callbacks.\n\nTo check a URL without opening it, call [`parseDeepLink`](types.md#parsedeeplink).\n\n### `openStory`\n\n```typescript\nopenStory(id: string): Promise<void>\n```\n\nOpens the Story with this Story ID. Its events report `storyPlaybackMode` as `'singleStory'`.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `id` | `string` | Yes | None | Story ID |\n\n- **Rejects**: when the Story cannot be loaded, or with the string `No Story with the provided ID was found.`\n- **Since**: 10.7.0 made the method async\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#openstory)\n\n### `openStoryByExternalId`\n\n```typescript\nopenStoryByExternalId(externalId: string): Promise<void>\n```\n\nOpens the Story with this external ID. Its events report `storyPlaybackMode` as `'singleStory'`.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `externalId` | `string` | Yes | None | Story external ID |\n\n- **Rejects**: when the Story cannot be loaded, or with the string `No Story with the provided External ID was found.`\n- **Since**: 10.7.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#openstorybyexternalid)\n\n### `openPage`\n\n```typescript\nopenPage(pageId: string): Promise<void>\n```\n\nOpens the Story that contains this Page, starting at the Page.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `pageId` | `string` | Yes | None | Story Page ID |\n\n- **Rejects**: when the SDK cannot load a Story for the Page\n- **Since**: 10.7.0 made the method async\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#openpage)\n\n### `openCategory`\n\n```typescript\nopenCategory(categoryId: string, storyId?: string): Promise<void>\n```\n\nOpens the Story player for a category. On the page, the SDK uses a Stories view whose only category is `categoryId`.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryId` | `string` | Yes | None | Story category ID |\n| `storyId` | `string` | No | None | Story to open first. When it is missing or not in the category, the first Story in the category opens |\n\n- **Rejects**: when the category cannot be loaded\n- **Since**: 10.7.0 made the method async\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#opencategory)\n\n### `openCollection`\n\n```typescript\nopenCollection(\n collectionId: string,\n destination?: {\n categoryId?: string;\n clipId?: string;\n initialFeed?: ClipFeed;\n },\n openedReason?: OpenedReason.deepLink\n): Promise<void>\n```\n\nOpens the Clips player for a collection.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `collectionId` | `string` | Yes | None | Clips collection ID |\n| `destination` | `{ categoryId?: string; clipId?: string; initialFeed?: ClipFeed }` | No | None | Clip or Clip category to show first. `clipId` takes priority when you pass both. When the destination is missing or not found, the first Clip in the collection opens |\n| `openedReason` | `OpenedReason.deepLink` | No | None | The [`OpenedReason`](types.md#openedreason) of the first Clip's `openedClip` event. `OpenedReason.deepLink` is the only accepted value |\n\nWithout `openedReason`, the first Clip reports `openedReason: deepLink`, unless the open lands on a Category (`destination.categoryId`): then it reports `categoryListTap`. Pass `Storyteller.OpenedReason.deepLink` to make a Category open report `deepLink` too. [`openDeepLink`](#opendeeplink) always reports `deepLink`.\n\n`destination.initialFeed` takes a [`ClipFeed`](types.md#clipfeed): `'forYou'`, the default, or `'following'`. `'following'` opens the Following tab of a collection that has the [For You and Following tabs](../Users.md#for-you-and-following-tabs). The SDK ignores it and logs a warning when you also pass `clipId` or `categoryId`. A collection without the tabs opens For You and logs a warning.\n\n- **Rejects**: when the collection cannot be loaded\n- **Since**: 10.7.0 made the method async and added `destination`. 11.1.0 added `destination.initialFeed`\n- **Guides**: [Use additional SDK methods](../AdditionalMethods.md#opencollection), [Start on the Following feed](../OpenPlayer.md#initial-feed)\n\n### `openClipByExternalId`\n\n```typescript\nopenClipByExternalId(collectionId: string, externalId: string): Promise<void>\n```\n\nOpens the Clips player for a collection at the Clip with this external ID. When no view on the page has the Clip, the SDK loads collection pages until it finds the Clip, up to 100 pages.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `collectionId` | `string` | Yes | None | Clips collection ID |\n| `externalId` | `string` | Yes | None | Clip external ID |\n\n- **Rejects**: when the collection cannot be loaded, or with a string message when the collection does not contain the Clip\n- **Since**: 10.7.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#openclipbyexternalid)\n\n### `dismissPlayer`\n\n```typescript\ndismissPlayer(animated: boolean, reason?: string): void\n```\n\nCloses the open Story player or Clips player, and any `StorytellerClipsPlayerView` on your page. It has no effect when neither is showing. The `dismissedStory` or `dismissedClip` event reports [`DismissedReason.instanceMethod`](types.md#dismissedreason). When you pass a `reason`, the event also reports it in `customDismissedReason`. A `StorytellerEmbeddedClipsPlayerView` ignores this call.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `animated` | `boolean` | Yes | None | `true` plays the close animation |\n| `reason` | `string` | No | None | Your reason for closing the player, reported as `customDismissedReason`. The SDK ignores an empty or whitespace-only string. Don't include personal data |\n\n- **Since**: 10.0.0. 11.1.0 added `reason`\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#dismissplayer)\n\n### `disablePlayback`\n\n```typescript\ndisablePlayback(): void\n```\n\nPauses the open Story player and the active Clip video. Players that open while playback is disabled stay paused.\n\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#disableplayback)\n\n### `enablePlayback`\n\n```typescript\nenablePlayback(): void\n```\n\nAllows playback again after `disablePlayback`, and resumes the open Story player and the active Clip. Playback is enabled by default.\n\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#enableplayback)\n\n### `enableLogging`\n\n```typescript\nenableLogging(): void\n```\n\nTurns on SDK info, warning, and log messages in the browser console. The SDK always writes errors to the console, with or without this call.\n\n- **Since**: 10.0.0\n- **Guide**: [Use additional SDK methods](../AdditionalMethods.md#enablelogging)\n\n### Deprecated members\n\nThese members still work in 11.1.0. Replace them with the members listed:\n\n| Member | Behavior | Replacement |\n| --- | --- | --- |\n| `openClip(id: string, onError?: (message: string) => void): void` | Opens a Clip that a Clips view on the page has loaded. Calls `onError` with a message when no view has the Clip | [`openCollection`](#opencollection) or [`openClipByExternalId`](#openclipbyexternalid) |\n| `enableEventTracking(): void` | Sets every tracking option to its default | [`eventTrackingOptions`](#eventtrackingoptions) |\n| `disableEventTracking(): void` | Sets every tracking option to its default, except `enableStorytellerTracking: false` | [`eventTrackingOptions`](#eventtrackingoptions) |\n| `get currentUserId(): string` | Always returns `''`. Deprecated in 10.11.0 | None |\n| [`get isPlayerVisible(): boolean`](#isplayervisible) | Returns the value of `isPresentingContent`. Deprecated in 11.1.0 | [`isPresentingContent`](#ispresentingcontent) |\n\n### Internal members\n\nThe type declarations also show members whose names end in `_`. They are for the SDK's own use. Don't call them.\n\n## `Storyteller.User`\n\n`Storyteller.User` stores user attributes for personalization and audience targeting. The SDK keeps them in local storage and adds them to its content requests. It also manages the categories that the user follows.\n\n```typescript\nStoryteller.User.setUserAttribute('location', 'New York');\n```\n\nSet attributes after `initialize` resolves. A new `externalId` in `initialize` clears the stored attributes and followed categories. See [Identify and personalize users](../Users.md#personalization-and-targeted-stories) and [Followed categories](../Users.md#followed-categories).\n\n| Member | Returns |\n| --- | --- |\n| [`setUserAttribute(key, value)`](#setuserattribute) | `true`, `-1`, or `undefined` |\n| [`setUserAttributes(attributes)`](#setuserattributes) | `void` |\n| [`getUserAttribute(key)`](#getuserattribute) | `string` or `undefined` |\n| [`getUserAttributes()`](#getuserattributes) | `Record<string, string>` |\n| [`removeUserAttribute(key)`](#removeuserattribute) | `void` |\n| [`setLocale(locale)`](#setlocale) | `void` |\n| [`locale`](#locale) | `string` or `undefined` |\n| [`followedCategories`](#followedcategories) | `string[]` |\n| [`isCategoryFollowed(categoryId)`](#iscategoryfollowed) | `boolean` |\n| [`addFollowedCategory(categoryId)`](#addfollowedcategory) | `Promise<void>` |\n| [`addFollowedCategories(categoryIds)`](#addfollowedcategories) | `Promise<void>` |\n| [`removeFollowedCategory(categoryId)`](#removefollowedcategory) | `Promise<void>` |\n| [`removeFollowedCategories(categoryIds)`](#removefollowedcategories) | `Promise<void>` |\n| [`setFollowedCategories(categoryIds)`](#setfollowedcategories) | `Promise<void>` |\n| [`getFollowableCategories()`](#getfollowablecategories) | `Promise<StorytellerFollowableCategories>` |\n\n`Storyteller.User` also has a public `parseUserAttributesToQueryStringAlphabetically(): string` method. The SDK calls it to build the user attribute query string for its content requests, so you don't need to call it.\n\n### `setUserAttribute`\n\n```typescript\nsetUserAttribute(key: string, value: string): true | -1 | undefined\n```\n\nStores one attribute. An existing value for the key is replaced.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `key` | `string` | Yes | None | Attribute name |\n| `value` | `string` | Yes | None | Attribute value |\n\n- **Returns**: `true` when the attribute is stored. `undefined` when `eventTrackingOptions.enablePersonalization` is `false`: the SDK does not store the attribute and logs a warning, which shows when logging is enabled. `-1` when the SDK stored the attribute but reading it back returns no value\n- **Throws**: `Error('Key and value are required when setting user attributes')` when `key` or `value` is empty\n- **Guide**: [Setting User Attributes](../Users.md#setting-user-attributes)\n\n### `setUserAttributes`\n\n```typescript\nsetUserAttributes(attributes: Record<string, string>): void\n```\n\nReplaces all custom attributes in one update. Stored keys that `attributes` leaves out are removed, and `{}` removes them all. The locale from [`setLocale`](#setlocale) stays unless `attributes` includes `stLocale`. When the new set equals the stored set, the SDK doesn't store it again, so open Stories don't reload.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `attributes` | `Record<string, string>` | Yes | None | The complete set of attributes. A plain object, or one made with `Object.create(null)`, whose keys and values are non-empty strings |\n\n- **Throws**: an `Error`, before anything changes, when `attributes` isn't a plain object, when a key or value is empty or a value isn't a string, or when a key is `__proto__`\n- **Personalization off**: when `eventTrackingOptions.enablePersonalization` is `false`, the SDK checks the input, stores nothing, and logs a warning\n- **Since**: 11.1.0\n- **Guide**: [Replace all user attributes](../Users.md#replacing-all-user-attributes)\n\n### `getUserAttribute`\n\n```typescript\ngetUserAttribute(key: string): string | undefined\n```\n\nReturns the stored value for `key`, or `undefined` when none is stored.\n\n### `getUserAttributes`\n\n```typescript\ngetUserAttributes(): IUserAttributes\n```\n\nReturns all stored attributes as an object. `IUserAttributes` is `Record<string, string>`. Returns `{}` when none are stored.\n\n### `removeUserAttribute`\n\n```typescript\nremoveUserAttribute(key: string): void\n```\n\nRemoves one attribute.\n\n- **Guide**: [Removing User Attributes](../Users.md#removing-user-attributes)\n\n### `setLocale`\n\n```typescript\nsetLocale(locale: string): void\n```\n\nSets the Clips locale. The SDK stores it as the `stLocale` user attribute, so it follows the same rules as `setUserAttribute`.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `locale` | `string` | Yes | None | Language code, such as `'es'` |\n\n- **Throws**: the `setUserAttribute` error when `locale` is empty\n- **Since**: 10.2.0\n- **Guide**: [Updating the Clips locale](../Users.md#updating-the-clips-locale)\n\n### `locale`\n\n```typescript\nget locale(): string | undefined\n```\n\nThe stored `stLocale` attribute, or `undefined`.\n\n### `followedCategories`\n\n```typescript\nget followedCategories(): string[]\n```\n\nThe IDs of the categories that the user follows. With app-managed following, the IDs keep the order in which the user followed them. Returns `[]` when `eventTrackingOptions.enablePersonalization` is `false`. Reading it doesn't make a request.\n\n- **Since**: 11.1.0\n- **Guide**: [Check followed categories](../Users.md#check-followed-categories)\n\n### `isCategoryFollowed`\n\n```typescript\nisCategoryFollowed(categoryId: string): boolean\n```\n\nReturns `true` when the user follows the category. The comparison ignores case, and it doesn't make a request.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryId` | `string` | Yes | None | Category external ID |\n\n- **Since**: 11.1.0\n- **Guide**: [Check followed categories](../Users.md#check-followed-categories)\n\n### `addFollowedCategory`\n\n```typescript\naddFollowedCategory(categoryId: string): Promise<void>\n```\n\nFollows one category. It behaves like [`addFollowedCategories`](#addfollowedcategories) with one ID.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryId` | `string` | Yes | None | Category external ID |\n\n- **Since**: 11.1.0\n- **Guide**: [Follow and unfollow categories](../Users.md#follow-and-unfollow-categories)\n\n### `addFollowedCategories`\n\n```typescript\naddFollowedCategories(categoryIds: string[]): Promise<void>\n```\n\nFollows categories when your tenant uses app-managed following. IDs match without regard to case. IDs that the user already follows are skipped without a request. For the other IDs, the SDK looks up each category's type from Storyteller and skips IDs that Storyteller doesn't return.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryIds` | `string[]` | Yes | None | Category external IDs |\n\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **No change**: the promise resolves without changes with Storyteller-managed following, when `eventTrackingOptions.enablePersonalization` is `false`, and when the user changes or personalization is turned off before the call runs\n- **Rejects**: with a `TypeError` when the input is not category ID strings. When the category lookup fails, with an `Error` whose message starts with `NetworkError`, `NetworkTimeoutError`, or `InvalidApiKeyError`, the same errors that [`initialize`](#initialize) uses. The followed categories don't change when the promise rejects\n- **Since**: 11.1.0\n- **Guide**: [Follow and unfollow categories](../Users.md#follow-and-unfollow-categories)\n\n### `removeFollowedCategory`\n\n```typescript\nremoveFollowedCategory(categoryId: string): Promise<void>\n```\n\nUnfollows one category. It behaves like [`removeFollowedCategories`](#removefollowedcategories) with one ID.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryId` | `string` | Yes | None | Category external ID |\n\n- **Since**: 11.1.0\n- **Guide**: [Follow and unfollow categories](../Users.md#follow-and-unfollow-categories)\n\n### `removeFollowedCategories`\n\n```typescript\nremoveFollowedCategories(categoryIds: string[]): Promise<void>\n```\n\nUnfollows categories when your tenant uses app-managed following. IDs match without regard to case. The SDK changes the follows on the device and doesn't make a request.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryIds` | `string[]` | Yes | None | Category external IDs |\n\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **No change**: the promise resolves without changes with Storyteller-managed following, when `eventTrackingOptions.enablePersonalization` is `false`, and when the user changes or personalization is turned off before the call runs\n- **Rejects**: with a `TypeError` when the input is not category ID strings\n- **Since**: 11.1.0\n- **Guide**: [Follow and unfollow categories](../Users.md#follow-and-unfollow-categories)\n\n### `setFollowedCategories`\n\n```typescript\nsetFollowedCategories(categoryIds: string[]): Promise<void>\n```\n\nReplaces the whole set of followed categories when your tenant uses app-managed following. The SDK looks up the categories from Storyteller and drops IDs that Storyteller doesn't return. An empty array clears the followed categories without a request.\n\n| Parameter | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `categoryIds` | `string[]` | Yes | None | The complete list of category external IDs that the user follows |\n\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **No change**: the promise resolves without changes with Storyteller-managed following, when `eventTrackingOptions.enablePersonalization` is `false`, and when the user changes or personalization is turned off before the call runs\n- **Rejects**: with a `TypeError` when the input is not category ID strings, and with the [`addFollowedCategories`](#addfollowedcategories) errors when the lookup fails. The previous followed categories remain when the promise rejects\n- **Since**: 11.1.0\n- **Guide**: [Replace the followed categories](../Users.md#replace-the-followed-categories)\n\n### `getFollowableCategories`\n\n```typescript\ngetFollowableCategories(): Promise<StorytellerFollowableCategories>\n```\n\nReturns the categories that your tenant lets users follow, with whether the current user follows each one. It works with both following models.\n\n- **Returns**: a [`StorytellerFollowableCategories`](types.md#storytellerfollowablecategories) object\n- **Waits**: until an `initialize` call succeeds. The promise stays pending until then\n- **Rejects**: when the request fails, with the [`addFollowedCategories`](#addfollowedcategories) request errors\n- **Since**: 11.1.0\n- **Guide**: [List followable categories](../Users.md#list-followable-categories)\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}