Skip to content

feat(ab-test): add selectABTest addon for split test selection and persistence#279

Open
MO-Thibault wants to merge 2 commits intoOptable:masterfrom
MO-Thibault:mo/ab-test-addon
Open

feat(ab-test): add selectABTest addon for split test selection and persistence#279
MO-Thibault wants to merge 2 commits intoOptable:masterfrom
MO-Thibault:mo/ab-test-addon

Conversation

@MO-Thibault
Copy link
Copy Markdown
Contributor

Summary

Extracts A/B test selection logic that lives duplicated across wrapper bundles into a reusable addon at lib/addons/prototypes/ab-test.js.

Exports:

  • calculateTrafficPercentages(abTests) — fills missing trafficPercentage values by distributing the remaining % evenly
  • determineABTest(abTests) — weighted random bucket selection (mirrors lib/edge/targeting.ts)
  • selectABTest(abTests) — full selection flow: forced overrides → exclude filter → random selection → persist to sessionStorage.OPTABLE_SPLIT_TEST

sessionStorage override keys (value "1" or "true" to activate):

  • optableInclude<ID> / optableResolve<ID> — force a specific test
  • optableExclude<ID> / optableInclude<ID>=false — exclude a test from random selection

OptablePrebidAnalytics accepts config.selectedTest (the result of selectABTest) and includes selectedABTest in every auction_processed witness payload.

Migration for wrappers

import { selectABTest } from '@optable/web-sdk/lib/dist/addons/prototypes/ab-test';

const selectedTest = selectABTest([
  { id: 'none', trafficPercentage: 5 },
  { id: 'all' }, // auto-filled to 95%
]);

// side effects (RTD gating, localStorage) stay in wrapper
window.optable.disabled = selectedTest?.id === 'none';
localStorage.setItem('OPTABLE_ENABLED', !window.optable.disabled);

new OptablePrebidAnalytics(optableInstance, {
  analytics: true,
  tenant: 'aditude',
  selectedTest,
});

Wrappers can drop: calculateTrafficPercentages, determineABTest, splitTestSelection, and the customAnalytics.selectedABTest block.

Test plan

  • selectABTest returns null for empty/null input
  • Traffic percentages auto-fill correctly when some tests omit trafficPercentage
  • Forced override via optableIncludeNONE=1 selects the none test regardless of random
  • Exclude override via optableExcludeNONE=1 removes none from random pool
  • Result persisted to sessionStorage.OPTABLE_SPLIT_TEST
  • selectedABTest appears in witness payload when config.selectedTest is set

…rsistence

Extracts A/B test selection logic from wrapper bundles into a reusable addon:
- calculateTrafficPercentages: fills missing trafficPercentage values evenly
- determineABTest: weighted random bucket selection (mirrors lib/edge/targeting.ts)
- selectABTest: full selection flow — forced overrides via sessionStorage
  (optableInclude<ID>, optableResolve<ID>, optableExclude<ID>), excludes marked
  tests, falls back to random, persists result to OPTABLE_SPLIT_TEST

OptablePrebidAnalytics accepts config.selectedTest (result of selectABTest) and
includes selectedABTest in every auction_processed witness payload.

Wrappers can replace calculateTrafficPercentages + determineABTest + splitTestSelection
with a single selectABTest() call.
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.

1 participant