ÿÿ Onboardings | Android SDK | Tài liệu Adapty

Xử lý dữ liệu từ onboardings trong Android SDK

Bắt đầu từ SDK v4, bạn có thể xây dá»±ng flows như má»™t lá»±a chá»n mạnh mẽ hÆ¡n so vá»›i onboardings. Khác vá»›i onboardings chạy trong WebView, flows render trá»±c tiếp trên thiết bị — mang lại hoạt ảnh mượt mà hÆ¡n, giao diện Android 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 flows & paywalls và Hiển thị flows & paywalls để bắt đầu.

Khi ngưá»i dùng trả lá»i má»™t câu há»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ụ:

override fun onStateUpdatedAction(action: AdaptyOnboardingStateUpdatedAction, context: Context) {
    // Store user preferences or responses
    when (val params = action.params) {
        is AdaptyOnboardingStateUpdatedParams.Select -> {
            // Handle single selection
        }
        is AdaptyOnboardingStateUpdatedParams.MultiSelect -> {
            // Handle multiple selections
        }
        is AdaptyOnboardingStateUpdatedParams.Input -> {
            // Handle text input
        }
        is AdaptyOnboardingStateUpdatedParams.DatePicker -> {
            // Handle date selection
        }
    }
}

Xem định dạng action tại đây.

Ví dụ vỠdữ liệu đã lưu (định dạng có thể khác trong quá trình 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",
    "value": {
        "day": 15,
        "month": 6,
        "year": 1990
        }
    }
}

Trưá»ng hợp sá»­ dụng

Enrich usÿÿer profiles with data

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 lại 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 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:

override fun onStateUpdatedAction(action: AdaptyOnboardingStateUpdatedAction, context: Context) {
    // Store user preferences or responses
    when (val params = action.params) {
        is AdaptyOnboardingStateUpdatedParams.Input -> {
            // Handle text input
            val builder = AdaptyProfileParameters.Builder()
            
            // Map elementId to appropriate profile field
            when (action.elementId) {
                "name" -> {
                    when (val inputParams = params.params) {
                        is AdaptyOnboardingInputParams.Text -> {
                            builder.withFirstName(inputParams.value)
                        }
                    }
                }
                "email" -> {
                    when (val inputParams = params.params) {
                        is AdaptyOnboardingInputParams.Email -> {
                            builder.withEmail(inputParams.value)
                        }
                    }
                }
            }
            
            Adapty.updateProfile(builder.build()) { error ->
                if (error != null) {
                    // handle the error
                }
            }
        }
    }
}

Tuỳ chỉnh paywall dá»±a trên câu trả lá»i

Khi dùng quiz trong onboarding, bạn cÅ©ng có thể tuỳ chỉnh 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 và sản phẩm khác nhau cho từng nhóm ngưá»i dùng.

  1. Thêm quiz vào onboarding builder và gán ID có ý nghÄ©a cho các lá»±a chá»n.
experience.webp
  1. Xá»­ lý các câu trả lá»i quiz dá»±a trên ID cá»§a chúng và đặt thuá»™c tính tuỳ chỉnh cho ngưá»i dùng.
override fun onStateUpdatedAction(action: AdaptyOnboardingStateUpdatedAction, context: Context) {
    // Handle quiz responses and set custom attributes
    when (val params = action.params) {
        is AdaptyOnboardingStateUpdatedParams.Select -> {
            // Handle quiz selection
            val builder = AdaptyProfileParameters.Builder()
            
            // Map quiz responses to custom attributes
            when (action.elementId) {
                "experience" -> {
                    // Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
                    builder.withCustomAttribute("experience", params.params.value)
                }
            }
            
            Adapty.updateProfile(builder.build()) { error ->
                if (error != null) {
                    // handle the error
                }
            }
        }
    }
}
  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ủa bạn 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.
ÿÿÿÿ