Skip to main content
The SDK provides methods to check cohort membership and react to changes in real-time, enabling dynamic personalization and targeting.

trigger()

segment()

segments()

query()

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

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

segment()

Check if the user is in a specific cohort.

Usage

Parameters

Example

Promise Form

Segment Patterns

segments()

Get all cohorts the user belongs to.

Usage

Parameters

Example

Promise Form

Segments Patterns

query()

Execute advanced queries against cohort data.

Usage

The query() method is reserved for future functionality and currently returns { result: false }. Use segment() to check individual cohort membership or segments() to get all cohorts.

ready()

Wait for SDK initialization or realtime data before checking cohorts.

Usage

Parameters

Example

Stages

Ready Patterns

readyWithTimeout()

If you need to delay critical actions (like ad requests) until Permutive is ready, use readyWithTimeout to set a maximum wait time. This ensures your page functions even if the SDK takes longer than expected to load.

Setup

First, add the readyWithTimeout function to your Permutive tag:

Usage

Parameters

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:
Console output:

Troubleshooting

Problem: No cohorts returned even though user should qualify.Solutions:
  • Use ready('realtime') before calling segments()
  • 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
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
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
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

Cohorts & Activations

Understanding cohort system

Event Tracking

Events that power cohorts

Google Ad Manager

Use cohorts for ad targeting

Custom Cohorts

Build cohorts in dashboard