Skip to content

feat(addons): add abTestAssignment addon#306

Merged
mosherBT merged 7 commits into
masterfrom
abTestAssignment
Jul 20, 2026
Merged

feat(addons): add abTestAssignment addon#306
mosherBT merged 7 commits into
masterfrom
abTestAssignment

Conversation

@jrosendahl-opt

@jrosendahl-opt jrosendahl-opt commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Moved all of the client side A/B test management to a single add-on.

##Changes

  • Adds lib/edge/abTest.ts with determineABTest extracted from targeting.ts — keeps the core assignment logic in the edge layer where targeting can use it without depending on addons
  • Adds lib/addons/abTestAssignment.ts with setupAB: manages client-side A/B variant assignment with localStorage stickiness, sessionStorage override, and Prebid bid stamping via applyToAuctionEvent / setHooks
  • Removes determineABTest and the unused ABTestConfig re-export from targeting.ts
  • Moves determineABTest tests from targeting.test.js into abTestAssignment.test.ts
  • Adds lib/addons/abTestAssignment.md with usage docs

jrosendahl-opt and others added 2 commits July 17, 2026 15:01
…ineABTest to edge/abTest

- Add lib/edge/abTest.ts with determineABTest (moved from targeting.ts)
- Add lib/addons/abTestAssignment.ts with setupAB: handles variant assignment,
  localStorage stickiness, sessionStorage override, and prebid bid stamping
  via applyToAuctionEvent/setHooks
- Remove determineABTest and ABTestConfig re-export from targeting.ts
- Move determineABTest tests from targeting.test.js to abTestAssignment.test.ts
- Add usage README at lib/addons/abTestAssignment.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
// sessionStorage unavailable
}

if (!selected) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow here needs to be more heavily commented. Just to explain first visit vs cache and things that are not immediately obvious on reading code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lib/addons/abTestAssignment.ts Outdated
let selected: ABTestConfig | null = null;

try {
const override = sessionStorage.getItem(sessionOverrideKey);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to accept this from the URL as well optableControlGroup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a mistake devs can make, I pulled out flags into a separate function to manage them. Modules should always call getFlags() from not on.

applyToAuctionEvent,
setHooks,
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing cache clearing based on split test. I think that will bite us so we need to address it.

Something like this

// Control group: clear cached EIDs so RTD/PPID/targetingFromCache serve nothing
if (isControlGroup) {
  try {
    localStorage.removeItem('OPTABLE_RESOLVED');
    Object.keys(localStorage)
      .filter((k) => k.startsWith('OPTABLE_TARGETING_'))
      .forEach((k) => localStorage.removeItem(k));
  } catch {
    /* ignore */
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object.keys portion (including the 2 next lines), can be replaced with {SDK}.targetingClearCache();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also fixed.

jrosendahl-opt and others added 4 commits July 20, 2026 11:01
…ds from modules

- Add lib/core/flags.ts: single place that reads URL params (with sessionStorage
  fallback) into a Flags object; lazy singleton, reset via resetFlags() for tests
- Update lib/core/prebid/rtd.ts to read optableDebug, optableForceGlobalRouting,
  and optableForceSkipMerge from getFlags() instead of sessionStorage directly
- Update lib/addons/abTestAssignment.ts to read optableControlGroup from getFlags()
  and remove sessionOverrideKey config option
- Add lib/core/flags.test.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… and first-visit assignment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Prevents stale Optable targeting data from a previous session being served
to users who are subsequently assigned to the control group.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…p cache clearing

When an SDK instance is provided, use its targetingClearCache() method for
precise key removal instead of a localStorage prefix scan. Falls back to the
prefix scan when no SDK instance is available.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace getSplitTestAssignment() function with splitTestAssignment string
- Remove applyToAuctionEvent from public API (internal to setHooks)
- Accept pbjs in SetupABConfig to register hooks automatically at setup time;
  setHooks() remains on result for deferred registration when pbjs is not
  yet available

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mosherBT
mosherBT merged commit 9f3a88a into master Jul 20, 2026
7 checks passed
@mosherBT
mosherBT deleted the abTestAssignment branch July 20, 2026 20:13
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.

3 participants