abTestAssignment: defer setupAB hooks onto pbjs.que when Prebid not ready - #311
Open
jplaroche wants to merge 1 commit into
Open
abTestAssignment: defer setupAB hooks onto pbjs.que when Prebid not ready#311jplaroche wants to merge 1 commit into
jplaroche wants to merge 1 commit into
Conversation
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.
mosherBT
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
setupABstampsortb2Imp.ext.optable.splitTestAssignmentonto bids by hooking Prebid'sauctionEnd. ItssetHookscallspbjs.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_pbjson 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.hookIntoPrebidalready solves this —setupABshould behave the same way.What Changed
abTestAssignment.ts: splitsetHooksintoregisterHooks(the previous direct-attach body) + a newsetHooksthat mirrorshookIntoPrebid— whenpbjsInstance.onEventis not a function, it defers registration ontopbjsInstance.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 stampssplitTestAssignmenton the next auction (unchanged behavior).With a not-yet-loaded instance:
setupAB({ variants, pbjs: { que: [] } })no longer throws; hook registration runs oncequeis 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 intosetupABagain.Breaking change
Requires release