> ## Documentation Index
> Fetch the complete documentation index at: https://docs.permutive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cohorts and Activations

> Understanding user segmentation in the Permutive JavaScript SDK

export const CohortsVsActivationsTable = () => <table>
    <thead>
      <tr>
        <th>Aspect</th>
        <th>Cohorts</th>
        <th>Activations</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><strong>Definition</strong></td>
        <td>All segments a user belongs to</td>
        <td>Cohorts configured for specific platforms</td>
      </tr>
      <tr>
        <td><strong>Scope</strong></td>
        <td>Entire Permutive system</td>
        <td>Platform-specific</td>
      </tr>
      <tr>
        <td><strong>Purpose</strong></td>
        <td>User segmentation</td>
        <td>Ad targeting</td>
      </tr>
      <tr>
        <td><strong>Configuration</strong></td>
        <td>Automatic based on events</td>
        <td>Configured in dashboard</td>
      </tr>
    </tbody>
  </table>;

export const ActivationTypesTable = () => <table>
    <thead>
      <tr>
        <th>Activation Type</th>
        <th>Platform</th>
        <th>Use Case</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><code>dfp</code></td>
        <td>Google Ad Manager</td>
        <td>Standard behavioral cohort activations</td>
      </tr>
      <tr>
        <td><code>dfp_contextual</code></td>
        <td>Google Ad Manager</td>
        <td>Real-time contextual cohorts</td>
      </tr>
      <tr>
        <td><code>appnexus_adserver</code></td>
        <td>Xandr/AppNexus</td>
        <td>Standard behavioral cohort activations</td>
      </tr>
      <tr>
        <td><code>appnexus_adserver_contextual</code></td>
        <td>Xandr/AppNexus</td>
        <td>Real-time contextual cohorts</td>
      </tr>
      <tr>
        <td><code>freewheel</code></td>
        <td>Freewheel</td>
        <td>CTV/video ad targeting</td>
      </tr>
    </tbody>
  </table>;

export const ActivationDefinition = () => <>
    <p><strong>Activations</strong> are subsets of cohorts configured for specific ad platforms. Not all cohorts are activated for all platforms—activations allow you to control which cohorts are sent to which ad networks.</p>
    <AccordionGroup>
      <Accordion title="Why use Activations?" icon="circle-question">
        <ul>
          <li><strong>Platform-specific targeting</strong> - Different ad platforms may need different cohorts</li>
          <li><strong>Data governance</strong> - Control which platforms receive which user segments</li>
          <li><strong>Performance optimization</strong> - Only send relevant cohorts to each platform</li>
          <li><strong>Compliance</strong> - Manage consent and privacy requirements per platform</li>
        </ul>
      </Accordion>
    </AccordionGroup>
  </>;

export const CohortTypes = () => <Tabs>
    <Tab title="Behavioral">
      <p>Based on user actions and event patterns tracked through the SDK.</p>
      <p><strong>Example:</strong> A user who reads 5+ sports articles becomes part of the "sports_enthusiast" cohort.</p>
      <pre><code>{`User reads article about tennis
    ↓
Track event: "Pageview" with properties
    ↓
Permutive evaluates: "User read 3+ sports articles in 7 days?"
    ↓
User enters cohort: "sports_enthusiast"`}</code></pre>
    </Tab>
    <Tab title="Classification Model">
      <p>Generated using machine learning models that predict user characteristics.</p>
      <p><strong>Example:</strong> ML model predicts user is likely to purchase premium subscription based on browsing patterns.</p>
    </Tab>
    <Tab title="Contextual">
      <p>Based on real-time content analysis of the current page or video being viewed.</p>
      <p><strong>Example:</strong> User viewing a page about electric vehicles gets contextual cohort "automotive_electric_vehicles" for that session.</p>
      <p><strong>Key characteristics:</strong></p>
      <ul>
        <li><strong>Real-time</strong> - Generated immediately when content is viewed</li>
        <li><strong>Transient</strong> - Only active while viewing the content</li>
        <li><strong>Privacy-friendly</strong> - No long-term user profiling required</li>
      </ul>
    </Tab>
  </Tabs>;

export const CohortDefinition = () => <>
    <p>A <strong>cohort</strong> is a privacy-safe representation of an audience.</p>
    <p>Traditionally, user IDs like third-party cookies have been used to communicate information about audiences and activate (target) them. A publisher might communicate behavioral data for a user to an ad server by attaching the data to a cookie ID. The ad server uses the cookie ID to record information about the user—both information from the publisher and other data parties they work with—and the ad server can later target an ad for a request from that user based on the information it has attached to their cookie ID.</p>
    <p>With cohorts, a code represents the group of users that fall into an audience. In the example above, when the publisher requests an ad from the ad server for the user, it includes the cohort code in the request, but not a user ID. The ad server can use the cohort code(s) to decision on the ad to respond with, but no other publisher or user data is leaked and a profile of the user cannot be built.</p>
    <p>By removing user identifiers from the equation, users' privacy is protected, the publisher's data cannot be targeted off of their site/app, and publishers can provide reachability (scale) to the ecosystem since cohorts can be built & activated in environments like Apple Safari, Mozilla Firefox, and iOS where third-party cookies and other deterministic identifiers are prohibited.</p>
  </>;

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.

<CardGroup cols={3}>
  <Card title="What are Cohorts" href="#what-are-cohorts" icon="users" />

  <Card title="Activations" href="#activations" icon="bullhorn" />

  <Card title="SDK Methods" href="#accessing-cohorts" icon="code" />
</CardGroup>

## What are Cohorts

<CohortDefinition />

## Cohort Types

<CohortTypes />

## 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

<ActivationDefinition />

### Activation Types

<ActivationTypesTable />

## Cohorts vs Activations

<CohortsVsActivationsTable />

## Accessing Cohorts

### Get All Segments

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

### Get Platform-Specific Segments

```javascript theme={"dark"}
// 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

```javascript theme={"dark"}
// 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:

```javascript theme={"dark"}
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:

```javascript theme={"dark"}
// 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](/sdks/web/javascript-sdk/features/real-time-triggers) for more details.

## localStorage Structure

Cohorts are stored in localStorage for fast access and ad targeting:

| Key           | Purpose                             |
| ------------- | ----------------------------------- |
| `_psegs`      | All cohorts                         |
| `_pdfps`      | Google Ad Manager (DFP) activations |
| `_papns`      | AppNexus activations                |
| `_prubicons`  | Rubicon activations                 |
| `_ppubmatics` | PubMatic activations                |

```javascript theme={"dark"}
// Direct localStorage access (for debugging)
var allCohorts = JSON.parse(localStorage.getItem('_psegs') || '[]');
var dfpCohorts = JSON.parse(localStorage.getItem('_pdfps') || '[]');
```

<Warning>
  Always use the SDK methods (`segments()`, `segment()`) rather than reading localStorage directly in production code. The SDK handles synchronization and edge cases.
</Warning>

## Using Cohorts with Ad Platforms

### Google Ad Manager

```javascript theme={"dark"}
// 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](/sdks/web/javascript-sdk/integrations/prebid).

### AppNexus/Xandr

```javascript theme={"dark"}
permutive.segments(function(segments) {
  // Use segments for AppNexus targeting
  apntag.setKeywords('permutive', segments);
}, 'appnexus');
```

## Cohort Patterns

<Tabs>
  <Tab title="Personalization">
    ```javascript theme={"dark"}
    // Personalize content based on cohorts
    permutive.ready(function() {
      permutive.segment(12345, function(isPremiumUser) {
        if (isPremiumUser) {
          showPremiumLayout();
          hideAds();
        }
      });
    }, 'realtime');
    ```
  </Tab>

  <Tab title="Paywall">
    ```javascript theme={"dark"}
    // Adjust paywall based on user segments
    permutive.segments(function(segments) {
      var isHighValueUser = segments.includes(54321);
      var isFrequentReader = segments.includes(98765);

      if (isHighValueUser && !isFrequentReader) {
        showSoftPaywall();
      }
    });
    ```
  </Tab>

  <Tab title="A/B Testing">
    ```javascript theme={"dark"}
    // Use cohorts for A/B test targeting
    permutive.segment(11111, function(inTestGroup) {
      if (inTestGroup) {
        runExperimentVariantB();
      } else {
        runExperimentVariantA();
      }
    });
    ```
  </Tab>

  <Tab title="Analytics">
    ```javascript theme={"dark"}
    // Pass cohorts to analytics
    permutive.segments(function(segments) {
      analytics.identify({
        permutive_cohorts: segments.slice(0, 10) // Top 10 cohorts
      });
    });
    ```
  </Tab>
</Tabs>

## Event-Based Cohort Updates

Cohorts update in real-time as users take actions:

```javascript theme={"dark"}
// 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

<AccordionGroup>
  <Accordion title="segments() returns empty array">
    **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)
  </Accordion>

  <Accordion title="User doesn't enter expected cohort">
    **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
  </Accordion>

  <Accordion title="Activations not matching cohorts">
    **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')`
  </Accordion>

  <Accordion title="Stale cohort data">
    **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
  </Accordion>
</AccordionGroup>

## Related Documentation

<CardGroup cols={2}>
  <Card title="Real-Time Triggers" icon="bell" href="/sdks/web/javascript-sdk/features/real-time-triggers">
    React to cohort changes
  </Card>

  <Card title="Custom Cohorts" icon="users" href="/products/signals/cohorts/custom">
    Build cohorts in dashboard
  </Card>

  <Card title="Contextual Cohorts" icon="bullseye" href="/products/signals/cohorts/contextual">
    Content-based cohorts
  </Card>

  <Card title="Google Ad Manager" icon="rectangle-ad" href="/sdks/web/javascript-sdk/integrations/google-ad-manager">
    GAM targeting setup
  </Card>
</CardGroup>
