Learn

← Track B: Client-Side Prebid.js
L3

B4

The auction lifecycle and bidsBackHandler

In this lesson you will
  • Sequence the auction: requestBids() fires adapters in parallel, responses are collected, bidsBackHandler fires on all-back or timeout, then targeting is set and the ad server is called.
  • Use the Prebid event system.

You call one function, and a stopwatch starts. Several SSPs are asked at once, bids trickle in, and at some deadline Prebid says "time is up" and hands the best price to your ad server. Understand that timeline and you can debug almost anything.

The whole auction hangs off requestBids(). Here is the sequence, start to finish:

The auction lifecycle
  1. 1requestBids() fires every bid adapter in parallel.
  2. 2Bid responses are collected as they arrive.
  3. 3bidsBackHandler fires when all bids are back OR the timeout hits, whichever comes first.
  4. 4setTargetingForGPTAsync() writes the winning key-values onto the ad slots.
  5. 5The ad server is called, and it decides the final winner across header demand and its own.
pbjs.requestBids({
  timeout: 1500,
  bidsBackHandler: function () {
    pbjs.setTargetingForGPTAsync();
    googletag.pubads().refresh();
  },
});
A minimal bidsBackHandler

The Prebid event system (pbjs.onEvent with bidWon, bidResponse, bidTimeout, and more) lets you hook the lifecycle for analytics and debugging without changing the core flow.

Quick check

Your bidsBackHandler runs with `timedOut: true`. What does that tell you?

Note

When bids arrive late or the page feels slow, this lifecycle is the map. The Debug "Timeouts / slow page" runbook walks it.

Key concepts
requestBids()bidsBackHandler (all-back or timeout)setTargetingForGPTAsync()The Prebid event system
Going deeper

To really lock this in: order a scrambled lifecycle, explain timedOut: true, and write a bidsBackHandler that calls setTargetingForGPTAsync() then refresh.

Where this leads
DEBUG

Proposed auction-timeline simulator.

Bidcliq Academy · B4: The auction lifecycle and bidsBackHandler