Skip to main content
Cohorts are the core mechanism for user segmentation in Permutive. The SDK provides methods to check cohort membership and react to changes in real-time.

What are Cohorts

Activations

SDK Methods

What are Cohorts

Cohort Types

How Cohorts Work

  1. Events are tracked via the SDK (pageviews, custom events, etc.)
  2. Rules are evaluated against user behavior
  3. Users enter/exit cohorts based on rule matching
  4. Cohorts are stored locally in the browser
  5. Cohorts are passed to ad platforms for targeting
User views sports article → Track Pageview event

                    Permutive evaluates rules

                    User enters "sports_enthusiast" cohort

                    Cohort stored in localStorage

                    Cohort passed to ad requests

Activations

Activation Types

Cohorts vs Activations

Accessing Cohorts

Get All Segments

// Get all cohorts the user belongs to
permutive.segments(function(segments) {
  console.log('All segments:', segments);
  // Output: [12345, 67890, 11111, ...]
});

Get Platform-Specific Segments

// Get cohorts activated for Google Ad Manager (DFP)
permutive.segments(function(segments) {
  console.log('DFP segments:', segments);
}, 'dfp');

// Get cohorts activated for AppNexus
permutive.segments(function(segments) {
  console.log('AppNexus segments:', segments);
}, 'appnexus');

Check Single Cohort Membership

// Check if user is in a specific cohort
permutive.segment(12345, function(inCohort) {
  if (inCohort) {
    console.log('User is in cohort 12345');
    showPremiumContent();
  } else {
    console.log('User is NOT in cohort 12345');
    showStandardContent();
  }
});

Wait for Cohort Data

Use ready() with the 'realtime' stage to ensure cohort data is available:
permutive.ready(function() {
  // Cohort data is now available
  permutive.segments(function(segments) {
    console.log('Segments (after ready):', segments);
  });
}, 'realtime');

Real-Time Triggers

React to cohort changes as they happen:
// Trigger when user enters/exits a cohort
permutive.trigger(12345, 'result', function(obj) {
  if (obj.result) {
    console.log('User just ENTERED cohort 12345');
  } else {
    console.log('User just EXITED cohort 12345');
  }
});
See Real-Time Triggers for more details.

localStorage Structure

Cohorts are stored in localStorage for fast access and ad targeting:
KeyPurpose
_psegsAll cohorts
_pdfpsGoogle Ad Manager (DFP) activations
_papnsAppNexus activations
_prubiconsRubicon activations
_ppubmaticsPubMatic activations
// Direct localStorage access (for debugging)
var allCohorts = JSON.parse(localStorage.getItem('_psegs') || '[]');
var dfpCohorts = JSON.parse(localStorage.getItem('_pdfps') || '[]');
Always use the SDK methods (segments(), segment()) rather than reading localStorage directly in production code. The SDK handles synchronization and edge cases.

Using Cohorts with Ad Platforms

// Using the DFP addon (automatic)
permutive.addon('web', { page: { type: 'article' } });
// Targeting is set automatically

// Manual targeting
permutive.segments(function(segments) {
  googletag.cmd.push(function() {
    googletag.pubads().setTargeting('permutive', segments);
  });
}, 'dfp');

Prebid.js

Cohorts are automatically passed to Prebid via the RTD module. See Prebid Integration.

AppNexus/Xandr

permutive.segments(function(segments) {
  // Use segments for AppNexus targeting
  apntag.setKeywords('permutive', segments);
}, 'appnexus');

Cohort Patterns

// Personalize content based on cohorts
permutive.ready(function() {
  permutive.segment(12345, function(isPremiumUser) {
    if (isPremiumUser) {
      showPremiumLayout();
      hideAds();
    }
  });
}, 'realtime');

Event-Based Cohort Updates

Cohorts update in real-time as users take actions:
// User reads an article about sports
permutive.addon('web', {
  page: {
    type: 'article',
    article: {
      categories: ['sports', 'football']
    }
  }
});

// Moments later, check if they entered the sports cohort
permutive.trigger(12345, 'segment', function(inSportsCohort) {
  if (inSportsCohort) {
    console.log('User just qualified for sports cohort!');
  }
});

Debugging Cohorts

Enable debug mode to see cohort activity:
?__permutive.loggingEnabled=true
Console output includes:
[Permutive] Segments updated: [12345, 67890, ...]
[Permutive] User entered segment: 12345
[Permutive] DFP segments: [12345]

Troubleshooting

Problem: No cohorts even after tracking events.Solutions:
  • Use ready('realtime') to wait for data
  • Check that events are being tracked (debug mode)
  • Verify cohorts are configured in dashboard
  • Ensure user hasn’t opted out (consent)
  • Allow time for cohort processing (seconds to minutes)
Problem: Events tracked but user not in cohort.Solutions:
  • Verify cohort rules in dashboard
  • Check event properties match rule conditions
  • Confirm cohort is active (not paused/archived)
  • Check cohort minimum threshold/frequency
Problem: User in cohort but activation array differs.Solutions:
  • Check that cohort is activated for the platform
  • Verify activation configuration in dashboard
  • Use correct type parameter: segments(cb, 'dfp')
Problem: Cohorts not updating after new events.Solutions:
  • Cohorts update in real-time but may take a few seconds
  • Refresh page to trigger re-evaluation
  • Check that new events are actually being tracked
  • Use trigger() for real-time change detection

Real-Time Triggers

React to cohort changes

Custom Cohorts

Build cohorts in dashboard

Contextual Cohorts

Content-based cohorts

Google Ad Manager

GAM targeting setup