Conditional Logic
Conditional logic creates dynamic, personalized experiences that adapt based on user properties and survey responses. Use conditional logic to branch survey paths, trigger different actions, or show different content to different users.
Where you can use conditional logic
Conditional logic works with both guides and surveys. You can select it as an action for either primary or secondary buttons.
Types of conditions
Create conditions based on two types of data:
User properties
User properties are attributes about your users, such as location, subscription tier, or account type. User properties must be shared client-side during the session with either the Amplitude SDK or the Engagement SDK.
Common user property examples:
subscription_tiercountryaccount_typeinitial_referring_domain
User property requirements
Properties must be available client-side during the current session. Properties shared from prior sessions or properties stored only on the server aren't supported. Go to Set user properties for implementation details.
Survey responses
Survey responses are the answers users provide to questions in your surveys. Use survey responses to branch your survey based on how users answer.
Survey response examples:
- NPS ratings
- Star ratings
- Multiple choice selections
- Text input values
Combining conditions
Combine multiple conditions to create more advanced logic. When you add multiple conditions, all conditions must be met for the action to execute.
For example: if subscription_tier = premium AND country = US, then visit link to premium US-specific content.
Set up conditional logic
The setup process is similar whether you add conditional logic to buttons or to survey steps.
Add conditional logic to buttons
- In your guide or survey, add a primary or secondary button.
- Click the On button click dropdown.
- Select Evaluate conditional logic.
- Navigate to the Conditional Logic section.
- Under When, select either User Property or Survey Response from the dropdown.
- Configure your condition:
- For User Property: Select the property, operator, and value.
- For Survey Response: Select the question, operator, and value.
- (Optional) Click Add condition to add more conditions.
- Under Do this, select the action to execute when the condition is met.
- Configure the action based on your selection.
Multiple conditional actions
Add multiple conditional actions to handle different scenarios. For example, one action for premium users and another for free users. Amplitude evaluates conditions in order and executes the first matching action.
Examples and use cases
Branch survey based on NPS score
Create a survey that asks different follow-up questions based on a user's NPS score:
- Add an NPS rating block asking "How likely are you to recommend us?"
- Add conditional logic:
- If
rating ≤ 6(Detractors), then go to step asking "What can we improve?" - If
rating ≥ 9(Promoters), then go to step saying "Thank you! Would you leave us a review?"
- If
Redirect users based on subscription tier
Create a guide with a button that directs users to different pages based on their subscription level:
- Add a primary button labeled "View Features".
- Select Evaluate conditional logic.
- Add conditions:
- If
subscription_tier = premium, then visit linkwww.example.com/premium-features. - If
subscription_tier = free, then visit linkwww.example.com/upgrade.
- If
Show guide only to specific user segments
Launch a secondary guide based on both user property and survey response:
- Add a primary button labeled "Next".
- Select Evaluate conditional logic.
- Add conditions:
- If
country = USANDrating > 8, then show guide "US-specific-offer". - If
country ≠ USANDrating > 8, then show guide "international-offer".
- If
Personalized CTA based on user properties
Create a button action that clicks different elements based on user characteristics:
- Add a primary button labeled "Get Started".
- Select Evaluate conditional logic.
- Add conditions:
- If
user_type = new, then click element[data-testid="onboarding-flow"]. - If
user_type = returning, then click element[data-testid="dashboard"].
- If
Best practices
- Test thoroughly: Use preview mode to test all conditional paths before publishing.
- Keep logic simple: Complex nested conditions can be difficult to maintain and debug.
- Monitor results: Use analytics to track how users flow through your conditional experiences.
Was this helpful?