Skip to content

Conversation

@ChristianPavilonis
Copy link
Collaborator

@ChristianPavilonis ChristianPavilonis commented Feb 9, 2026

Passes Permutive audience segments from the browser through to the ad server mediation endpoint, enabling segment-targeted ad decisioning.

  • Introduces a context provider registry on the JS side (context.ts) — a generic mechanism for integrations to contribute data to auction requests without core needing integration-specific knowledge.
  • The Permutive integration registers a context provider that reads cohort segments from localStorage (permutive-app key) and injects them as permutive_segments in the request config.
  • On the Rust side, convert_tsjs_to_auction_request now forwards all config entries into the AuctionRequest.context map instead of discarding them.
  • The AdServer Mock provider reads permutive_segments from the context and appends them as a ?permutive=seg1,seg2,... query parameter on the mediation endpoint URL.
    Changes
Layer File What
JS core core/context.ts (new) Context provider registry (registerContextProvider, collectContext)
JS core core/request.ts Calls collectContext() to build config payload
JS integration integrations/permutive/segments.ts (new) Reads segments from localStorage (core.cohorts.all primary, eventUpload fallback)
JS integration integrations/permutive/index.ts Registers context provider with Permutive segments
Rust common auction/formats.rs Forwards config entries into AuctionRequest.context
Rust common integrations/adserver_mock.rs build_endpoint_url() appends ?permutive= query param
Tests context.test.ts, segments.test.ts, Rust unit tests Full coverage for new functionality

Closes #132


How to Manually Test

  1. Verify Permutive segment extraction (JS)
  2. Open a publisher page that has Permutive active (or any page where you can set localStorage manually).
  3. Open DevTools Console and confirm localStorage.getItem('permutive-app') has data — look for core.cohorts.all containing segment IDs.
  4. If testing without a real Permutive install, seed it manually:
      localStorage.setItem('permutive-app', JSON.stringify({
     core: { cohorts: { all: ['10000001', '10000003', 'adv', 'bhgp'] } }
   }));
  1. Load the page with the tsjs tag. In the DevTools Console, filter for context — you should see a log like:
    requestAds: payload { units: N, contextKeys: ["permutive_segments"] }

  2. Verify segments are sent to the server

  3. Open DevTools Network tab and filter for /auction.

  4. Trigger an ad request.

  5. Inspect the /auction POST request body — the config object should contain:

      {
     config: {
       permutive_segments: [10000001, 10000003, adv, bhgp]
     }
   }

@ChristianPavilonis ChristianPavilonis marked this pull request as ready for review February 11, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

As publisher I want to see Permutive segment propagate to ad server

2 participants