React Native SDKでオンボーディングのデータを処理する

オンボーディングはSDK v4で非推奨となり、将来のリリースで削除される予定です。 バグ修正や機能改善は行われません。代わりにフローをご利用ください。オンボーディングはWebView内で動作しますが、フローはデバイス上でネイティブにレンダリングされるため、よりスムーズなアニメーション、一貫したネイティブの外観、高速な読み込み、WebViewランタイムへの依存なしで利用できます。詳細はフローとペイウォールの取得およびフローとペイウォールの表示をご覧ください。

ユーザーがクイズの質問に回答したり、入力フィールドにデータを入力したりすると、onStateUpdatedAction メソッドが呼び出されます。フィールドタイプをコード内で保存または処理できます。

例:

// Full-screen presentation
const unsubscribe = view.setEventHandlers({
  onStateUpdated(action, meta) {
    // Process data 
  },
});

// Embedded widget
<AdaptyOnboardingView
  onboarding={onboarding}
  eventHandlers={{
    onStateUpdated(action, meta) {
      // Process data 
    },
  }}
/>

アクションの形式はこちらをご覧ください。

保存されたデータの例(実装によって形式が異なる場合があります)
// Example of a saved select action
{
    "elementId": "preference_selector",
    "elementType": "select",
    "value": {
        "id": "option_1",
        "value": "premium",
        "label": "Premium Plan"
    },
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "preferences_screen",
        "screenIndex": 1,
        "totalScreens": 3
    }
}

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

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

// Example of a saved date picker action
{
    "elementId": "birthday_picker",
    "elementType": "date_picker",
    "value": {
        "day": 15,
        "month": 6,
        "year": 1990
    },
    "meta": {
        "onboardingId": "onboarding_123",
        "screenClientId": "profile_screen",
        "screenIndex": 0,
        "totalScreens": 3
    }
}

ユースケース

ユーザープロファイルにデータを付加する

入力データをユーザープロファイルとすぐに紐付けて、同じ情報を二度尋ねないようにするには、アクションを処理する際に入力データでユーザープロファイルを更新する必要があります。

たとえば、name というIDのテキストフィールドでユーザーに名前を入力してもらい、その値をユーザーのファーストネームとして設定したいとします。また、email フィールドでメールアドレスも入力してもらうとします。アプリのコードでは、次のようになります。

// Full-screen presentation
const unsubscribe = view.setEventHandlers({
  onStateUpdated(action, meta) {
    // Store user preferences or responses
    if (action.elementType === 'input') {
      const profileParams = {};
      
      // Map elementId to appropriate profile field
      switch (action.elementId) {
        case 'name':
          if (action.value.type === 'text') {
            profileParams.firstName = action.value.value;
          }
          break;
        case 'email':
          if (action.value.type === 'email') {
            profileParams.email = action.value.value;
          }
          break;
      }
      
      // Update profile if we have data to update
      if (Object.keys(profileParams).length > 0) {
        adapty.updateProfile(profileParams).catch(error => {
          // handle the error
        });
      }
    }
  },
});

// Embedded widget
<AdaptyOnboardingView
  onboarding={onboarding}
  eventHandlers={{
    onStateUpdated(action, meta) {
      // Store user preferences or responses
      if (action.elementType === 'input') {
        const profileParams = {};
        
        // Map elementId to appropriate profile field
        switch (action.elementId) {
          case 'name':
            if (action.value.type === 'text') {
              profileParams.firstName = action.value.value;
            }
            break;
          case 'email':
            if (action.value.type === 'email') {
              profileParams.email = action.value.value;
            }
            break;
        }
        
        // Update profile if we have data to update
        if (Object.keys(profileParams).length > 0) {
          adapty.updateProfile(profileParams).catch(error => {
            // handle the error
          });
        }
      }
    },
  }}
/>

アンケートの回答に基づいてペイウォールをカスタマイズする

オンボーディングでクイズを使用することで、オンボーディング完了後にユーザーに表示するペイウォールをカスタマイズすることもできます。

たとえば、スポーツの経験についてユーザーに質問し、ユーザーグループごとに異なるCTAやプロダクトを表示することができます。

  1. オンボーディングビルダーでクイズを追加し、各選択肢に意味のあるIDを割り当てます。
experience.webp
  1. IDに基づいてクイズの回答を処理し、ユーザーにカスタム属性を設定します。
// Full-screen presentation
const unsubscribe = view.setEventHandlers({
  onStateUpdated(action, meta) {
    // Handle quiz responses and set custom attributes
    if (action.elementType === 'select') {
      const profileParams = {};
      
      // Map quiz responses to custom attributes
      switch (action.elementId) {
        case 'experience':
          // Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
          profileParams.codableCustomAttributes = {
            experience: action.value.value
          };
          break;
      }
      
      // Update profile if we have data to update
      if (Object.keys(profileParams).length > 0) {
        adapty.updateProfile(profileParams).catch(error => {
          // handle the error
        });
      }
    }
  },
});

// Embedded widget
<AdaptyOnboardingView
  onboarding={onboarding}
  eventHandlers={{
    onStateUpdated(action, meta) {
      // Handle quiz responses and set custom attributes
      if (action.elementType === 'select') {
        const profileParams = {};
        
        // Map quiz responses to custom attributes
        switch (action.elementId) {
          case 'experience':
            // Set custom attribute 'experience' with the selected value (beginner, amateur, pro)
            profileParams.codableCustomAttributes = {
              experience: action.value.value
            };
            break;
        }
        
        // Update profile if we have data to update
        if (Object.keys(profileParams).length > 0) {
          adapty.updateProfile(profileParams).catch(error => {
            // handle the error
          });
        }
      }
    },
  }}
/>
  1. カスタム属性の値ごとにセグメントを作成します。
  2. プレースメントを作成し、作成した各セグメントに対してオーディエンスを追加します。
  3. アプリのコードで、そのプレースメントに対するペイウォールを表示します。オンボーディングにペイウォールを開くボタンがある場合は、このボタンのアクションへの応答としてペイウォールのコードを実装してください。