Skip to main content
Version: 3.x.x

Events

StorifyMe SDK 3.x uses focused delegates so a view controller can handle only the event groups it needs. Assign each delegate to the widget before calling load().

Widget load and failure​

final class ViewController: UIViewController, StorifyMeWidgetDelegate {
private let widget = StorifyMeWidget()

override func viewDidLoad() {
super.viewDidLoad()
widget.setWidgetId(widgetId: 12345)
widget.widgetDelegate = self
view.addSubview(widget)
widget.load()
}

func onLoaded(widgetID: StorifyMeWidgetID, experiences: [StorifyMeExperience]) {
print("Loaded \(experiences.count) experiences for widget \(widgetID)")
}

func onFailed(error: StorifyMeError) {
print("Widget failed to load: \(error.message)")
}
}

StorifyMeWidgetDelegate also provides onSizeChanged(widgetID:height:), onScrolled(widgetID:offsetX:), and onIntegrityFailed(storyID:reason:). Its methods have default no-op implementations, so implement only the callbacks you use.

Experience lifecycle​

extension ViewController: StorifyMeExperienceDelegate {
func onOpened(_ experience: StorifyMeExperience, at index: Int) {
analytics.track("experience_opened", experience.id)
}

func onFinished(_ experience: StorifyMeExperience, at index: Int) {
analytics.track("experience_finished", experience.id)
}

func onClosed(_ experience: StorifyMeExperience?) {
print("Viewer closed")
}

func onShared(_ experience: StorifyMeExperience) {
analytics.track("experience_shared", experience.id)
}
}

The experience model unifies stories, shorts, snaps, and ads. See Experiences and content types for its fields and type handling.

Intercept experience navigation​

Implement onNavigationRequested to handle a configured experience navigation URL in your app. Complete the callback with .handleNavigation after routing yourself, or .openExperience to let the SDK open its viewer.

func onNavigationRequested(
_ experience: StorifyMeExperience,
completion: @escaping (StorifyMeExperienceNavigationDecision) -> Void
) {
guard let urlString = experience.navigationUrl,
let url = URL(string: urlString),
router.canOpen(url) else {
completion(.openExperience)
return
}

router.open(url)
completion(.handleNavigation)
}

StorifyMeInteractionDelegate receives typed actions and analytics events, and can intercept links opened inside the viewer.

extension ViewController: StorifyMeInteractionDelegate {
func onAction(_ action: StorifyMeInteractionAction) {
print("Action \(action.type), value: \(String(describing: action.value))")
}

func onEvent(_ event: StorifyMeInteractionEvent) {
analytics.track(event.action, event.context)
}

func onLinkTriggered(
url: String,
completion: @escaping (StorifyMeLinkTriggerCompletion) -> Void
) {
guard let destination = URL(string: url), router.canOpen(destination) else {
completion(.openLinkByDefault)
return
}

router.open(destination)
completion(.ignorePresentingLink)
}
}

StorifyMeInteractionAction includes fields such as type, value, href, and a typed context. StorifyMeInteractionEvent includes action, value, context, and rawData.

Ads and commerce​

Use StorifyMeAdDelegate for ad impressions:

extension ViewController: StorifyMeAdDelegate {
func onAdDisplayed(_ experience: StorifyMeExperience, at index: Int) {
analytics.track("ad_displayed", experience.id)
}
}

Use StorifyMeCommerceDelegate for cart events:

extension ViewController: StorifyMeCommerceDelegate {
func onCartItemAdded(productId: String, quantity: Int) {
cart.add(productId: productId, quantity: quantity)
}

func onCartUpdated(_ cart: StorifyMeCart) {
print("Cart total: \(cart.total) \(cart.currency)")
}

func onCheckout(_ cart: StorifyMeCart) {
checkout.start(with: cart)
}
}

SwiftUI callbacks​

StorifyMeWidgetView exposes equivalent modifiers. The v3 names use typed experience and interaction payloads:

StorifyMeWidgetView(widgetId: 12345)
.onLoaded { widgetID, experiences in
print("Loaded \(experiences.count) experiences for \(widgetID)")
}
.onFailed { error in
print("Load failed: \(error.message)")
}
.onOpened { experience, index in
analytics.track("experience_opened", experience.id)
}
.onExperienceNavigationRequested { experience, completion in
completion(.openExperience)
}
.onAction { action in
print("Action: \(action.type)")
}
.onCartUpdated { cart in
print("Cart total: \(cart.total)")
}

See SwiftUI integration for the full modifier list.

v2 compatibility APIs​

StorifyMeStoryEventProtocol, its legacy callback methods, and StorifyMeStoryModel remain available with deprecation warnings in v3. New integrations should use the focused delegates and StorifyMeExperience. See the v2 to v3 migration guide for the iOS API mapping.