Skip to main content

Product hydration

Product hydration allows your app to supply enriched product data (pricing, images, variants, stock) to the Bambuser live player at runtime. When a live show starts, the player fires a provide-product-data event listing all products it needs data for. Your app looks up each product by SKU and pushes the data back into the player using invoke("updateProductWithData", ...).

Prerequisites

currency and locale must be set in your player configuration — product hydration will not work without them.

let playerView = bambuserPlayer.createPlayerView(
videoConfiguration: .init(
type: .live(id: "your-show-id"),
events: ["*"],
configuration: [
"currency": "USD", // Required for product hydration
"locale": "en-US" // Required for product hydration
]
)
)
playerView.delegate = self

Handle the provide-product-data Event

The player fires provide-product-data at show start, and again whenever a new product needs to be displayed. Handle it in your BambuserVideoPlayerDelegate:

func onNewEventReceived(id: String, event: BambuserEventPayload) {
if event.type == "provide-product-data" {
Task {
try await self.hydrate(data: event.data)
}
}
}

The event payload contains an "event" dictionary with a "products" array. Each entry has:

FieldTypeDescription
idStringBambuser-generated product ID — pass this back to the player
refStringYour product SKU — use this to look up your own data
urlStringProduct URL as set in the Bambuser dashboard

Send Product Data Back to the Player

Call invoke("updateProductWithData", ...) for each product. The arguments string must start with the Bambuser product id in single quotes, followed by a comma and the product object:

func hydrate(data: [String: Any]) async throws {
guard let event = data["event"] as? [String: Any],
let products = event["products"] as? [[String: Any]] else { return }

for product in products {
guard let id = product["id"] as? String,
let sku = product["ref"] as? String else { continue }

// Look up product data from your own catalog using the SKU
guard let productData = YourProductService.product(for: sku) else { continue }

try await self.playerView?.invoke(
function: "updateProductWithData",
arguments: """
'\(id)', {
sku: '\(productData.sku)',
name: '\(productData.name)',
brandName: '\(productData.brand)',
introduction: '\(productData.shortDescription)',
description: '\(productData.description)',
variations: [
{
sku: '\(productData.variationSku)',
name: '\(productData.variationName)',
colorName: '\(productData.colorName)',
imageUrls: ['\(productData.imageUrl)'],
sizes: [
{
sku: '\(productData.sizeSku)',
currency: 'USD',
current: \(productData.price),
original: \(productData.originalPrice),
name: '\(productData.sizeName)',
inStock: \(productData.stock),
}
]
}
]
}
"""
)
}
}

Full Product Data Structure

The product object passed to updateProductWithData supports the following fields:

Product

FieldTypeRequiredDescription
skuStringYesYour product SKU / identifier
nameStringYesProduct display name
brandNameStringYesBrand name
introductionStringNoShort introductory text
descriptionStringNoFull description — supports HTML
variationsArrayYesList of product variations (colors/styles)

Variation

FieldTypeRequiredDescription
skuStringYesVariation SKU
nameStringYesVariation display name
colorNameStringYesColor name shown in the variation selector
colorHexCodeStringNoHex color code e.g. "#000000"
imageUrls[String]YesOrdered list of image URLs for this variation
sizesArrayYesList of sizes/SKUs for this variation

Size

FieldTypeRequiredDescription
skuStringYesSize-level SKU
nameStringYesSize name e.g. "Small", "XL"
currentDoubleYesCurrent (sale) price
originalDoubleNoOriginal price — shown as strike-through
currencyStringYesThree-letter currency code e.g. "USD"
inStockIntYesAvailable stock quantity (0 = out of stock)
perUnitDoubleNoPrice per unit (for bundle/multi-pack pricing)
unitAmountIntNoQuantity per unit
unitDisplayNameStringNoUnit label e.g. "kg", "L", "st"

Instead of raw string interpolation, use the HydratedProduct builder from the SDK example app. The builder validates required fields and serialises the product to the correct format:

func hydrateUsingBuilder(data: [String: Any]) async throws {
guard let event = data["event"] as? [String: Any],
let products = event["products"] as? [[String: Any]] else { return }

for product in products {
guard let sku = product["ref"] as? String,
let id = product["id"] as? String else { continue }

guard let source = YourProductService.product(for: sku) else { continue }

let hydratedProduct = try HydratedProduct(sku: source.sku)
.withName(source.name)
.withBrandName(source.brand)
.withVariations(
source.variations.map { v in
try Variation()
.withSku(v.sku)
.withName(v.name)
.withColorName(v.colorName)
.withImageUrls(v.imageUrls)
.withSizes(
v.sizes.map { s in
try ProductSize()
.withSku(s.sku)
.withName(s.name)
.withCurrentPrice(s.currentPrice)
.withInStock(s.inStock)
.build()
}
)
.build()
}
)
.build()

let hydrationString = "'\(id)', \(try hydratedProduct.toJSON())"

try await playerView?.invoke(
function: "updateProductWithData",
arguments: hydrationString
)
}
}

Notes

  • The player may fire provide-product-data multiple times during a show as new products are highlighted. Your hydration handler must be idempotent.
  • Fields not provided in your hydration response fall back to data previously scraped or manually set in the Bambuser dashboard.
  • invoke is an async throws method — always call it inside a Task or async context.