-
Notifications
You must be signed in to change notification settings - Fork 0
Create new sample page deferred prebid #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7bf99aa
2d39965
d2ef071
6941e26
0dbd6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,14 +58,6 @@ | |
| // Read from localStorage | ||
| const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>'; | ||
| const secureSignalsStorage = localStorage[secureSignalsStorageKey]; | ||
| const token = sdk.getAdvertisingToken(); | ||
|
|
||
| // Safety net: If token exists but Secure Signals haven't loaded yet, reload the page | ||
| if (token && !secureSignalsStorage && !<%= isOptout %>) { | ||
| console.log("Token exists but Secure Signals not loaded yet, reloading page..."); | ||
| location.reload(); | ||
| return; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the infinite reload loop in secure signals client server (bug fix) |
||
|
|
||
| const secureSignalsStorageJson = secureSignalsStorage && JSON.parse(secureSignalsStorage); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM nginx:alpine | ||
|
|
||
| # Install gettext for envsubst | ||
| RUN apk add --no-cache gettext | ||
|
|
||
| # Copy static files from client-side-deferred directory | ||
| COPY client-side-deferred/app.css /usr/share/nginx/html/ | ||
| COPY prebid.js /usr/share/nginx/html/ | ||
|
|
||
| # Copy config and HTML | ||
| COPY client-side-deferred/default.conf /etc/nginx/conf.d/default.conf | ||
| COPY client-side-deferred/index.html /usr/share/nginx/html/index.template.html | ||
| COPY client-side-deferred/entrypoint.sh /entrypoint.sh | ||
|
|
||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] | ||
| CMD ["nginx", "-g", "daemon off;"] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Deferred UID2/EUID Integration with Prebid.js (using mergeConfig) | ||
|
|
||
| This example demonstrates how to integrate UID2 or EUID with Prebid.js using **deferred configuration**. Unlike the standard integration where UID2/EUID is configured on page load, this pattern uses `mergeConfig()` and `refreshUserIds()` to add the identity module *after* the page has already loaded. | ||
|
|
||
| ## Use Cases | ||
|
|
||
| This pattern is useful for: | ||
|
|
||
| - **Async Login**: User logs in after the page has loaded | ||
| - **Delayed Consent**: Consent is given asynchronously (e.g., via a consent management platform) | ||
| - **Single Page Applications (SPAs)**: Dynamic login/logout without full page reloads | ||
| - **Lazy Loading**: Only load UID2/EUID when actually needed | ||
| - **User State Changes**: Handle logout and re-login scenarios | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### Standard Flow (for comparison) | ||
| ```javascript | ||
| // Page load: UID2 configured immediately | ||
| pbjs.setConfig({ | ||
| userSync: { | ||
| userIds: [{ name: 'uid2', params: {...} }] | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ### Deferred Flow (this example) | ||
| ```javascript | ||
| // Step 1: Page load - Prebid configured WITHOUT UID2 | ||
| pbjs.setConfig({ | ||
| userSync: { | ||
| syncDelay: 5000, | ||
| auctionDelay: 1000, | ||
| // Note: NO userIds configured here! | ||
| } | ||
| }); | ||
|
|
||
| // Step 2: Later (after login, consent, etc.) - Add UID2 via mergeConfig | ||
| pbjs.mergeConfig({ | ||
| userSync: { | ||
| userIds: [{ | ||
| name: 'uid2', | ||
| params: { | ||
| uid2ApiBase: 'https://operator-integ.uidapi.com', | ||
| email: '[email protected]', | ||
| subscriptionId: 'your-subscription-id', | ||
| serverPublicKey: 'your-server-public-key' | ||
| } | ||
| }] | ||
| } | ||
| }); | ||
|
|
||
| // Step 3: Trigger user ID refresh to generate the token | ||
| await pbjs.refreshUserIds(); | ||
| ``` | ||
|
|
||
| ## Key Prebid.js APIs | ||
|
|
||
| | API | Purpose | | ||
| |-----|---------| | ||
| | `pbjs.setConfig()` | Initial configuration (without UID2) | | ||
| | `pbjs.mergeConfig()` | Add/update configuration without replacing existing config | | ||
| | `pbjs.refreshUserIds()` | Trigger user ID module to fetch/generate new IDs | | ||
| | `pbjs.getUserIds()` | Get current user IDs (check if token was generated) | | ||
|
|
||
| ## Live Examples | ||
|
|
||
| - **UID2**: [https://unifiedid.com/examples/cstg-prebid-deferred-example/](https://unifiedid.com/examples/cstg-prebid-deferred-example/) | ||
| - **EUID**: [https://euid.eu/examples/cstg-prebid-deferred-example/](https://euid.eu/examples/cstg-prebid-deferred-example/) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont think these URLs would be where the examples will live |
||
|
|
||
| ## Running Locally | ||
|
|
||
| ### Using Docker Compose (recommended) | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| docker compose up prebid-client-side-deferred | ||
| ``` | ||
|
|
||
| Access at: http://localhost:3053 | ||
|
|
||
| ### Using the Reverse Proxy | ||
|
|
||
| ```bash | ||
| docker compose up | ||
| ``` | ||
|
|
||
| Access at: http://prebid-deferred.sample-dev.com (requires hosts file configuration) | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Description | Default | | ||
| |----------|-------------|---------| | ||
| | `UID_CLIENT_BASE_URL` | API base URL for client-side calls | `https://operator-integ.uidapi.com` | | ||
| | `UID_CSTG_SUBSCRIPTION_ID` | Your CSTG subscription ID | Test value provided | | ||
| | `UID_CSTG_SERVER_PUBLIC_KEY` | Your CSTG server public key | Test value provided | | ||
| | `UID_STORAGE_KEY` | localStorage key for token storage | `__uid2_advertising_token` | | ||
| | `IDENTITY_NAME` | Display name (UID2 or EUID) | `UID2` | | ||
| | `DOCS_BASE_URL` | Base URL for documentation links | `https://unifiedid.com/docs` | | ||
|
|
||
| ## Testing Flow | ||
|
|
||
| 1. **Page loads** - Observe that Prebid is loaded but UID2 shows "Not yet configured (deferred)" | ||
| 2. **Enter email** - Type an email address in the input field | ||
| 3. **Click "Configure UID2 with mergeConfig()"** - This triggers: | ||
| - `pbjs.mergeConfig()` to add UID2 configuration | ||
| - `pbjs.refreshUserIds()` to generate the token | ||
| 4. **Observe results** - Token appears in the status tables | ||
| 5. **Test opt-out** - Use `[email protected]` to see opt-out behavior | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [UID2 Client-Side Integration Guide for Prebid.js](https://unifiedid.com/docs/guides/integration-prebid-client-side) | ||
| - [EUID Client-Side Integration Guide for Prebid.js](https://euid.eu/docs/guides/integration-prebid-client-side) | ||
| - [Prebid.js User ID Module](https://docs.prebid.org/dev-docs/modules/userId.html) | ||
| - [Prebid.js setConfig/mergeConfig](https://docs.prebid.org/dev-docs/publisher-api-reference/setConfig.html) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setConfig and mergeConfig have different prebid docs references, merge config would be here https://docs.prebid.org/dev-docs/publisher-api-reference/mergeConfig.html |
||
|
|
||
| ## Related Examples | ||
|
|
||
| - [client-side](../client-side/) - Standard Prebid + UID2 (configured on page load) | ||
| - [client-server](../client-server/) - Server-side token generation with Prebid | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.