Skip to content

Callbacks#

The SDK reports events and asks for ad settings through delegate objects. You set one global delegate on Storyteller.sharedInstance, and you can set a delegate on each view. Every callback is optional. For setup steps, see Handle delegates and callbacks.

Delegate interfaces#

The SDK defines three delegate interfaces:

Interface Set it on Callbacks
IStorytellerDelegate Storyteller.sharedInstance.delegate onUserActivityOccurred, onShareButtonTapped, getAdConfig, getBottomBannerAdConfig, userNavigatedToApp, categoryFollowActionTaken, onPlayerPresented, onPlayerDismissed
IListViewDelegate The delegate of a Stories or Clips row or grid onDataLoadStarted, onDataLoadComplete, onPlayerDismissed, onTileTapped
IStorytellerClipsPlayerDelegate The delegate of a StorytellerClipsPlayerView or StorytellerEmbeddedClipsPlayerView The IListViewDelegate callbacks, plus onTopLevelBackTapped

Assigning a delegate object replaces the previous one, so include every callback that you need in each assignment.

IStorytellerDelegate#

Callback availability#

Version Global callbacks
10.0.0–10.5.x Three: onUserActivityOccurred, onShareButtonTapped, getAdConfig
10.6.0–11.0.2 The same three, plus userNavigatedToApp (four total)
11.1.0 The same four, plus getBottomBannerAdConfig, categoryFollowActionTaken, onPlayerPresented and onPlayerDismissed (eight total)

Assigning a new delegate replaces the callbacks supported by that SDK version. The getAdConfig TypeScript member was required in 10.0.0 and became optional in 10.1.0.

interface IStorytellerDelegate {
  onUserActivityOccurred?: (
    type: ActivityType,
    data: UserActivityData
  ) => void;
  onShareButtonTapped?: (
    text: string,
    title: string,
    url: string
  ) => Promise<void>;
  getAdConfig?: (
    adRequestInfo: StorytellerAdRequestInfo
  ) => AdConfig | null;
  getBottomBannerAdConfig?: (
    adRequestInfo: StorytellerBottomBannerAdRequestInfo
  ) => BottomBannerAdConfig | null;
  userNavigatedToApp?: (url: string) => void;
  categoryFollowActionTaken?: (
    category: StorytellerCategory,
    isFollowing: boolean
  ) => void;
  onPlayerPresented?: () => void;
  onPlayerDismissed?: () => void;
}

The global delegate handles events from every Story player and Clips player on the page.

Storyteller.sharedInstance.delegate = {
  onUserActivityOccurred: (type, data) => {
    console.log(type, data.context);
  },
};

onUserActivityOccurred#

onUserActivityOccurred?: (type: ActivityType, data: UserActivityData) => void

Called for each analytics event. The SDK ignores the return value.

Parameter Type Description
type ActivityType The event name, such as openedStory
data UserActivityData The event properties. Each event page lists the properties that it sets

The privacy options control the callback:

  • The callback runs only when enableUserActivityTracking is true
  • Ad events reach the callback only when enableAdTracking is true
  • When enableFullVideoAnalytics is false, the SDK sets storyId, storyTitle, storyDisplayTitle, pageId, pageTitle, clipId, and clipTitle to null

data.context holds the view's configuration.context, unless that value is undefined. Assign the delegate before initialize to receive the sdkInitialized event.

onShareButtonTapped#

onShareButtonTapped?: (
  text: string,
  title: string,
  url: string
) => Promise<void>

Called when a user taps the link share button in the Story player or the Clips player. Implement it to replace the browser share sheet.

Parameter Type Description
text string Share text. For a Story, the share text of a poll or quiz Page, and an empty string on other Pages. For a Clip, the Clip description, the same value as title
title string Share title. For a Story, the Story title. For a Clip, the Clip description
url string The link to share

The player pauses while the share runs. What happens next depends on the callback:

  • Promise resolves: the SDK records the shareSuccess event and resumes playback
  • Promise rejects: the SDK resumes playback. It records no shareSuccess event and doesn't call navigator.share
  • Missing, throws, or returns no promise: the SDK calls navigator.share instead

The share button appears only in browsers that support navigator.share. Story Pages set up to share their image or video file download it and don't call this callback.

getAdConfig#

getAdConfig?: (adRequestInfo: StorytellerAdRequestInfo) => AdConfig | null

Called before an ad request when Storyteller serves ads from your app (Google Ad Manager). In any other ad setup, the SDK doesn't call it. For other ad servers, ask your Storyteller contact.

Parameter Type Description
adRequestInfo StorytellerAdRequestInfo The Story or Clip context of the ad slot

Return an ad configuration, or null to send no ad request. The SDK uses this shape of the declared AdConfig union:

interface IntegratingAppAdConfig {
  type?: 'doubleclick';
  slot: string;
  customTargeting?: AdTargeting;
  publisherProvidedId?: string | null;
}

interface AdTargeting {
  [index: string]: string | string[];
}
Field Type Required Description
slot string Yes Google Ad Manager ad unit, in the form /[NETWORK_CODE]/[UNIT_CODE]. A configuration without slot is not valid
customTargeting AdTargeting No Key-value pairs for the ad request. Values are strings or arrays of strings
publisherProvidedId string or null No Publisher Provided ID (PPID). The SDK trims whitespace and omits an empty value
type 'doubleclick' No Ad server type

The SDK adds its default targeting keys and lets your customTargeting values override them. When enableAdTracking is false, the SDK omits its default keys and publisherProvidedId, and still sends your customTargeting.

AdConfig and AdTargeting are not exported by name. The declared AdConfig union also includes { type: 'custom'; remoteUrl: string }, which the SDK uses for Storyteller first-party ads. The SDK ignores that shape when your delegate returns it.

getBottomBannerAdConfig#

getBottomBannerAdConfig?: (
  adRequestInfo: StorytellerBottomBannerAdRequestInfo
) => BottomBannerAdConfig | null

Called when a Clip in the Clips player can show a bottom banner. Return the Google Ad Manager banner unit and the sizes it accepts, or null to show no banner.

Parameter Type Description
adRequestInfo StorytellerBottomBannerAdRequestInfo The collection and the categories of the Clip
  • Returns: a BottomBannerAdConfig with a slot and a size, or null. Return it synchronously. The SDK requests only the sizes that fit the player. When the configuration isn't valid or the callback throws, the SDK shows no banner

The banner shows only when all four of these are in place:

  1. Storyteller sets your tenant to serve ads from your app (Google Ad Manager), as for getAdConfig, and turns on showBottomBannerAd for the app or collection. Ask your Storyteller contact.
  2. The Clips view's configuration sets adConfiguration.bottomBannerEnabled to true. Players that the SDK creates for openCollection, openClipByExternalId, or openDeepLink without a matching view on the page never show the banner.
  3. This callback returns a valid configuration. It needs a slot and a size. If you set type, it must be 'doubleclick'.
  4. Your page loads Google Publisher Tag (GPT) and calls googletag.setConfig({ disableInitialLoad: true }).

The SDK calls this callback only when the first two hold.

When enableAdTracking is false, the banner request sends no custom targeting at all: neither the SDK's default keys nor your customTargeting. The bottom banner guide covers the GPT setup, the supported players, and the layout limits.

userNavigatedToApp#

userNavigatedToApp?: (url: string) => void

Called when a user taps an in-app action on a Story Page or a Clip. Implement it to route the URL inside your application. Without this callback, in-app actions open like regular URLs.

Parameter Type Description
url string The action URL set in the Storyteller CMS

categoryFollowActionTaken#

categoryFollowActionTaken?: (
  category: StorytellerCategory,
  isFollowing: boolean
) => void

Called after a user follows or unfollows a category with the follow button in the Clips player, once the SDK has stored the change. Use it to update your own list of followed categories. The SDK calls it only when your tenant uses app-managed following, and never with Storyteller-managed following.

Parameter Type Description
category StorytellerCategory The category that the user followed or unfollowed
isFollowing boolean true after a follow, false after an unfollow

onPlayerPresented#

onPlayerPresented?: () => void

Called when a Story or Clips player opens over your page, as isPresentingContent turns true. Use it to pause your page's own media, for example.

  • The SDK doesn't call it again while an action in the player replaces the content, or while a Category screen opens inside the Clips player
  • When an open method or openDeepLink opens content in a different player, the SDK closes the open player first. You get onPlayerDismissed, then onPlayerPresented
  • StorytellerClipsPlayerView and StorytellerEmbeddedClipsPlayerView don't call it

The SDK catches and logs an error that the callback throws.

onPlayerDismissed#

onPlayerDismissed?: () => void

Called when the last open Story or Clips player closes, as isPresentingContent turns false. Use it to resume your page's own media, for example.

Every way of closing a player calls it once, including dismissPlayer and an open method or openDeepLink call that opens content in a different player. The SDK catches and logs an error that the callback throws.

The view delegate has its own onPlayerDismissed, which the SDK calls only for a player that the view opened.

IListViewDelegate#

interface IListViewDelegate {
  onDataLoadStarted?: () => void;
  onDataLoadComplete?: (
    success: boolean,
    error: Error | null,
    dataCount: number
  ) => void;
  onPlayerDismissed?: () => void;
  onTileTapped?: (tile: StorytellerTileData) => void;
}

A view delegate handles events from one view. The SDK fills callbacks that you leave out with no-op functions.

const storyRow = new Storyteller.StorytellerStoriesRowView('stories-row-id');

storyRow.delegate = {
  onDataLoadStarted: () => console.log('Loading Stories'),
  onDataLoadComplete: (success, error, dataCount) => {
    console.log(success, error, dataCount);
  },
};
  • Since: 10.0.0 renamed onStoriesDataLoadStarted to onDataLoadStarted and onStoriesDataLoadComplete to onDataLoadComplete
  • Guide: Handle view callbacks

onDataLoadStarted#

onDataLoadStarted?: () => void

Called each time the view starts loading its content. The first load starts inside the constructor, before you can assign a delegate, so your delegate never receives that first call. Show your loading state before you create the view.

Later calls happen after a source change (categories, collection, clipId, or externalId), on reloadData, and when a Clips row or grid reloads after its player closes. That reload happens only when the collection's settings from Storyteller order watched Clips and reload the view on exit, and the user has watched a Clip.

onDataLoadComplete#

onDataLoadComplete?: (
  success: boolean,
  error: Error | null,
  dataCount: number
) => void

Called when the content request finishes.

Parameter Type Description
success boolean true when the request succeeded. false when it failed or returned no Stories or Clips
error Error or null null on success. On failure, the request error. When the failure is not an Error, the SDK passes an Error with the message Network Error
dataCount number Stories views: the number of Stories loaded. Clips views: the number of Clips in the first page. Single-Clip players: 1. 0 on failure

Later Clips pages load as users reach the end of the content, and they do not call this callback. See Clips paging.

An automatic refresh that finds new content calls this callback without calling onDataLoadStarted first. A refresh that finds the same content calls neither.

In a Clips player with the For You and Following tabs, this callback and onDataLoadStarted report only the For You load. Following loads, including failed ones, don't call them.

onPlayerDismissed#

onPlayerDismissed?: () => void

Called when the Story or Clips player that the view opened is dismissed. For a StorytellerClipsPlayerView, it is also called when dismissPlayer closes the view. A tap on the Clips player top-level back button calls onTopLevelBackTapped instead.

onTileTapped#

onTileTapped?: (tile: StorytellerTileData) => void

Called once each time a user activates a Story or Clip tile in a row or grid by mouse, touch, or keyboard, before the player opens. A click with a modifier key, such as Ctrl-click, opens the tile in a new tab or window and doesn't call it.

Parameter Type Description
tile StorytellerTileData The tapped Story or Clip, its one-based tileIndex, its categories, and its CMS metadata

To handle taps yourself, set the theme property lists.enablePlayerOpen to false. The SDK then opens nothing, and every click calls onTileTapped, including modified clicks. The SDK catches and logs an error that the callback throws.

IStorytellerClipsPlayerDelegate#

interface IStorytellerClipsPlayerDelegate extends IListViewDelegate {
  onTopLevelBackTapped?: () => void;
}

The delegate of StorytellerClipsPlayerView and StorytellerEmbeddedClipsPlayerView. It supports the IListViewDelegate callbacks. A Clips player has no tiles, so it never calls onTileTapped.

onTopLevelBackTapped#

onTopLevelBackTapped?: () => void

Called when a user taps the top-level back button. The button shows only when topLevelBackButtonEnabled is true. Without this callback, the SDK calls window.history.back().

clipPlayer.topLevelBackButtonEnabled = true;
clipPlayer.delegate = {
  onTopLevelBackTapped: () => {
    window.history.back();
  },
};