Skip to content

Running Prebid.js and Amazon TAM together

Short answer

Yes. Prebid.js and Amazon TAM are separate systems that both write targeting onto the same ad server request, so they can run in parallel and compete. The requirement is that they share one timeout and one completion gate: the ad server call must wait for both, and must fire as soon as both are done or the timeout expires, whichever comes first.

Last updated Intermediate

Amazon TAM (Transparent Ad Marketplace) is Amazon's server-side header bidding product. From the page's point of view it looks like a second, independent wrapper: you call apstag.fetchBids(), it returns bids, and you set them as targeting. It brings Amazon demand plus a set of SSPs that transact through Amazon.

Because it is genuinely separate from Prebid, publishers frequently want both. Done well this is free incremental competition. Done badly it doubles your ad latency.

The mistake: chaining them

The naive integration runs Prebid, waits for it to finish, then runs TAM, waits for that, then calls the ad server. Two 1,500 ms timeouts in sequence is a 3-second worst case before a single ad request leaves the browser. On mobile that is catastrophic for viewability, and it will show up in your Core Web Vitals.

The fix: one timeout, one gate

Start both at the same moment. Give them a single shared deadline. Then gate the ad server call on a small counter that fires when both have reported back, or when the deadline hits, whichever happens first.

// Both auctions start together and share one deadline.
var pending = 2;
var sent = false;

function requestAds() {
  if (sent) return;
  sent = true;
  googletag.cmd.push(function () {
    pbjs.setTargetingForGPTAsync();   // Prebid targeting
    apstag.setDisplayBids();          // TAM targeting
    googletag.pubads().refresh();
  });
}

function done() {
  if (--pending === 0) requestAds();
}

// One hard deadline for the whole auction, not one per system.
setTimeout(requestAds, TIMEOUT_MS);

pbjs.requestBids({ timeout: TIMEOUT_MS, bidsBackHandler: done });
apstag.fetchBids({ slots: slots, timeout: TIMEOUT_MS }, done);

The sent flag matters more than it looks. Without it, a bidder that answers just after the timeout fires can trigger a second ad server call, and you get duplicate requests, discrepancies against your ad server reporting, and occasionally two creatives fighting over one slot.

Ordering the targeting calls

Set both sets of targeting before the refresh, and set them on the same slots. If you call setTargetingForGPTAsync() after refresh(), the targeting arrives too late and your header bidding line items never match — the classic symptom is bids appearing in the wrapper's debug output while the ad server reports zero header bidding revenue.

How ssm.codes handles it

The v7 engine runs Prebid and TAM as parallel adapters under one unified timeout, defaulting to 1,500 ms, with the gate and the duplicate-request guard built in. The adaptive mode then tunes that single deadline to the device: shortened by up to 20% on fast connections, extended by 20% on 3G, and bidding skipped entirely on 2G or on devices reporting 1 GB of memory or less, where the auction would cost more in abandonment than it could earn.

Related questions

Does Amazon TAM compete with Prebid or replace it?

It competes. Both write price targeting onto the same ad server request and the ad server picks the highest. They are complementary because the demand only partially overlaps: TAM brings Amazon's own demand plus SSPs transacting through Amazon, some of which you may not have a direct Prebid relationship with.

What timeout should I use when running both?

One shared timeout for the whole auction, not one each. Around 1,500 ms is a reasonable desktop starting point. What matters far more than the exact number is that it is shared and enforced by a single deadline, so the worst case is one timeout rather than the sum of two.

Do I need an Amazon TAM account to use TAM?

Yes. TAM requires approval from Amazon Publisher Services and gives you a pub ID that goes in the tag. It is a direct relationship, like an SSP contract. Approval is not automatic and Amazon applies its own inventory quality standards.

Can I add Google Open Bidding on top of both?

Yes. Open Bidding runs server-side inside Ad Manager rather than in the page, so it adds no client-side latency and resolves in the same unified decision as your header bidding targeting. Running all three is common. The cost is complexity in reconciliation, not speed.

Try it on your own site

Free up to 1 million ad impressions a month. You keep your Ad Manager account and your SSP contracts.

Start free