Swift

Initialization

For information on how to connect your app to the mbark platform please refer to this documentation.
Initialize the SDK with Mbark-Info.plist providing platform keys:
1
/// Initializes an instance of the API with the host's 'MbarkInfo.plist' file.
2
///
3
/// Returns a new Mbark instance object. This allows us to create more than one
4
/// instance of the API, which is convenient if we'd like to send data to more
5
/// than one flow from a single app.
6
Mbark.initializeSDK()
Copied!
Initialize the SDK by manually providing platform keys:
1
/// Initializes an instance of the API with manually added API info (config ID
2
/// and (prod | dev) API Key).
3
///
4
/// Returns a new Mbark instance object. This allows us to create more than one
5
/// instance of the API, which is convenient if we'd like to send data to more
6
/// than one flow from a single app.
7
Mbark.initializeSDK(instanceName: String = UUID().uuidString,
8
selectedLanguage: String? = nil) -> MbarkInstance?
Copied!

Check active status

1
/// Provides whether the SDK is active / enabled based on the availability of
2
/// the mbark platform
3
Mbark.isActive
Copied!

User-flows

Creating a remote configurable view controller:
1
/// Used to generate a single UIViewController from the mbark remote config
2
Mbark.userView(forMbarkId: String,
3
onLoaded: @escaping (Bool) -> Void) -> MbarkViewController?
Copied!
Creating a complete, self-contained user-flow:
1
/// Used to generate a complete user-flow from the mbark remote config
2
Mbark.userFlow(startingViewId: String,
3
onLoaded: @escaping (Bool) -> Void)-> UINavigationController?
Copied!

Action Handlers

Add an action handler (MbarkActionHandler) to respond to user events originating from an mbark view.
1
/// Adds an action handler, used to respond to events originating from the SDK
2
Mbark.addActionHandler(_ actionHandler: MbarkActionHandler)
Copied!
Removes an action handler (MbarkActionHandler)
1
/// Removes an action handler, based on its identifier
2
Mbark.removeActionHandler(forId: String)
Copied!
Adds a purchase action handler to respond user purchase requests originating from an mbark view.
1
/// Adds a purchase action handler, used to respond to purchase requestsoriginating
2
/// from the SDK
3
Mbark.addPurchaseActionHandler(_ purchaseActionHandler: MbarkPurchaseActionHandler)
Copied!
Removes a purchase action handler (MbarkPurchaseActionHandler)
1
/// Removes a purchase action handler, based on its identifier
2
Mbark.removePurchaseActionHandler(forId: String)
Copied!

Event tracking

Track the start of a user-flow:
1
/// Helper method used to simplify tracking flow starts
2
Mbark.trackFlowStart()
Copied!
Track the end of a user-flow:
1
/// Helper method used to simplify tracking flow ends
2
Mbark.trackFlowEnd()
Copied!
Manually track an event outside of an mbark user-flow:
1
/// Tracks Mbark events
2
Mbark.track(eventType: MbarkEventType,
3
step: String? = nil,
4
component: String? = nil,
5
data: MbarkEventData? = nil)
Copied!
Manually track an event only once per user-flow:
1
/// Track singular Mbark events
2
Mbark.trackOnce(eventType: MbarkEventType,
3
step: String? = nil,
4
component: String? = nil,
5
data: MbarkEventData? = nil)
Copied!
Event tracking helpers
The following are helper methods which will format the above tracking event calls automatically:
Tracking app loading:
1
/// Helper method used to simplify tracking app loading
2
Mbark.trackAppLoading()
Copied!
Tracking an onboarding step view:
1
/// Helper method used to simplify tracking step views - used in cases where we
2
// can't register the step with an mbark id for example in SSO-flows
3
Mbark.trackStepView(_ step: String,
4
data: MbarkEventData? = nil)
Copied!
Tracking an onboarding step view only once:
1
/// Helper method used to simplify tracking step views only once
2
Mbark.trackStepViewOnce(_ step: String,
3
data: MbarkEventData? = nil)
Copied!
Tracking authentication for a new user:
1
/// Helper method used to simplify tracking new user authentication events
2
Mbark.trackAuthenticationForNewUser()
Copied!
Tracking authentication for an existing user:
1
/// Helper method used to simplify tracking existing user authentication events
2
Mbark.trackAuthenticationForExistingUser()
Copied!
Tracking granted system permissions:
1
/// Helper method used to simplify tracking accept events
2
Mbark.trackAccept(step: String? = nil,
3
component: String? = nil,
4
shouldTrackOnce: Bool = false)
Copied!
Tracking revoked system permissions:
1
/// Helper method used to simplify tracking reject events
2
Mbark.trackReject(step: String? = nil,
3
component: String? = nil,
4
shouldTrackOnce: Bool = false)
Copied!
Tracking taps:
1
/// Helper method used to simplify tracking tap events
2
Mbark.trackTap(step: String? = nil,
3
component: String? = nil,
4
data: MbarkEventData? = nil)
Copied!
Tracking input field entries:
1
/// Helper method used to simplify tracking component input events
2
Mbark.trackInput(step: String? = nil,
3
component: String? = nil,
4
data: MbarkEventData? = nil)
Copied!

MbarkActionHandler

MbarkActionHandler helps the mbark SDK and a host app work in tandem to respond to user interactions. Through Screen Builder, you can define action handler identifiers that make existing logic in your app available to mbark's generated UI. For more details, please refer to this documentation.
Initialize a new MbarkActionHandler:
1
/// Initializes a new action handler, passing in an identifier and a handling
2
/// closure
3
MbarkActionHandler.init(id: String,
4
handler: @escaping () -> Void)
Copied!
Notify the mbark SDK that an action was handled:
1
/// The following notifies SDK that an action was handled sucussfully and that it
2
/// can follow up with any additional actions defined on the interaction.
3
actionHandlerInstance.finish(success: true)
Copied!

MbarkPurchaseActionHandler

MbarkPurchaseActionHandler helps the mbark SDK coordinate in-app purchase requests. Through Screen Builder, you can add product SKUs that make existing products and subscriptions available to mbark's generated UI. For more details, please refer to this documentation.
1
/// Initializes a new purchase action handler, passing in an identifier and a
2
/// handling closure
3
///
4
/// The handling closure will receive the SKU the user wishes to purchase
5
MbarkPurchaseActionHandler.init(id: String,
6
handler: @escaping (String) -> Void)
Copied!
Notify the mbark SDK that a purchase action was handled:
1
/// The following notifies SDK that an action was handled sucussfully and that it
2
/// can follow up with any additional actions defined on the interaction.
3
actionHandlerInstance.finish(success: true)
Copied!
Last modified 6mo ago