Prebid Server User ID Sync


Many bidders track their bidder-specific user IDs through cookies. Since bidders will generally serve ads from a different domain than where Prebid Server is hosted, those cookies must be consolidated under the Prebid Server domain so that they can be sent to each demand source as part of auction calls.

How it Works

Prebid Server stores bidder IDs in the uids cookie in the host domain. For example:


Here’s how these IDs get placed in the cookie from Prebid.js:

Prebid Server Cookie Sync

1) Prebid.js starts by calling the Prebid Server /cookie_sync, letting it know which server-side bidders will be participating in the header bidding auction.


{"bidders":["bidderA","bidderB"], "gdpr":1, "gdpr_consent":"...", "us_privacy": "..."}

2) If privacy regulations allow, Prebid Server will look at the uids cookie in the host domain and determine whether any bidders are missing or need to be refreshed. It responds with an array of pixel syncs. e.g.


3) When it receives the response, Prebid.js loops through each element of bidder_status[], dropping a pixel for each bidder_status[].usersync.url.

4) The bidder-specific endpoints read the users’ cookie for the bidder’s domain and respond with a redirect back to Prebid Server’s /setuid endpoint

5) When the browser receives this redirect, it contacts Prebid Server, which will once again check the privacy settings and if allowed, update the uids cookie.

Cookie sync for AMP works in a way quite similar to Prebid.js.

1) The Prebid Server hosting company places a modified version of the load-cookie script onto a CDN. This script is part of the Prebid Universal Creative repo.

The only two values currently valid for ‘endpoint’ are ‘appnexus’ and ‘rubicon’ – other host companies should update their copy to include their endpoint.

See the AMP implementation guide for more information.

2) The publisher places the ‘load-cookie’ script into the page:

<amp-iframe width="1" title="User Sync"
  sandbox="allow-scripts allow-same-origin"
  <amp-img layout="fill" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" placeholder></amp-img>

If the publisher has an AMP Consent Management Platform, they should use load-cookie-with-consent.html.

3) At runtime, the load-cookie script just calls the Prebid Server /cookie_sync endpoint. The rest works the same as described for Prebid.js above.

Bidder Instructions for Building a Sync Endpoint

Building a sync endpoint is optional – there is no benefit from ID syncing for mobile-only bidders. For browser-based bidding, ID syncing can help improve buyer bid rate. There are two main options a bidder can choose to support:

  • redirect: the client will drop an IMG tag into the page, then call the bidder’s URL which needs to redirect to the Prebid Server /setuid endpoint.
  • iframe: the client will drop an IFRAME tag into the page, then call the bidder’s URL which responds with HTML and Javascript that calls the Prebid Server /setuid endpoint at some point.

Bidders must implement an endpoint under their domain which accepts an encoded URI for redirects. This URL should be able to accept privacy parameters:

  • gdpr: if 0, declares this request isn’t in GDPR scope. If 1, declares it is in scope. Otherwise indeterminate.
  • gdpr_consent: the TCF1 or TCF2 consent string. This is unpadded base64-URL encoded.
  • us_privacy: the IAB US Privacy string

The specific attributes can differ for your endpoint. For instance, you could choose to receive gdprConsent rather than gdpr_consent.

Here’s an example that shows the privacy macros as configured in PBS-Go:

    userMacro: YOURMACRO

PBS-Java uses slightly different macros in the bidder config:

  redirect-url: /setuid?bidder=acuityads&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&us_privacy={{us_privacy}}&uid=YOURMACRO

In either case, the {{…}} macros are resolved by PBS.

The “YOURMACRO” string here needs to be whatever your sync endpoint will recognize and resolve to the user’s ID from your domain. Some examples of macros that bidders use: $UID, ${UID}, \(visitor_cookie\), ${DI_USER_ID}, etc. Every bidder has their own value here.

Here’s how this all comes together:

  1. Prebid.js calls Prebid Server’s cookie_sync endpoint
  2. PBS responds with an array of user sync URLs, which may include your bidder’s sync url
  3. Prebid.js drops an img or iframe into the page, causing the browser to connect to the your usersync endpoint.
  4. Your usersync endpoint will return with either a redirect to Prebid Server’s /setuid endpoint or iframe HTML that eventually calls Prebid Server’s /setuid endpoint.
  5. Prebid Server then saves this ID mapping of mybidder: 132 under the cookie at

Then the next time the client then calls, the ID for mybidder will be available in the Cookie. Prebid Server will then stick this value into request.user.buyeruid in the OpenRTB request it sends to mybidder’s bid adapter.

Further Reading