Overview
Real-time triggers enable:- Personalization based on cohort membership
- Dynamic content that updates as users qualify for cohorts
- Conditional logic for features, ads, and experiences
- Real-time reactions to cohort entry and exit
trigger()
React to cohort entry and exit events in real-time. The handler fires whenever the user’s membership in the specified segment changes.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
segmentCode | number | The cohort ID to watch |
parameterName | string | Parameter name (typically "result") |
handler | function | Callback on segment transitions (receives object with result property) |
Example
The handler receives
{ result: true } when the user enters the segment and { result: false } when they exit. For many segments (e.g., “5+ pageviews”), once a user qualifies they typically stay qualified, so you may only see the entry event. To check current membership at any time, use permutive.segment().Trigger Patterns
- Personalization
- Feature Flags
- Messaging
segment()
Check if the user is in a specific cohort.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
segmentCode | number | The cohort ID to check |
handler | function | Callback with boolean result |
Example
Promise Form
Segment Patterns
- Conditional Content
- A/B Testing
- Analytics
segments()
Get all cohorts the user belongs to.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | function | Callback with segments array |
type | string | Optional: ‘all’ (default) or platform-specific (‘dfp’, ‘appnexus’, etc.) |
Example
Promise Form
Segments Patterns
- Ad Targeting
- Analytics
- Personalization
query()
Execute advanced queries against cohort data.Usage
ready()
Wait for SDK initialization or realtime data before checking cohorts.Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | function | Called when stage is reached |
stage | string | ’initialised’ (default) or ‘realtime’ |
Example
Stages
| Stage | When Fires |
|---|---|
initialised | SDK has loaded and initialized |
realtime | Real-time cohort data has been processed |
Ready Patterns
- Wait for Cohorts
- Safe Initialization
readyWithTimeout()
If you need to delay critical actions (like ad requests) until Permutive is ready, usereadyWithTimeout to set a maximum wait time. This ensures your page functions even if the SDK takes longer than expected to load.
Setup
First, add thereadyWithTimeout function to your Permutive tag:
Usage
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | function | Called when ready or timeout is reached |
stage | string | ’initialised’ or ‘realtime’ |
timeoutMs | number | Maximum milliseconds to wait before calling callback anyway |
Example
Using
readyWithTimeout is strongly recommended when delaying ad requests, as it ensures ads will still load even if there’s a network issue with the Permutive SDK.Combining Methods
Check Multiple Cohorts
Watch and Initial Check
Timing Considerations
Why Use ready()?
Trigger Timing
Triggers fire whenever segment membership changes on the current page:{ result: true }when user enters the segment{ result: false }when user exits the segment
Triggers only fire for segment transitions caused by events tracked on the current page via the
track method. For checking a user’s current cohort membership at any time, use permutive.segment() instead.Debugging
Enable debug mode to see cohort activity:Troubleshooting
segments() returns empty array
segments() returns empty array
Problem: No cohorts returned even though user should qualify.Solutions:
- Use
ready('realtime')before callingsegments() - Verify events are being tracked
- Check cohorts are configured and active in dashboard
- Ensure consent is granted (if
consentRequired: true) - Allow time for cohort processing
trigger() not firing
trigger() not firing
Problem: Trigger callback not being called.Solutions:
- Verify cohort ID is correct
- Check that cohort rules would qualify the user
- Enable debug mode to see cohort changes
- Ensure SDK is initialized before setting trigger
segment() always returns false
segment() always returns false
Problem: User should be in cohort but check returns false.Solutions:
- Verify cohort ID matches dashboard
- Check cohort is active (not paused/archived)
- Ensure user meets cohort criteria
- Use
ready('realtime')to ensure data is loaded
Stale cohort data
Stale cohort data
Problem: Cohort membership not updating.Solutions:
- Refresh page to trigger re-evaluation
- Verify new events are being tracked
- Use
trigger()with'result'parameter for real-time updates - Check for SDK errors in console