Web SDK

This guide describes how to add and use StorySDK to your site or web app.

SDK token

To get SDK token go to app settings page and copy SDK token:

Installation

NPM

Yarn

Basic Usage

Please note: StorySDK Core is built on React and requires it to be present in your project. React is NOT bundled with the library, including the CDN version.

Dependencies

StorySDK will not work without React. It relies on React for rendering components and uses React hooks internally.

React

To integrate StorySDK in a React application:

Next.js

When using StorySDK with Next.js, you need to load the component dynamically without server-side rendering:

Then in your component file (components/StoryComponent.js):

JavaScript (ES6)

For vanilla JavaScript applications:

Static HTML

Important: React is NOT included in the CDN bundle. You need to include React and ReactDOM separately before loading StorySDK.

For static HTML pages:

Shopify (Liquid)

StorySDK can be easily integrated into your Shopify store using theme sections. Follow these steps:

  1. Add the following code to the <head> tag of your Shopify theme:

  1. Create a section for StorySDK integration in your theme customizer:

This implementation allows you to:

  • Add StorySDK to your Shopify theme through the theme customizer

  • Configure your StorySDK token and container height directly from the Shopify admin

  • Place the StorySDK container anywhere in your store through the theme editor

Available Parameters

By specifying the following data attributes in the HTML tag, you can control the appearance, behavior, and functionality of the SDK directly from HTML without additional JavaScript configuration.

Parameter
Description

data-storysdk-group-image-width

Specifies the width of the group image in pixels, controlling how large the group's main image will appear.

data-storysdk-group-image-height

Sets the height of the group image, allowing you to control the image's vertical display size.

data-storysdk-group-title-size

Adjusts the font size of the group title, so you can set the desired emphasis for the group title text.

data-storysdk-group-class-name

Allows a custom CSS class to be applied to the individual group elements. Use this to apply unique styling to each group.

data-storysdk-groups-class-name

Adds a custom CSS class to the container for multiple groups. This is useful for controlling overall styling for the collection of groups.

data-storysdk-autoplay

Enables autoplay for stories if set to "true". The stories will play automatically without requiring user interaction.

data-storysdk-group-id

Identifies a specific group ID to load within the SDK, allowing targeted display of group content when autoplay is enabled.

data-storysdk-start-story-id

Sets the initial story to display when the SDK opens, letting you direct users to a specific story.

data-storysdk-forbid-close

Prevents users from closing the SDK interface if set to "true". Useful for mandatory viewing scenarios.

data-storysdk-is-show-mockup

Displays the story content within a device mockup if set to "true", providing a preview within a simulated device frame.

data-storysdk-is-status-bar-active

Activates a status bar at the top of the story if set to "true", helping indicate story progress.

data-storysdk-open-in-external-modal

Opens stories within an external modal if set to "true". This is useful if you want to display content in a standalone modal overlay.

data-storysdk-groups-outline-color

Specifies a custom outline color for groups. This is useful for visually highlighting or differentiating specific groups within the interface.

data-storysdk-active-group-outline-color

Specifies a custom outline color for the active group or for the group when hovered over. This helps emphasize the currently selected or focused group in the interface.

Example Implementation

⚡️ Please note that in order for stories to be displayed in the SDK, they need to be published.

API Reference

Story Class

The main class for interacting with the StorySDK.

Constructor

Parameters:

  • token (string, required): Your application token provided by StorySDK

  • options (object, optional): Configuration options for StorySDK

Options

Methods

renderGroups(container)

Renders story groups in the specified element.

Parameters:

  • container (HTMLElement, optional): The DOM element to render stories in. If not provided, the container specified during initialization will be used.

Returns: void

destroy()

Cleans up resources used by the Story instance, unmounting React components.

Returns: void

on<T = any>(eventName, listener)

Subscribes to a story event.

Parameters:

  • eventName (StoryEventTypes): Name of the event to subscribe to

  • listener (function): Callback function to execute when the event occurs

Returns: Function to unsubscribe from the event

off<T = any>(eventName, listener)

Removes a specific event listener.

Parameters:

  • eventName (StoryEventTypes): Name of the event

  • listener (function): The listener function to remove

Returns: void

once<T = any>(eventName, listener)

Subscribes to an event for one time only. The listener automatically unsubscribes after being called once.

Parameters:

  • eventName (StoryEventTypes): Name of the event to subscribe to

  • listener (function): Callback function to execute when the event occurs

Returns: Function to unsubscribe from the event

Event Handling

StorySDK uses a TypeScript-based event system for handling interactions with stories. You can subscribe to these events using the on method:

Available Events

StorySDK provides the following event types:

  • groupClose: When a story group is closed (provides group ID, user ID, viewing duration in seconds, and language)

  • groupOpen: When a story group is opened (provides user ID, group ID, start time, and language)

  • storyClose: When a story is closed (provides group ID, story ID, user ID, viewing duration, and language)

  • storyOpen: When a specific story is opened (provides group ID, story ID, user ID, and language)

  • storyNext: When navigating to the next story (provides group ID, story ID, user ID, and language)

  • storyPrev: When navigating to the previous story (provides group ID, story ID, user ID, and language)

  • widgetAnswer: When a user responds to an interactive widget (polls, quizzes, etc.)

  • widgetClick: When a widget within a story is clicked (buttons, links, swipe up actions)

Widget Click Event

The widgetClick event is fired when a user interacts with clickable elements in a story. The event provides detailed information about the interaction through its payload.

Event Structure

Example Usage

Implementation Notes

  • Button widgets include an actionType field and may contain customFields for additional context

  • Link widgets provide the target URL in the data.url field

  • Swipe up actions are similar to links but represent a different user interaction pattern

  • All widget events include user, story, and widget identifiers for comprehensive tracking

Widget Answer Event

The widgetAnswer event is fired when a user responds to an interactive widget. This event provides data about the user's response.

Supported Widget Types

The widgetAnswer event is available for the following widget types:

Event Structure

Example Usage

Implementation Notes

  • The widget field identifies the specific type of interactive element from the WidgetTypes enum

  • The answer field can contain various data types depending on the widget (string, number, object, array)

  • This event is useful for:

    • Collecting user feedback

    • Building personalization features

    • Creating dynamic, interactive story experiences

    • Analyzing user engagement with interactive elements

Group Open Event

The groupOpen event is fired when a user opens a story group. This event provides information about which group was opened and by whom.

Event Structure

Example Usage

Implementation Notes

  • The startTime is provided as a numeric timestamp which can be converted to a Date object

  • The language field can be used for analytics or to ensure proper localization

  • This event is typically paired with groupClose to track complete interaction sessions

  • This event is useful for:

    • Monitoring which story groups are most popular

    • Analyzing user behavior patterns

    • Building recommendation engines based on user preferences

Group Close Event

The groupClose event is fired when a user closes a story group. This event provides information about which group was closed and how long the user interacted with it.

Event Structure

Example Usage

Implementation Notes

  • The duration is provided in seconds, useful for calculating engagement metrics

  • This event complements the groupOpen event for complete session analysis

  • Comparing duration across different groups can help identify the most engaging content

  • This event is useful for:

    • Measuring content effectiveness

    • Identifying drop-off points in user flows

    • Optimizing story sequences based on engagement patterns

    • Building analytics dashboards for content performance

Story Open Event

The storyOpen event is fired when a user opens an individual story within a group. This event provides information about which specific story was opened.

Event Structure

Example Usage

Implementation Notes

  • This event is fired at the individual story level, as opposed to the group level

  • It contains both the story ID and its parent group ID for hierarchical tracking

  • A single user session will typically trigger multiple story open events as the user progresses

  • This event is useful for:

    • Analyzing navigation patterns within story groups

    • Building progression funnels to identify drop-off points

    • Tracking which individual stories drive user engagement

    • Creating personalized experiences based on story viewing history

Story Close Event

The storyClose event is fired when a user finishes viewing an individual story. This event provides information about which story was viewed and for how long.

Event Structure

Example Usage

Implementation Notes

  • The duration field indicates how long the user viewed the story in seconds

  • This event complements the storyOpen event for complete story viewing analysis

  • Short durations may indicate skipped or unengaging content

  • This event is useful for:

    • Determining which stories hold user attention the longest

    • Calculating completion rates for individual stories

    • Refining content based on viewing patterns

    • Building detailed analytics for story-level engagement

Story Next Event

The storyNext event is fired when a user navigates to the next story in a sequence. This event helps track user navigation patterns.

Event Structure

Example Usage

Story Previous Event

The storyPrev event is fired when a user navigates to the previous story in a sequence. This event helps identify when users revisit content.

Event Structure

Example Usage

Implementation Notes for Navigation Events

  • Both storyNext and storyPrev events have identical structures but represent different navigation actions

  • The storyId in these events refers to the story being navigated TO (not from)

  • High rates of backward navigation may indicate confusing content or users reviewing important information

  • These events are useful for:

    • Creating flow diagrams of user navigation patterns

    • Identifying content that users frequently revisit

    • Optimizing story sequences based on navigation behavior

    • Understanding how users interact with story sequences

Styling & Customization

HTML Data Attributes

You can configure StorySDK using HTML data attributes in static HTML implementations:

Custom CSS Classes

Apply custom styling using the provided class name options:

Then in your CSS:

Troubleshooting

Debug Mode

Enable debug mode to see detailed logging of API requests and responses:

With debug mode enabled:

  • API requests and responses will be logged to the console

  • If a #storysdk-debug element exists in your DOM, debug information will be appended there

Common Issues

  1. Stories not appearing

    • Verify your app token is correct

    • Ensure the target element has sufficient height (min-height: 100px recommended)

    • Check browser console for errors

    • Make sure you've imported the CSS: import "@storysdk/core/dist/bundle.css";

  2. Initialization issues

    • When using the static HTML approach, make sure the data-storysdk-token attribute is correctly set

    • If manually initializing, ensure the container element exists in the DOM before calling renderGroups()

  3. Cleanup issues

    • Always call destroy() when unmounting your component to prevent memory leaks

Browser Support

StorySDK supports all modern browsers:

  • Chrome (latest versions)

  • Firefox (latest versions)

  • Safari (latest versions)

  • Edge (latest versions)

Last updated

Was this helpful?