feat(addons): add abTestAssignment addon#306
Conversation
…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) { |
There was a problem hiding this comment.
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
| let selected: ABTestConfig | null = null; | ||
|
|
||
| try { | ||
| const override = sessionStorage.getItem(sessionOverrideKey); |
There was a problem hiding this comment.
I think we need to accept this from the URL as well optableControlGroup
There was a problem hiding this comment.
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, | ||
| }; | ||
| } |
There was a problem hiding this comment.
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 */
}
}
There was a problem hiding this comment.
The object.keys portion (including the 2 next lines), can be replaced with {SDK}.targetingClearCache();
…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>
Summary
Moved all of the client side A/B test management to a single add-on.
##Changes
lib/edge/abTest.tswithdetermineABTestextracted fromtargeting.ts— keeps the core assignment logic in the edge layer where targeting can use it without depending on addonslib/addons/abTestAssignment.tswithsetupAB: manages client-side A/B variant assignment with localStorage stickiness, sessionStorage override, and Prebid bid stamping viaapplyToAuctionEvent/setHooksdetermineABTestand the unusedABTestConfigre-export fromtargeting.tsdetermineABTesttests fromtargeting.test.jsintoabTestAssignment.test.tslib/addons/abTestAssignment.mdwith usage docs