Muta allows you to collect user inputs during the placement flow, including text inputs and multiple choice selections. These inputs are automatically collected and made available when the flow completes.
Example Usage
import MutaSDK
import SwiftUI
struct OnboardingView: View {
@State private var userInputs: [String: Any] = [:]
var body: some View {
VStack {
// Your content
}
.onAppear {
setupUserInputCollection()
}
}
private func setupUserInputCollection() {
let subscription = Muta.shared.on { event in
if case .userInputFinal(let event) = event {
// Access text input values
event.userInputs.textInputs.forEach { input in
print("Input from screen \(input.screenName): \(input.value)")
}
// Access multiple choice selections
event.userInputs.multipleChoices.forEach { choice in
let selections = choice.selections.map { $0.choiceText }
print("Choices from screen \(choice.screenName): \(selections)")
}
}
}
// Show the placement
Muta.shared.displayPlacement(
placementId: "your-placement-id",
backgroundColor: .white
)
}
}
Text Inputs
struct TextInput {
let screenIndex: Int
let screenName: String
let value: String
let placeholder: String
let isRequired: Bool
}
Multiple Choice
struct MultipleChoiceInput {
let screenIndex: Int
let screenName: String
let isRequired: Bool
let selections: [Selection]
}
struct Selection {
let choiceText: String
let choiceIndex: Int
}
Event Structure
The userInputFinal
event provides a comprehensive structure of all collected inputs:
struct UserInputFinalEvent: MutaEvent {
let timestamp: Int
let placementId: String
let flowName: String?
let userInputs: UserInputs
}
struct UserInputs {
let multipleChoices: [MultipleChoiceInput]
let textInputs: [TextInput]
}