State Transitions
State transitions define how your state machine moves between states based on events.
Basic Transition
A transition specifies:
- From State: Current state
- To State: Target state
- Event: Event that triggers the transition
- Filters (optional): Conditions that must be met
Structure
{
"stateTransition": {
"EVENT_NAME": {
"currentState": [
{
"transitionTo": "targetState",
"filters": { /* optional */ }
}
]
}
}
}
Simple Example
{
"stateTransition": {
"USER_LOGIN": {
"0": [
{
"transitionTo": "1"
}
]
}
}
}
Meaning: When USER_LOGIN event occurs and state machine is in state "0", transition to state "1".
Multiple Transitions
You can define multiple transitions for the same event:
{
"stateTransition": {
"BUTTON_CLICKED": {
"0": [
{
"transitionTo": "1",
"filters": {
"operator": "AND",
"filter": [
{
"propertyName": "buttonId",
"propertyType": "string",
"comparisonType": "=",
"comparisonValue": "signup"
}
]
}
},
{
"transitionTo": "2",
"filters": {
"operator": "AND",
"filter": [
{
"propertyName": "buttonId",
"propertyType": "string",
"comparisonType": "=",
"comparisonValue": "login"
}
]
}
}
]
}
}
}
Meaning:
Transition Priority
When multiple transitions are defined, the SDK evaluates them in order and takes the first matching transition. Make sure to order them correctly:
{
"stateTransition": {
"BUTTON_CLICKED": {
"0": [
{
"transitionTo": "1",
"filters": {
"operator": "AND",
"filter": [
{
"propertyName": "userType",
"propertyType": "string",
"comparisonType": "=",
"comparisonValue": "premium"
}
]
}
},
{
"transitionTo": "2"
// No filters - this is the default case
}
]
}
}
}
Flow:
Multiple Events
You can define transitions for multiple events:
{
"stateTransition": {
"USER_LOGIN": {
"0": [{"transitionTo": "1"}]
},
"BUTTON_CLICKED": {
"1": [{"transitionTo": "2"}],
"2": [{"transitionTo": "3"}]
},
"SCREEN_VIEW": {
"3": [{"transitionTo": "4"}]
}
}
}
State Machine Flow Example
{
"stateTransition": {
"APP_LAUNCH": {
"0": [{"transitionTo": "1"}]
},
"BUTTON_CLICKED": {
"1": [{"transitionTo": "2"}],
"2": [{"transitionTo": "3"}]
},
"NUDGE_DISMISSED": {
"3": [{"transitionTo": "0"}]
}
}
}
Flow Diagram:
Conditional Transitions with Filters
Use filters to add conditions to transitions:
{
"stateTransition": {
"USER_LOGIN": {
"0": [
{
"transitionTo": "1",
"filters": {
"operator": "AND",
"filter": [
{
"propertyName": "userType",
"propertyType": "string",
"comparisonType": "=",
"comparisonValue": "premium"
},
{
"propertyName": "loginCount",
"propertyType": "number",
"comparisonType": ">",
"comparisonValue": 5
}
]
}
}
]
}
}
}
Meaning: Only transition if user is premium AND has logged in more than 5 times.
See Filters for detailed filter documentation.
No Transition
If no transition matches, the state machine stays in its current state:
{
"stateTransition": {
"BUTTON_CLICKED": {
"0": [
{
"transitionTo": "1",
"filters": {
"operator": "AND",
"filter": [
{
"propertyName": "buttonId",
"propertyType": "string",
"comparisonType": "=",
"comparisonValue": "signup"
}
]
}
}
]
}
}
}
If buttonId is not "signup", no transition occurs and state remains "0".
Best Practices
- Order Matters: Place more specific transitions before general ones
- Use Filters: Add filters to make transitions conditional
- Default Cases: Include default transitions without filters when needed
- Clear State Names: Use meaningful state names (or numbers) for clarity
- Reset States: Define reset states to clean up completed flows