ÿÿ Onboarding | iOS SDK | Tài liệu Adapty

Xử lý dữ liệu từ onboarding trong iOS SDK

Bắt đầu từ SDK v4, bạn có thể xây dá»±ng flow như má»™t lá»±a chá»n mạnh mẽ hÆ¡n so vá»›i onboarding. Khác vá»›i onboarding chạy trong WebView, flow render trá»±c tiếp trên thiết bị — mang lại hiệu ứng chuyển động mượt mà hÆ¡n, giao diện iOS nhất quán, thá»i gian tải nhanh hÆ¡n và không phụ thuá»™c vào WebView runtime. Xem Lấy flow & paywall và Hiển thị flow & paywall để bắt đầu.

Khi ngưá»i dùng trả lá»i câu há»i trong bài quiz hoặc nhập dữ liệu vào trưá»ng nhập liệu, phương thức onStateUpdatedAction sẽ được gá»i. Bạn có thể lưu hoặc xá»­ lý loại trưá»ng đó trong code cá»§a mình.

Ví dụ:

func onboardingController(_ controller: AdaptyOnboardingController, onStateUpdatedAction action: AdaptyOnboardingsStateUpdatedAction) {
    // Store user preferences or responses
    switch action.params {
    case .select(let params):
        // Handle single selection
    case .multiSelect(let params):
        // Handle multiple selections
    case .input(let params):
        // Handle text input
    case .datePicker(let params):
        // Handle date selection
    }
}

Äối tượng action chứa:

Tham sốMô tả
elementIdÄịnh danh duy nhất cho phần tá»­ input. Bạn có thể dùng nó để liên kết câu há»i vá»›i câu trả lá»i khi lưu lại.
paramsÄối tượng dữ liệu đầu vào cá»§a ngưá»i dùng, chứa các thuá»™c tính type và value.
params.typeLoại phần tử input. Có thể là:
• "select" - Chá»n má»™t giá trị từ các tùy chá»n
• "multiSelect" - Chá»n nhiá»u giá trị từ các tùy chá»n
• "input" - Trưá»ng nhập văn bản
• "datePicker" - Chá»n ngày
params.valueGiá trị được ngưá»i dùng chá»n hoặc nhập. Cấu trúc phụ thuá»™c vào loại:
• select: Äối tượng có id, value, label
• multiSelect: Mảng các đối tượng có id, value, label
• input: Äối tượng có type, value
• datePicker: Äối tượng có day, month, year
Ví dụ dữ liệu đã lưu (có thể khác với triển khai của bạn)
// Example of a saved select action
{
    "elementId": "preference_selector",
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "preferences_screen",
        "screenIndex": 1,
        "screensTotal": 3
    },
    "params": {
        "type": "select",
        "value": {
            "id": "option_1",
            "value": "premium",
            "label": "Premium Plan"
        }
    }
}

// Example of a saved multi-select action
{
    "elementId": "interests_selector",
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "interests_screen",
        "screenIndex": 2,
        "screensTotal": 3
    },
    "params": {
        "type": "multiSelect",
        "value": [
            {
                "id": "interest_1",
                "value": "sports",
                "label": "Sports"
            },
            {
                "id": "interest_2",
                "value": "music",
                "label": "Music"
            }
        ]
    }
}

// Example of a saved input action
{
    "elementId": "name_input",
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "profile_screen",
        "screenIndex": 0,
        "screensTotal": 3
    },
    "params": {
        "type": "input",
        "value": {
            "type": "text",
            "value": "John Doe"
        }
    }
}

// Example of a saved date picker action
{
    "elementId": "birthday_picker",
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "profile_screen",
        "screenIndex": 0,
        "screensTotal": 3
    },
"params": {
    "type": "datePicker",
    "vÿÿalue": {
        "day": 15,
        "month": 6,
        "year": 1990
        }
    }
}

Các trưá»ng hợp sá»­ dụng

Làm phong phú thêm dữ liệu hồ sÆ¡ ngưá»i dùng

Nếu bạn muốn liên kết ngay dữ liệu đầu vào vá»›i hồ sÆ¡ ngưá»i dùng và tránh há»i há» hai lần vá» cùng má»™t thông tin, bạn cần cập nhật hồ sÆ¡ ngưá»i dùng vá»›i dữ liệu đầu vào khi xá»­ lý action.

Ví dụ, bạn yêu cầu ngưá»i dùng nhập tên cá»§a há» vào trưá»ng văn bản có ID là name, và bạn muốn đặt giá trị cá»§a trưá»ng này làm tên cá»§a ngưá»i dùng. Ngoài ra, bạn yêu cầu há» nhập email vào trưá»ng email. Trong code ứng dụng cá»§a bạn, nó có thể trông như thế này:

func onboardingController(_ controller: AdaptyOnboardingController, onStateUpdatedAction action: AdaptyOnboardingsStateUpdatedAction) {
    // Store user preferences or responses
    switch action.params {
    case .input(let params):
        // Handle text input
        let builder = AdaptyProfileParameters.Builder()

        // Map elementId to appropriate profile field
        switch action.elementId {
        case "name":
            builder.with(firstName: params.value.value)
        case "email":
            builder.with(email: params.value.value)
        default:
            break
        }

        // Delegate methods are synchronous; kick off the async update in a Task.
        Task {
            do {
                try await Adapty.updateProfile(params: builder.build())
            } catch {
                // handle the error
            }
        }
    default:
        break
    }
}

Tùy chỉnh paywall dá»±a trên câu trả lá»i

Sá»­ dụng quiz trong onboarding, bạn cÅ©ng có thể tùy chỉnh các paywall hiển thị cho ngưá»i dùng sau khi há» hoàn thành onboarding.

Ví dụ: bạn có thể há»i ngưá»i dùng vá» kinh nghiệm thể thao cá»§a há» và hiển thị các CTA cùng sản phẩm khác nhau cho từng nhóm ngưá»i dùng.

  1. Thêm quiz trong trình tạo onboarding và gán ID có ý nghÄ©a cho các lá»±a chá»n cá»§a quiz.
experience.webp
  1. Xá»­ lý các phản hồi quiz dá»±a trên ID cá»§a chúng và đặt thuá»™c tính tùy chỉnh cho ngưá»i dùng.
func onboardingController(_ controller: AdaptyOnboardingController, onStateUpdatedAction action: AdaptyOnboardingsStateUpdatedAction) {
    // Handle quiz responses and set custom attributes
    switch action.params {
    case .select(let params):
        // Handle quiz selection
        let builder = AdaptyProfileParameters.Builder()

        // Map quiz responses to custom attributes
        switch action.elementId {
        case "experience":
            // Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
            try? builder.with(customAttribute: params.value.value, forKey: "experience")
        default:
            break
        }

        // Delegate methods are synchronous; kick off the async update in a Task.
        Task {
            do {
                try await Adapty.updateProfile(params: builder.build())
            } catch {
                // handle the error
            }
        }
    default:
        break
    }
}
  1. Tạo phân khúc cho từng giá trị thuộc tính tùy chỉnh.
  2. Tạo một placement và thêm đối tượng cho từng phân khúc bạn đã tạo.
  3. Hiển thị paywall cho placement trong code ứng dụng của bạn. Nếu onboarding có nút mở paywall, hãy triển khai code paywall như một phản hồi cho hành động của nút này.
ÿÿÿÿ