Shoppable Stories

Shoppable Stories enables your users to add products and services within the cart and checkout directly within the Story without leaving the Story watching experience.

This walkthrough shows how to use Shoppable Stories in your app.

πŸ“˜

Before you begin

You need to have the working Storyly setup as described in Initial SDK Setup

πŸ“˜

Before you begin

You need to have at least 1 active Story with the Product Catalog in it to test this feature out.

🚧

Warning

In-Story Checkout step has not been implemented yet. Documentation will be updated once it becomes available.

Product Fallback for Hydration

There is a boolean parameter named isProductFallbackEnabledwhich is used to determine whether the product data should be hydrated from the feed or not. By default, it is set to false, which means that product data will not be hydrated from the feed. However, when this parameter is set to true, product data will be hydrated from the feed.

You can set theisProductFallbackEnabled to true if you want to enable product fallback from the feed.

storylyWeb.init({
  token: token,
  props: {},
  isProductFallbackEnabled: Boolean
});

Supplemental Product Feed Handling

If you're using a multi-market Product Feed depending on language or country, to automate the Shoppable Story Group creation, you can define the version of the feed that you'd like to use per user on the client side.

That way without creating Story Groups per each region or language, you can serve the relevant content to each market with a single Story Group.

storylyWeb.init({
  token: token,
  props: {},
  productFeedLanguage: "en",
  productFeedCountry: "US"
});

Storyly Cart

There is a boolean parameter named isProductCartEnabled which adds cart icon to top of the left of Shoppable Stories. By default, it is set to false, but, when this parameter is set as true, the cart and the cart icon will be enabled on Shoppable Stories.

storylyWeb.init({
  token: token,
  props: {},
  isProductCartEnabled: Boolean
});

Product Hydration

The onStorylyHydration function is a callback event that is triggered when the product data has been successfully retrieved from Stories. It provides you with an array of objects representing the found product IDs in the Stories.

To use the onStorylyHydration function, define the onStorylyHydration callback function in the events section, which will be triggered when the product data has successfully been retrieved from Stories.

Inside the onStorylyHydration callback, you can access productIds, which represents the found product IDs in the Stories. Perform any necessary actions with the product IDs, such as processing product data for hydration.

storylyWeb.init({
  token: token,
  props: {},
  events: {
    onStorylyHydration: (products: [Object]) => {
       console.log(products);
   }
});

Parameters

  • products (Array of objects): An array of objects representing the hydrated product data from stories. Each object contains the following properties:
    • id (String): The unique identifier for the product.
    • product_group_id (String): The identifier for the product group to which the product belongs.
    • product_id (String): The identifier for the product.

setStorylyHydration Method

The setStorylyHydration function allows you to hydrate your products in Storyly. It takes a list of products as input and updates the hydration status of these products in Storyly.

To use the setStorylyHydration function, you need to provide a list of products as input. The list of products should be an array of objects, where each object represents a product.

// Call the hydrateProducts function with the products data
storylyWeb.setStorylyHydration(products);

Here is an example of asetStorylyHydration. We set the product data manually as an example, but you can set your data from your database as well.

// Define the products data to hydrate
const products = [
  {
    id: '1014-67-1008',
    account_id: 1014,
    feed_id: 67,
    product_id: '1008',
    product_group_id: '1005',
    title: 'Title',
    description: "Description",
    url: 'https://www.storyly.io/',
    mobile_url: '',
    image_urls: [
      'https://random-feed-generator.vercel.app/images/cosmetics/group-5/1.jpg',
    ],
    price: 0,
    sales_price: 79.99,
    price_date: '',
    price_currency: 'USD',
    unit_pricing_measure: '',
    availability: 'in stock',
    category: '',
    type: '',
    brand: '',
    condition: '',
    age_group: '',
    gender: '',
    variant: [],
  },
  // ... add more product objects as needed
];


// Call the hydrateProducts function with the product data
storylyWeb.setStorylyHydration(products);

🚧

Warning

For a Story that needs product data, if that product data is not provided, the Story Group containing that Story is not displayed.

Please make sure that you pass the necessary product data to avoid any issue.

Update Storyly Cart

The onStoryCartUpdate event handler is a callback function that gets triggered when a new product is added, a product from the cart is removed, or the cart is updated. You can define this event handler using the storylyWeb.init function to customize the behavior when the cart is updated.

// Initialize Storyly with the onStoryCartUpdate event handler
storylyWeb.init({
  // ... other configuration options
  events: {
    onStoryCartUpdate: handleStoryProductAdded,
  },
});

// Define the onStoryCartUpdate event handler function
function handleStoryProductAdded(data) {
  const { product, group, onError, onSuccess } = data;
  
  console.log('New product added:', product);
  // ... do something with the product, such as updating UI, triggering actions, etc.

  onError({
    message: `We're sorry to inform you that the item you're interested in purchasing is currently out of stock.`,
  });
  // Handle the onError newly added product based on your application's logic
  
  onSuccess({
    products: 'all products',
    price: 'total_price',
    sales_price: 'total_sales_price',
    price_currency: 'currency',
  });
  // Update the cart with the product information accordingly
}

onStoryCartClicked Event

The onStoryCartClicked method is an event that is triggered when a user clicks on the "Go to Cart" button in a product interactive. It is used to handle cart-related functionality in an application, such as navigating to the cart page, updating the UI, or performing other actions related to the clicked product.

function onStoryCartClicked(data) {
  // Access the product data from the 'data' parameter
  const productData = data.products;
  // ... do something with the product data, such as navigating to cart, triggering actions, etc.
}

storylyWeb.init({
  // Other configurations...
  events: {
    onStoryCartClicked: onStoryCartClicked, // Assign the function as the event handler
  },
});