Skip to content

Open a player programmatically#

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.

const openFeaturedStory = async () => {
  try {
    await Storyteller.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 disableUrls theme 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.

Open a content URL#

openDeepLink opens a Storyteller share link, or a custom-scheme link from your app, in the right player. Call it after initialize resolves:

const openContentUrl = async (contentUrl) => {
  try {
    const handled = await Storyteller.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.

Supported URL formats#

The SDK accepts:

  • 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.
/stories/story-external-id The Story with this external ID
/category/category-id The Story Category
/clip/clip-id The Clip with this ID
/clip/clip-id?collectionId=collection-id The Clip in that collection
/clip?collectionId=collection-id The collection
/clip?collectionId=collection-id&categoryId=category-id The Clip Category in that collection
/clip/clip-id?collectionId=collection-id&categoryId=category-id The Clip Category in that collection. The SDK ignores the Clip ID in this format.
/clips/clip-external-id The Clip with this external ID. Storyteller finds its collection.
/clips/clip-external-id?collectionId=collection-id The Clip with this external ID in that collection

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.

Placement context#

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.

Full signature: openDeepLink.

Open a Story#

openStory#

Opens a Story by its ID.

await Storyteller.sharedInstance.openStory('story-id');

Full signature: openStory.

openStoryByExternalId#

Opens a Story by its external ID.

await Storyteller.sharedInstance.openStoryByExternalId('story-external-id');

Full signature: openStoryByExternalId.

openPage#

Opens the Story that contains a Page, starting at that Page.

await Storyteller.sharedInstance.openPage('page-id');

Full signature: openPage.

openCategory#

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.

await Storyteller.sharedInstance.openCategory('category-id', 'story-id');

Full signature: openCategory.

Open Clips#

openCollection#

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.

await Storyteller.sharedInstance.openCollection('collection-id');

await Storyteller.sharedInstance.openCollection('collection-id', {
  clipId: 'clip-id',
});

await Storyteller.sharedInstance.openCollection('collection-id', {
  categoryId: 'clip-category-id',
});

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.

await Storyteller.sharedInstance.openCollection(
  'collection-id',
  { categoryId: 'clip-category-id' },
  Storyteller.OpenedReason.deepLink
);

Full signature: openCollection.

Start on the Following feed#

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'.

await Storyteller.sharedInstance.openCollection('collection-id', {
  initialFeed: 'following',
});
  • 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:

https://storyteller.com/go/clip?collectionId=collection-id&feed=following
tenantstories://open/clip?collectionId=collection-id&feed=following
#clips/collection-id?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.

openClipByExternalId#

Opens the Clips player for a collection, at the Clip with this external ID.

await Storyteller.sharedInstance.openClipByExternalId(
  'collection-id',
  'clip-external-id'
);

Full signature: openClipByExternalId.

Close the player#

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.

Full signature: dismissPlayer.

Player sound#

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.

Read the current state with isPlayerMuted.

Handle errors#

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.

Next steps#