> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 条件付きロジックを追加する

> Widget Studio で Survey イベントを設定し、訪問者の回答に基づいてフォーム要素、アンケート要素、画面を表示または非表示にします。

条件付きロジックは、訪問者の回答によって関連性がある場合にのみ、要素または画面を表示します。すべての訪問者にすべての質問をするフォームでは、大半の訪問者に自分には関係のない質問にも回答させることになり、フォームが必要以上に長くなります。

たとえば、最新の製品を希望する訪問者は、ブログのトピックを選ぶ必要がありません。最初の選択の後に表示される 2 つ目のドロップダウンは、必要な詳細だけを収集します。しかも、その詳細を提供する必要がある訪問者だけに表示されます。

## 条件付きロジックの仕組み

条件付きのルールはすべて、Widget Studio の **Events** セクションにある **Survey** イベントです。Survey イベントタイプは、アンケートの値とフォームの値を区別せずに扱います。そのため、**Form** セクションの **Dropdown** と **Survey** セクションの **Short answer** は、どちらも条件として使用できます。

各イベントには、2 つの部分があります:

* **Condition:** イベントをトリガーする回答です。たとえば、特定のドロップダウンの選択肢などです。
* **Action:** 条件を満たしたときに Kameleoon が行う処理です。たとえば、非表示の要素を表示することなどです。

アクションで要素を表示する場合は、その要素を最初は非表示にしておきます。そうしなければ、イベントで変化させるものがありません。

## 訪問者の選択後に 2 つ目のドロップダウンを表示する

フォローアップの質問が一部の回答にのみ当てはまる場合は、条件付きロジックを使用します。ニュースレターフォームで、訪問者に **Latest products** または **Blog updates** のいずれかを選択してもらうとします。**Latest products** を選択した訪問者だけが製品カテゴリーを選ぶ必要があるため、2 つ目のドロップダウンはその場合にのみ表示されます。

![Initial state が Enabled、Required がオンで、Latest Products と Blog Updates の選択肢があるドロップダウンの設定パネル](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-forms/add-conditional-logic-to-your-forms/Capture-decran-2023-02-17-a-15.55.36.png)

2 つ目のドロップダウンには、**All products**、**Clothes**、**Shoes** の選択肢があります。

![Initial state が Enabled、Required がオンで、All Products、Clothes、Shoes の選択肢があるドロップダウンの設定パネル](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-forms/add-conditional-logic-to-your-forms/Capture-decran-2023-02-17-a-16.01.02.png)

訪問者が **Latest products** を選択したときにのみ 2 つ目のドロップダウンを表示するには、次の手順に従います:

1. **Elements** リストで 2 つ目のドロップダウンにカーソルを合わせ、**three-dots** メニューをクリックして、**Hide** をクリックします。イベントが実行されるまで、ドロップダウンは非表示のままになります。
2. 左サイドバーで **Events** をクリックし、**Add event** をクリックします。
3. **Survey** を選択し、**Next** をクリックします。
4. **If the value for** で、1 つ目のドロップダウンを選択します。
5. **is** で、**Latest products** を選択します。

![条件 If the value for Dropdown を設定し、Latest products を含む値のリストを表示した新しいアンケートイベント](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-forms/forms-survey-event-dropdown-value-step-1-zoom2-v2.png)

6. **Actions** で **Show an element** を選択し、2 つ目のドロップダウンを選びます。
7. **Save event** をクリックします。

訪問者が **Latest products** を選択すると、2 つ目のドロップダウンが表示されます。**Blog updates** を選択した訪問者はイベントをトリガーしないため、その訪問者には 2 つ目のドロップダウンは非表示のままです。

![メールフィールド、Please choose an option と表示されたドロップダウン、無効化された Subscribe ボタンを備えた、Stay up to date! のアニメーション付きポップイン](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-forms/add-conditional-logic-to-your-forms/widget-conditional-logic.gif)

## NPS スコアに基づいて画面を表示する

アンケートに条件付きロジックを使用すると、訪問者が回答した後に表示される内容を変更できます。複数の画面からなる NPS アンケートを作成し、訪問者のスコアに基づいて体験をカスタマイズしたいとします。訪問者が 0 から 6 のスコア（Detractor）を付けた場合は、より詳しいフィードバックを求めるフォローアップ質問を表示するとよいでしょう。スコアが 7 から 10（Passive または Promoter）の場合は、サンクスメッセージに直接進めることができます。

次の例では、アンケートは 2 つの画面で構成されています:

* **Screen 1:** NPS スコアの質問（0-10）。Detractors（スコア 0 から 6）の場合、フォローアップの自由記述欄で、スコアの主な理由を尋ねます。
* **Screen 2:** 確認画面（「Thank you for your feedback!」）。

### アンケートの画面を設定する

Widget Studio で、両方の画面を作成します:

* NPS 要素を含む Screen 1
* 確認メッセージを含む Screen 2

![NPS スコアの質問を含む Screen 1](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-csat-nps-and-surveys/create-conditional-logic-in-your-surveys/screenshot-2025-06-10-at-3.45.08PM-1536x960.png)

Screen 2 には、訪問者が回答した後に表示される確認メッセージが表示されます。

![「Thank you for your feedback!」メッセージを含む Screen 2](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-csat-nps-and-surveys/create-conditional-logic-in-your-surveys/screenshot-2025-06-10-at-3.44.05PM-1536x960.png)

Screen 1 がデフォルトの画面になっていることを確認します。

### Detractors にフォローアップ質問をする

1. NPS 要素を選択します。
2. **Settings** タブの **Follow-up question** で、**Detractors** を選択します。

![フォローアップ質問が Detractors（0-6 のスコア）に設定された NPS 要素の設定と、フォローアップのテキストフィールドを表示したアンケートのポップアッププレビュー](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-csat-nps-and-surveys/create-conditional-logic-in-your-surveys/screenshot-2025-06-10-at-3.46.55PM-1536x960.png)

### Passives と Promoters に対する条件付きロジックのイベントを追加する

1. 左サイドバーで **Events** をクリックし、**Add event** をクリックします。
2. **Create new event** パネルで、イベントタイプとして **Survey** を選択します。

![Click、URL、Display、Survey、Language、Timer のオプションを表示し、Survey が選択された Create new event のダイアログ](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-csat-nps-and-surveys/create-conditional-logic-in-your-surveys/conditional-logic-survey.png)

3. **If the value for** で **NPS** を選択します。
4. **matches** で **Passives** と **Promoters** を選択します。

![New survey event の Conditions ボックス。条件は NPS matches Passives and Promoters](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/conditional-logic-survey-event-conditions-step-1.png)

5. 次に、アクションを定義します。**Add action** > **Show a screen** をクリックします。
6. **Thank you** を選択します。

![Show a screen が選択され、画面として Thank you が選ばれた、イベントの Actions セクション](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/images/assets/widgets/create-a-widget-with-the-widget-studio/create-csat-nps-and-surveys/create-conditional-logic-in-your-surveys/ty-screen-1-768x655.png)

7. 2 つ目のアクションを定義します: **Hide element** > **Screen 1**。

この設定では、訪問者が 7 から 10 のスコアを選択した場合に Screen 2 が表示されます。これにより、フィードバックからサンクス画面へ、スムーズに移行できます。

### 最終的なロジックを確認する

最終的なロジックは次のとおりです:

1. ウィジェットは、常に最初に Screen 1 を表示します。
2. スコアが 0 から 6 の場合、ウィジェットはフォローアップ質問を表示します。
3. 訪問者が Screen 1 の **Submit** をクリックすると、Screen 2 に進みます。
4. スコアが 7 以上の場合、ウィジェットはフォローアップ質問をスキップし、訪問者を直接 Screen 2 に進めます。

このロジックにより、Detractors からより詳細な知見を収集できる一方で、他の訪問者にはストレスのない体験を提供できます。

## その他の条件

Survey イベントは、**Short answer** フィールドでも使用できます。入力がルールに違反した場合にメッセージを表示するには、条件として **matches validation rule** または **doesn't match validation rule** を選択します。そのメッセージを設定するには、[Short answer の入力を検証する](https://docs.kameleoon.com/ja/user-manual/assets/widgets/create-a-widget-with-the-widget-studio/create-forms/add-rules-to-your-form-fields.md)をご覧ください。
