Open a Story or Clips player from your own button, link, or route instead of a
tile. These methods are on Storyteller.sharedInstance. Each one returns a
promise that rejects when the SDK can't open the content. Call them after
initialize resolves.
constopenFeaturedStory=async()=>{try{awaitStoryteller.sharedInstance.openStory('story-id');}catch(error){console.error('The Story could not be opened.',error);}};document.getElementById('featured-story-button')?.addEventListener('click',openFeaturedStory);
The SDK first looks for the content in the views on your page and opens it in
that view's player. It uses only views whose player URLs are turned on, which
means the disableUrlstheme setting is false. If no view on
the page has the content, the SDK loads it from Storyteller and opens it in a
player that it creates over your page. Either way, the SDK opens the player by setting the page's hash
URL, such as #stories/story-id, and the promise resolves at that point. See
basename for the URL format.
openDeepLink opens a Storyteller share link, or a custom-scheme link from
your app, in the right player. Call it after initialize resolves:
constopenContentUrl=async(contentUrl)=>{try{consthandled=awaitStoryteller.sharedInstance.openDeepLink(contentUrl,{context:{location:'home',module:'related-content'},});if(!handled){// Not a Storyteller content URL. Handle it yourself.}}catch(error){console.error('The content could not be opened.',error);}};
The promise:
resolves to false when the URL isn't a supported Storyteller link. Nothing
opens.
resolves to 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
If another openDeepLink call or a browser navigation starts while the SDK is
still loading content for an earlier call, the earlier call doesn't open its
content and doesn't change the newer route or its context. Its promise still
resolves to true, or rejects if its content can't be loaded.
To check a URL without opening it, call Storyteller.parseDeepLink(contentUrl).
It returns the destination, or null for an unsupported URL, and doesn't load
content or change the page. See DeepLink for
the destination fields.
HTTP and HTTPS URLs on storyteller.com, shar.estori.es, or
ope.nstori.es, including their subdomains
URLs with a custom scheme that ends in stories, such as
tenantstories://
hash routes, on their own or at the end of an HTTP or HTTPS URL on any
host, such as your own site. When an HTTP or HTTPS URL has a fragment, the
SDK reads only the fragment.
In a custom-scheme URL, the SDK ignores the part between :// and the next
/. Put a word such as open there, then the content path:
tenantstories://open/clip/clip-id.
Before it reads the content path, the SDK removes a leading /go, /open,
or /page/meta. Query parameter names are case-insensitive, so
collectionId and collectionid both work.
Content paths, for Storyteller hosts and custom schemes:
Path
Opens
/story-id
The Story with this ID
/story-id/page-id
The Page, or the Story if the Page can't be opened
/story-id/page-id/answer-id
The Page. parseDeepLink returns answerId, but opening uses only the Page.
If a Page link can't open its Page, the SDK opens its Story instead. The
promise rejects if that Story also fails to open. A Clip Category link
without collectionId rejects.
A content path opens a Clip Category instead of a Clip when it has both a
Clip ID and a categoryId. openCollection works the other way round: when
you pass both, clipId takes priority. To open a Clip within a Clip
Category from a link, use the hash route
#clips/collection-id/clip-id?category=category-id.
parseDeepLink returns null, and openDeepLink resolves to false, for
malformed URLs and for paths that don't match a format in these tables, such
as paths that start with /sheet, /profile, or /search.
Hash routes, on their own or after any HTTP or HTTPS URL:
Hash
Opens
#stories/story-id
The Story
#stories/story-id/page-id
The Page in that Story
#stories/story-id?categoryId=category-id
The Story in that Story Category
#stories/story-id/page-id?categoryId=category-id
The Page, in that Story and Story Category
#clips/collection-id
The collection
#clips/collection-id/clip-id
The Clip in that collection
#clips/collection-id?category=category-id
The Clip Category in that collection
#clips/collection-id/clip-id?category=category-id
The Clip, in that Clip Category and collection
Story and Page hashes name the category with categoryId. Clips hashes use
category. When a hash has both a content ID and a category, the SDK opens
the content within that category, and the promise rejects if the content
isn't in the category.
IDs in any of these URLs can be percent-encoded. The SDK decodes each ID
once, so don't encode an ID twice.
The SDK opens the content the same way as the open methods below: in the
player of a view on your page that has the content, or in a player that it
creates over your page.
Pass context to attach placement data to the analytics events of the
content you open. The SDK returns it in data.context to your
onUserActivityOccurred
callback and doesn't send it to Storyteller. See
placement context.
With context, that value replaces the selected view's configured context
for this opening.
Without the option, the SDK uses the selected view's configured context. A
player that the SDK creates, because no view on the page has the content,
has no configured context.
Each opening replaces the temporary context from the previous call.
Opens the Story player for a Category. Pass a Story ID as the second argument
to start at that Story; otherwise, the first Story in the Category opens.
Opens the Clips player for a collection. Pass a destination to start at a
Clip, or at the first Clip in a Clip Category. Otherwise, the first Clip in the
collection opens.
If you pass both clipId and categoryId, clipId takes priority. The
player opens the Category only when the Clip isn't in the collection.
The third argument sets the opening reason in analytics events, and accepts
only Storyteller.OpenedReason.deepLink. Without it, the openedClip event
for the first Clip still reports openedReason: deepLink, unless the player
opens on a Category (destination.categoryId), which reports
categoryListTap. Pass deepLink when the user arrived through a deep link,
so that a Category open reports deepLink too. openDeepLink always passes
it.
A Clips player can show two feeds as tabs: For You and Following. Pass
initialFeed: 'following' to open the collection on its Following feed. The tab labels come from your theme, so yours may differ.
The default is 'forYou'.
A clipId or categoryId in the same destination takes priority. The
player opens that Clip or Category and logs a warning that it ignored
initialFeed.
If the collection doesn't have Following turned on, the player opens For
You and logs a warning. The promise doesn't reject.
If the user follows nothing, Following shows its themed empty state.
For You loads behind Following, so the user can switch back.
The option applies to this call only. The SDK doesn't remember which feed
the user last selected.
Call enableLogging to see the warnings in the browser console.
Events report the same opening reason as they would on For You, and the SDK
sends no extra event for the feed. When the player opens on Following, the
first openedClip event has clipFeedType: 'following'.
openDeepLink starts on Following for collection links with
feed=following:
The feed parameter name and its value are case-insensitive. Any other value
opens For You. A Clip or Category in the link still takes priority, and the
supported URL formats still apply.
For a StorytellerClipsPlayerView or StorytellerEmbeddedClipsPlayerView,
use the initialFeed configuration
instead.
Call dismissPlayer to close Storyteller content, for example when your
application navigates away. Pass true to play the close animation.
Storyteller.sharedInstance.dismissPlayer(true);
The call closes the Story or Clips player open over your page and any
StorytellerClipsPlayerView on the page, together when both are showing. It
doesn't close a StorytellerEmbeddedClipsPlayerView. If neither a player nor
a StorytellerClipsPlayerView is showing, the call does nothing, so you don't
need to check first.
Don't use isPresentingContent
to decide whether to call it. That property counts only players open over
your page, so it is false while a StorytellerClipsPlayerView is the only
content showing.
Whether Stories and Clips start with sound, and whether the SDK remembers the
user's choice, come from your tenant's player settings in Storyteller. There
is nothing to set in code. Ask your Storyteller contact to change them.
Stories and Clips each have their own starting state: sound on, sound off, or
follow the device silent switch. Browsers can't read a silent switch, so that
option starts muted. When your tenant sets no starting state, Clips start
with sound and Stories start muted.
When the user mutes or unmutes a Story or Clip, the next Story or Clip starts
the same way until the page reloads. A Story player keeps the choice as the
user moves between Stories.
If your settings keep the user's choice, the SDK saves it in the browser as
Storyteller.playerMuted, and later visits start with the saved choice
instead of the default. The SDK saves it only when enableFunctionalCookies
is true, and removes it when your settings stop keeping the choice. See
Functional cookies and local storage items.
Browsers can block playback with sound until the user interacts with the
page, for example when a deep link opens a player as the page loads. The
Story or Clip then plays muted, and the user can unmute it. The SDK doesn't
save a mute that the browser forced as the user's choice.
Wrap each call in try/catch, or add .catch(), so that a rejected promise
doesn't go unhandled. The rejection value can be an Error or a string.
Method
When the content is missing
openDeepLink
Resolves to false when the URL isn't a supported Storyteller link. Rejects when the content can't be loaded, or a Clip Category URL has no collection.
openStory, openStoryByExternalId
Rejects when the Story request fails, or with a string when no Story has the ID.
openPage
Rejects when the SDK can't load a Story that contains the Page.
openCategory
Rejects when the SDK can't load the Category, or the Category has no Stories. If storyId isn't in the Category, the first Story opens instead.
openCollection
Rejects when the SDK can't load the collection, or the collection has no Clips. If the destination Clip or Category isn't in the collection, the first Clip opens instead.
openClipByExternalId
Rejects when the SDK can't load the collection, or with a string when the collection has no Clip with the external ID.
When the SDK opens the first Story or Clip instead of the one you asked for,
it logs a message. Call enableLogging to see it in the browser console.
{"slug": "open-player", "page_title": "Open a Player Programmatically", "page_url": "OpenPlayer/", "canonical_url": "/web/OpenPlayer/", "markdown": "# Open a player programmatically\n\nOpen a Story or Clips player from your own button, link, or route instead of a\ntile. These methods are on `Storyteller.sharedInstance`. Each one returns a\npromise that rejects when the SDK can't open the content. Call them after\n`initialize` resolves.\n\n```javascript\nconst openFeaturedStory = async () => {\n try {\n await Storyteller.sharedInstance.openStory('story-id');\n } catch (error) {\n console.error('The Story could not be opened.', error);\n }\n};\n\ndocument\n .getElementById('featured-story-button')\n ?.addEventListener('click', openFeaturedStory);\n```\n\nThe SDK first looks for the content in the views on your page and opens it in\nthat view's player. It uses only views whose player URLs are turned on, which\nmeans the `disableUrls` [theme setting](Themes.md) is `false`. If no view on\nthe page has the content, the SDK loads it from Storyteller and opens it in a\nplayer that it creates over your page. Either way, the SDK opens the player by setting the page's hash\nURL, such as `#stories/story-id`, and the promise resolves at that point. See\n[`basename`](StorytellerListView.md#basename) for the URL format.\n\n## Open a content URL {#open-a-content-url}\n\n`openDeepLink` opens a Storyteller share link, or a custom-scheme link from\nyour app, in the right player. Call it after `initialize` resolves:\n\n```javascript\nconst openContentUrl = async (contentUrl) => {\n try {\n const handled = await Storyteller.sharedInstance.openDeepLink(contentUrl, {\n context: { location: 'home', module: 'related-content' },\n });\n\n if (!handled) {\n // Not a Storyteller content URL. Handle it yourself.\n }\n } catch (error) {\n console.error('The content could not be opened.', error);\n }\n};\n```\n\nThe promise:\n\n- resolves to `false` when the URL isn't a supported Storyteller link. Nothing\n opens.\n- resolves to `true` once the SDK has found the content and opened the player\n route. The player then renders.\n- rejects when the content can't be loaded\n\nIf another `openDeepLink` call or a browser navigation starts while the SDK is\nstill loading content for an earlier call, the earlier call doesn't open its\ncontent and doesn't change the newer route or its context. Its promise still\nresolves to `true`, or rejects if its content can't be loaded.\n\nTo check a URL without opening it, call `Storyteller.parseDeepLink(contentUrl)`.\nIt returns the destination, or `null` for an unsupported URL, and doesn't load\ncontent or change the page. See [`DeepLink`](reference/types.md#deeplink) for\nthe destination fields.\n\n### Supported URL formats\n\nThe SDK accepts:\n\n- HTTP and HTTPS URLs on `storyteller.com`, `shar.estori.es`, or\n `ope.nstori.es`, including their subdomains\n- URLs with a custom scheme that ends in `stories`, such as\n `tenantstories://`\n- hash routes, on their own or at the end of an HTTP or HTTPS URL on any\n host, such as your own site. When an HTTP or HTTPS URL has a fragment, the\n SDK reads only the fragment.\n\nIn a custom-scheme URL, the SDK ignores the part between `://` and the next\n`/`. Put a word such as `open` there, then the content path:\n`tenantstories://open/clip/clip-id`.\n\nBefore it reads the content path, the SDK removes a leading `/go`, `/open`,\nor `/page/meta`. Query parameter names are case-insensitive, so\n`collectionId` and `collectionid` both work.\n\nContent paths, for Storyteller hosts and custom schemes:\n\n| Path | Opens |\n| --- | --- |\n| `/story-id` | The Story with this ID |\n| `/story-id/page-id` | The Page, or the Story if the Page can't be opened |\n| `/story-id/page-id/answer-id` | The Page. `parseDeepLink` returns `answerId`, but opening uses only the Page. |\n| `/stories/story-external-id` | The Story with this external ID |\n| `/category/category-id` | The Story Category |\n| `/clip/clip-id` | The Clip with this ID |\n| `/clip/clip-id?collectionId=collection-id` | The Clip in that collection |\n| `/clip?collectionId=collection-id` | The collection |\n| `/clip?collectionId=collection-id&categoryId=category-id` | The Clip Category in that collection |\n| `/clip/clip-id?collectionId=collection-id&categoryId=category-id` | The Clip Category in that collection. The SDK ignores the Clip ID in this format. |\n| `/clips/clip-external-id` | The Clip with this external ID. Storyteller finds its collection. |\n| `/clips/clip-external-id?collectionId=collection-id` | The Clip with this external ID in that collection |\n\nIf a Page link can't open its Page, the SDK opens its Story instead. The\npromise rejects if that Story also fails to open. A Clip Category link\nwithout `collectionId` rejects.\n\nA content path opens a Clip Category instead of a Clip when it has both a\nClip ID and a `categoryId`. `openCollection` works the other way round: when\nyou pass both, `clipId` takes priority. To open a Clip within a Clip\nCategory from a link, use the hash route\n`#clips/collection-id/clip-id?category=category-id`.\n\n`parseDeepLink` returns `null`, and `openDeepLink` resolves to `false`, for\nmalformed URLs and for paths that don't match a format in these tables, such\nas paths that start with `/sheet`, `/profile`, or `/search`.\n\nHash routes, on their own or after any HTTP or HTTPS URL:\n\n| Hash | Opens |\n| --- | --- |\n| `#stories/story-id` | The Story |\n| `#stories/story-id/page-id` | The Page in that Story |\n| `#stories/story-id?categoryId=category-id` | The Story in that Story Category |\n| `#stories/story-id/page-id?categoryId=category-id` | The Page, in that Story and Story Category |\n| `#clips/collection-id` | The collection |\n| `#clips/collection-id/clip-id` | The Clip in that collection |\n| `#clips/collection-id?category=category-id` | The Clip Category in that collection |\n| `#clips/collection-id/clip-id?category=category-id` | The Clip, in that Clip Category and collection |\n\nStory and Page hashes name the category with `categoryId`. Clips hashes use\n`category`. When a hash has both a content ID and a category, the SDK opens\nthe content within that category, and the promise rejects if the content\nisn't in the category.\n\nIDs in any of these URLs can be percent-encoded. The SDK decodes each ID\nonce, so don't encode an ID twice.\n\nThe SDK opens the content the same way as the `open` methods below: in the\nplayer of a view on your page that has the content, or in a player that it\ncreates over your page.\n\n### Placement context\n\nPass `context` to attach placement data to the analytics events of the\ncontent you open. The SDK returns it in `data.context` to your\n[`onUserActivityOccurred`](StorytellerDelegate.md#onuseractivityoccurred)\ncallback and doesn't send it to Storyteller. See\n[placement context](Analytics.md#context).\n\n- With `context`, that value replaces the selected view's configured context\n for this opening.\n- Without the option, the SDK uses the selected view's configured context. A\n player that the SDK creates, because no view on the page has the content,\n has no configured context.\n- Each opening replaces the temporary context from the previous call.\n\nFull signature: [`openDeepLink`](AdditionalMethods.md#opendeeplink).\n\n## Open a Story {#open-a-story}\n\n### openStory\n\nOpens a Story by its ID.\n\n```javascript\nawait Storyteller.sharedInstance.openStory('story-id');\n```\n\nFull signature: [`openStory`](AdditionalMethods.md#openstory).\n\n### openStoryByExternalId\n\nOpens a Story by its external ID.\n\n```javascript\nawait Storyteller.sharedInstance.openStoryByExternalId('story-external-id');\n```\n\nFull signature:\n[`openStoryByExternalId`](AdditionalMethods.md#openstorybyexternalid).\n\n### openPage\n\nOpens the Story that contains a Page, starting at that Page.\n\n```javascript\nawait Storyteller.sharedInstance.openPage('page-id');\n```\n\nFull signature: [`openPage`](AdditionalMethods.md#openpage).\n\n### openCategory\n\nOpens the Story player for a Category. Pass a Story ID as the second argument\nto start at that Story; otherwise, the first Story in the Category opens.\n\n```javascript\nawait Storyteller.sharedInstance.openCategory('category-id', 'story-id');\n```\n\nFull signature: [`openCategory`](AdditionalMethods.md#opencategory).\n\n## Open Clips {#open-clips}\n\n### openCollection\n\nOpens the Clips player for a collection. Pass a `destination` to start at a\nClip, or at the first Clip in a Clip Category. Otherwise, the first Clip in the\ncollection opens.\n\n```javascript\nawait Storyteller.sharedInstance.openCollection('collection-id');\n\nawait Storyteller.sharedInstance.openCollection('collection-id', {\n clipId: 'clip-id',\n});\n\nawait Storyteller.sharedInstance.openCollection('collection-id', {\n categoryId: 'clip-category-id',\n});\n```\n\nIf you pass both `clipId` and `categoryId`, `clipId` takes priority. The\nplayer opens the Category only when the Clip isn't in the collection.\n\nThe third argument sets the opening reason in analytics events, and accepts\nonly `Storyteller.OpenedReason.deepLink`. Without it, the `openedClip` event\nfor the first Clip still reports `openedReason: deepLink`, unless the player\nopens on a Category (`destination.categoryId`), which reports\n`categoryListTap`. Pass `deepLink` when the user arrived through a deep link,\nso that a Category open reports `deepLink` too. `openDeepLink` always passes\nit.\n\n```javascript\nawait Storyteller.sharedInstance.openCollection(\n 'collection-id',\n { categoryId: 'clip-category-id' },\n Storyteller.OpenedReason.deepLink\n);\n```\n\nFull signature: [`openCollection`](AdditionalMethods.md#opencollection).\n\n### Start on the Following feed {#initial-feed}\n\nA Clips player can show two feeds as tabs: For You and Following. Pass\n`initialFeed: 'following'` to open the collection on its Following feed. The tab labels come from your theme, so yours may differ.\nThe default is `'forYou'`.\n\n```javascript\nawait Storyteller.sharedInstance.openCollection('collection-id', {\n initialFeed: 'following',\n});\n```\n\n- A `clipId` or `categoryId` in the same `destination` takes priority. The\n player opens that Clip or Category and logs a warning that it ignored\n `initialFeed`.\n- If the collection doesn't have Following turned on, the player opens For\n You and logs a warning. The promise doesn't reject.\n- If the user follows nothing, Following shows its themed empty state.\n- For You loads behind Following, so the user can switch back.\n- The option applies to this call only. The SDK doesn't remember which feed\n the user last selected.\n\nCall `enableLogging` to see the warnings in the browser console.\n\nEvents report the same opening reason as they would on For You, and the SDK\nsends no extra event for the feed. When the player opens on Following, the\nfirst `openedClip` event has `clipFeedType: 'following'`.\n\n`openDeepLink` starts on Following for collection links with\n`feed=following`:\n\n```text\nhttps://storyteller.com/go/clip?collectionId=collection-id&feed=following\ntenantstories://open/clip?collectionId=collection-id&feed=following\n#clips/collection-id?feed=following\n```\n\nThe `feed` parameter name and its value are case-insensitive. Any other value\nopens For You. A Clip or Category in the link still takes priority, and the\n[supported URL formats](#supported-url-formats) still apply.\n\nFor a `StorytellerClipsPlayerView` or `StorytellerEmbeddedClipsPlayerView`,\nuse the [`initialFeed` configuration](StorytellerEmbeddedClipsPlayerView.md#initial-feed)\ninstead.\n\n### openClipByExternalId\n\nOpens the Clips player for a collection, at the Clip with this external ID.\n\n```javascript\nawait Storyteller.sharedInstance.openClipByExternalId(\n 'collection-id',\n 'clip-external-id'\n);\n```\n\nFull signature:\n[`openClipByExternalId`](AdditionalMethods.md#openclipbyexternalid).\n\n## Close the player {#close-the-player}\n\nCall `dismissPlayer` to close Storyteller content, for example when your\napplication navigates away. Pass `true` to play the close animation.\n\n```javascript\nStoryteller.sharedInstance.dismissPlayer(true);\n```\n\nThe call closes the Story or Clips player open over your page and any\n`StorytellerClipsPlayerView` on the page, together when both are showing. It\ndoesn't close a `StorytellerEmbeddedClipsPlayerView`. If neither a player nor\na `StorytellerClipsPlayerView` is showing, the call does nothing, so you don't\nneed to check first.\n\nDon't use [`isPresentingContent`](AdditionalMethods.md#ispresentingcontent)\nto decide whether to call it. That property counts only players open over\nyour page, so it is `false` while a `StorytellerClipsPlayerView` is the only\ncontent showing.\n\nFull signature: [`dismissPlayer`](AdditionalMethods.md#dismissplayer).\n\n## Player sound {#player-sound}\n\nWhether Stories and Clips start with sound, and whether the SDK remembers the\nuser's choice, come from your tenant's player settings in Storyteller. There\nis nothing to set in code. Ask your Storyteller contact to change them.\n\nStories and Clips each have their own starting state: sound on, sound off, or\nfollow the device silent switch. Browsers can't read a silent switch, so that\noption starts muted. When your tenant sets no starting state, Clips start\nwith sound and Stories start muted.\n\nWhen the user mutes or unmutes a Story or Clip, the next Story or Clip starts\nthe same way until the page reloads. A Story player keeps the choice as the\nuser moves between Stories.\n\nIf your settings keep the user's choice, the SDK saves it in the browser as\n`Storyteller.playerMuted`, and later visits start with the saved choice\ninstead of the default. The SDK saves it only when `enableFunctionalCookies`\nis `true`, and removes it when your settings stop keeping the choice. See\n[Functional cookies and local storage items](PrivacyAndTracking.md#functional-cookies-and-local-storage-items).\n\nBrowsers can block playback with sound until the user interacts with the\npage, for example when a deep link opens a player as the page loads. The\nStory or Clip then plays muted, and the user can unmute it. The SDK doesn't\nsave a mute that the browser forced as the user's choice.\n\nRead the current state with\n[`isPlayerMuted`](AdditionalMethods.md#isplayermuted).\n\n## Handle errors {#handle-errors}\n\nWrap each call in `try`/`catch`, or add `.catch()`, so that a rejected promise\ndoesn't go unhandled. The rejection value can be an `Error` or a string.\n\n| Method | When the content is missing |\n| --- | --- |\n| `openDeepLink` | Resolves to `false` when the URL isn't a supported Storyteller link. Rejects when the content can't be loaded, or a Clip Category URL has no collection. |\n| `openStory`, `openStoryByExternalId` | Rejects when the Story request fails, or with a string when no Story has the ID. |\n| `openPage` | Rejects when the SDK can't load a Story that contains the Page. |\n| `openCategory` | Rejects when the SDK can't load the Category, or the Category has no Stories. If `storyId` isn't in the Category, the first Story opens instead. |\n| `openCollection` | Rejects when the SDK can't load the collection, or the collection has no Clips. If the `destination` Clip or Category isn't in the collection, the first Clip opens instead. |\n| `openClipByExternalId` | Rejects when the SDK can't load the collection, or with a string when the collection has no Clip with the external ID. |\n\nWhen the SDK opens the first Story or Clip instead of the one you asked for,\nit logs a message. Call `enableLogging` to see it in the browser console.\n\n## Next steps\n\n- [Use additional SDK methods](AdditionalMethods.md): full signatures for every method on this page\n- [Integrate analytics](Analytics.md): the events that each player sends when it opens\n- [Configure views](StorytellerListView.md#basename): hash URLs and `basename`\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}