Deferred Client-Side UID2 Integration with Prebid.js

This example demonstrates how to integrate UID2 with Prebid.js using deferred configuration. Unlike the standard integration where UID2 is configured on page load, this pattern uses mergeConfig() and refreshUserIds() to add UID2 after the page has loaded. [Source Code]

๐Ÿ“„ Initial Prebid Config (on page load)

Notice: No UID2 userIds configured - this is intentional for deferred loading.


        

What happens when you click "Configure":

  1. pbjs.mergeConfig(uidConfig) - Merges UID2 user ID module configuration into the existing Prebid config without overwriting other settings. This allows adding UID2 after the page has already loaded.
  2. pbjs.refreshUserIds({ submoduleNames: ['uid2'] }) - Triggers Prebid to re-fetch the UID2 user ID specifically, which initiates token generation using the provided email and CSTG credentials.

What happens when you click "Clear":

  1. localStorage.removeItem(storageKey) - Clears the UID2 identity from browser storage.
  2. location.reload() - Reloads the page to clear Prebid's in-memory cache, preventing future bid requests from using the old token.

Why reload? UID2 state lives in browser storage and Prebid's memory. Prebid only reads the tokenโ€”it doesn't provide a method to clear just UID2 without affecting other ID modules. Page reload ensures a clean state.

UID2 Integration Status

Ready for Targeted Advertising:
?
Indicates whether a valid UID2 token is present and can be used for personalized ad targeting.
Advertising Token:
?
The encrypted UID2 token that is passed to ad systems without exposing raw user identity.
Is Login Required?
?
Indicates whether a new UID2 token needs to be generated. Returns "yes" when no valid identity exists or the current identity has expired.
Has Opted Out?
?
Shows whether the user has exercised opt-out, in which case no advertising token may be generated or used.

Prebid Integration Status

Prebid.js uses mergeConfig() to add UID2 after the page has loaded, then refreshUserIds() triggers token generation.

Prebid Token Storage:
?
Shows the UID2 token stored by Prebid in localStorage under the key '__uid2_advertising_token'. Prebid manages this storage for header bidding.