Skip to content

abTestAssignment: defer setupAB hooks onto pbjs.que when Prebid not ready - #311

Open
jplaroche wants to merge 1 commit into
masterfrom
feat/setupab-defer-prebid-hooks
Open

abTestAssignment: defer setupAB hooks onto pbjs.que when Prebid not ready#311
jplaroche wants to merge 1 commit into
masterfrom
feat/setupab-defer-prebid-hooks

Conversation

@jplaroche

Copy link
Copy Markdown
Contributor

Why

setupAB stamps ortb2Imp.ext.optable.splitTestAssignment onto bids by hooking Prebid's auctionEnd. Its setHooks calls pbjs.getEvents() / pbjs.onEvent() synchronously, so it only works when the Prebid instance is already loaded. Bundles whose Prebid global hydrates late (e.g. AtlasMG's __pmc_atlasmg_pbjs on PMC / SHE Media) have no safe way to pass an instance: passing a queue-only stub throws, and passing nothing means the caller must re-implement the queue dance. OptablePrebidAnalytics.hookIntoPrebid already solves this — setupAB should behave the same way.

What Changed

  • abTestAssignment.ts: split setHooks into registerHooks (the previous direct-attach body) + a new setHooks that mirrors hookIntoPrebid — when pbjsInstance.onEvent is not a function, it defers registration onto pbjsInstance.que; otherwise it registers immediately. Also no-ops on a falsy instance.

How to Test

  • With a ready Prebid instance: setupAB({ variants, pbjs }) attaches immediately and stamps splitTestAssignment on the next auction (unchanged behavior).

  • With a not-yet-loaded instance: setupAB({ variants, pbjs: { que: [] } }) no longer throws; hook registration runs once que is drained by the real Prebid, and bids are stamped from that point.

  • Tested

  • Docs / README updated (if public API changed)

Notes

  • Backwards compatible: the ready-instance path is identical to before; only the not-ready path changes (previously threw / no-op'd).

  • Unblocks removing the bundle-side queue workaround in PMC / SHE Media (optable-solutions) — after this ships they can pass pbjs: getPbjs() straight into setupAB again.

  • Breaking change

  • Requires release

Mirror OptablePrebidAnalytics.hookIntoPrebid: setupAB's setHooks now
checks whether the Prebid instance is ready (onEvent is a function) and,
if not, queues hook registration onto pbjs.que instead of calling
getEvents()/onEvent() directly. Lets callers pass a queue-only stub
({ que: [] }) safely; previously that threw.
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.

2 participants