TriggerProvider enables reactive updates when users enter or exit cohorts, allowing your app to respond to segment changes in real-time.
Cohort Triggers
Query Triggers
User ID
Overview
TriggerProvider provides:
- Real-time cohort change notifications
- Immediate callback when users enter/exit cohorts
- Query-based triggers for complex conditions
- User identity change monitoring
Accessing TriggerProvider
Cohort Membership Triggers
Watch for changes in cohort membership:Watching Multiple Cohorts
Query Triggers
For more complex data, use query triggers that return dictionaries or integers:Dictionary Queries
Integer Queries
User ID Triggers
Monitor changes to the user identity:TriggerAction Lifecycle
Keeping Triggers Active
UIViewController Integration
SwiftUI Integration
tvOS Considerations
tvOS Note: TriggerProvider works identically on tvOS. Use it to update UI elements based on cohort membership in your focus-based navigation.
Best Practices
- Do
- Don't
- Store TriggerAction references as instance properties
- Use
[weak self]in closures to avoid retain cycles - Dispatch UI updates to main thread
- Release triggers when no longer needed
- Group related cohorts in a single trigger
Troubleshooting
Trigger callbacks not firing
Trigger callbacks not firing
Problem: No callbacks when cohort membership changes.Solutions:
- Verify you’re storing a strong reference to TriggerAction
- Check that cohort IDs match your dashboard
- Enable debug logging to see cohort updates
- Ensure SDK is initialized before creating triggers
Trigger stops working
Trigger stops working
Problem: Trigger worked initially but stopped.Cause: TriggerAction reference was released.Solution: Store TriggerAction as an instance property, not a local variable.
UI not updating
UI not updating
Problem: Callback fires but UI doesn’t change.Solution: Dispatch UI updates to main thread:
Related Documentation
Cohorts & Activations
Understanding user segments
Identity Management
User identity tracking
Page Tracking
Trigger cohort qualification
Issues
Common problems and solutions