Methods
Initializes the SDK with your API key.
Muta.configure(apiKey: String)
Parameters
Parameter | Type | Required | Description |
---|
apiKey | String | Yes | Your Muta API key |
Muta.shared.displayPlacement()
Displays a placement in a modal overlay.
// Using SwiftUI Color
func displayPlacement(
placementId: String,
backgroundColor: Color = .white,
presentationType: PresentationType = .slide,
loadingView: AnyView? = nil
)
// Using hex color string
func displayPlacement(
placementId: String,
backgroundHexColor: String,
presentationType: PresentationType = .slide,
loadingView: AnyView? = nil
)
Parameters
Parameter | Type | Required | Description |
---|
placementId | String | Yes | The ID of the placement to display |
backgroundColor | Color | No | Background color that matches your first placement screen. Defaults to white. |
backgroundHexColor | String | No | Background color as a hex string. Alternative to backgroundColor. |
presentationType | PresentationType | No | Animation style when showing the placement. Defaults to .slide |
loadingView | AnyView? | No | A custom SwiftUI view to show while the placement is loading |
Muta.shared.on()
Subscribe to Muta events.
// Subscribe to all events
func on(_ handler: @escaping (MutaEvent) -> Void) -> Subscription
// Subscribe to specific event type
func on<T: MutaEvent>(_ type: T.Type, handler: @escaping (T) -> Void) -> Subscription
Parameters
Parameter | Type | Required | Description |
---|
handler | (MutaEvent) -> Void | Yes | The closure to be called when any event occurs |
type | T.Type | Yes | The specific event type to listen for |
handler | (T) -> Void | Yes | The closure to be called when the specific event occurs |
Returns
A Subscription
object that can be used to unsubscribe from the event.
Types
MutaEvent
Base protocol for all Muta events.
protocol MutaEvent {
var timestamp: Int { get }
var placementId: String { get }
var flowName: String? { get }
}
FlowStartedEvent
struct FlowStartedEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String?
let totalScreens: Int
}
ScreenViewedEvent
struct ScreenViewedEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String?
let screenIndex: Int
let totalScreens: Int
let screenName: String?
}
FlowCompletedEvent
struct FlowCompletedEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String
let screenIndex: Int
let totalScreens: Int
let screenName: String
}
FlowAbandonedEvent
struct FlowAbandonedEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String?
let screenIndex: Int
let totalScreens: Int
let lastScreenIndex: Int
let screenName: String?
}
struct UserInputFinalEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String?
let userInputs: UserInputs
}
struct UserInputs {
let multipleChoices: [MultipleChoiceInput]
let textInputs: [TextInput]
}
struct MultipleChoiceInput {
let screenIndex: Int
let screenName: String
let isRequired: Bool
let selections: [Selection]
}
struct Selection {
let choiceText: String
let choiceIndex: Int
}
struct TextInput {
let screenIndex: Int
let screenName: String
let value: String
let placeholder: String
let isRequired: Bool
}
ErrorEvent
enum ErrorEvent {
case network(message: String, timestamp: Int)
case placement(message: String, code: String, timestamp: Int, placementId: String)
}
Example Usage
import SwiftUI
import MutaSDK
@main
struct YourApp: App {
init() {
Muta.configure(apiKey: "your-api-key")
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
var body: some View {
Button("Show Placement") {
Muta.shared.displayPlacement(
placementId: "your-placement-id",
backgroundColor: .white,
presentationType: .fade,
loadingView: AnyView(
VStack {
ProgressView()
Text("Loading...")
}
)
)
}
}
}