Skip to content

Commit d9d42d4

Browse files
update prebid configuration and explanation in readme
1 parent 6ddb406 commit d9d42d4

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

web-integrations/prebid-integrations/client-side-deferred/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,36 @@ Access at: http://prebid-deferred.sample-dev.com (requires hosts file configurat
109109
4. **Observe results** - Token appears in the status tables
110110
5. **Test opt-out** - Use `[email protected]` to see opt-out behavior
111111

112+
## Clearing UID2 Identity (Logout)
113+
114+
UID2 state lives in two places:
115+
- **Browser storage** (localStorage) - where the token is persisted
116+
- **Prebid's in-memory cache** - where Prebid holds the token during the session
117+
118+
To fully clear UID2 and prevent future bid requests from using the token:
119+
120+
```javascript
121+
// Step 1: Clear UID2 from browser storage
122+
localStorage.removeItem('__uid2_advertising_token');
123+
124+
// Step 2: Page reload clears Prebid's in-memory cache
125+
location.reload();
126+
```
127+
128+
### Why Page Reload?
129+
130+
Prebid's UID2 module doesn't expose a method to clear just UID2 without affecting other user ID modules. The `mergeConfig()` API is additive—once UID2 is added to `userSync.userIds`, there's no built-in way to remove only that configuration. Page reload ensures Prebid reinitializes fresh with an empty localStorage.
131+
132+
### Alternative: Using the UID2 JavaScript SDK
133+
134+
If you're using the [UID2 JavaScript SDK](https://unifiedid.com/docs/sdks/sdk-ref-javascript) directly (not just Prebid's module), you can use:
135+
136+
```javascript
137+
__uid2.disconnect();
138+
```
139+
140+
This automatically clears both storage and in-memory state without page reload. However, this method is **not available** when using Prebid's UID2 module alone—Prebid uses an internal implementation that doesn't expose the full SDK globally.
141+
112142
## Documentation
113143

114144
- [UID2 Client-Side Integration Guide for Prebid.js](https://unifiedid.com/docs/guides/integration-prebid-client-side)

web-integrations/prebid-integrations/client-side-deferred/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export SERVER_PUBLIC_KEY=${UID_CSTG_SERVER_PUBLIC_KEY:-"UID2-X-I-MFkwEwYHKoZIzj0
66
export SUBSCRIPTION_ID=${UID_CSTG_SUBSCRIPTION_ID:-"DMr7uHxqLU"}
77
export UID_STORAGE_KEY=${UID_STORAGE_KEY:-"__uid2_advertising_token"}
88
export IDENTITY_NAME=${IDENTITY_NAME:-"UID2"}
9+
export IDENTITY_NAME_LOWER=$(echo "$IDENTITY_NAME" | tr '[:upper:]' '[:lower:]')
910
export DOCS_BASE_URL=${DOCS_BASE_URL:-"https://unifiedid.com/docs"}
1011

1112
# Copy static files

web-integrations/prebid-integrations/client-side-deferred/index.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@
110110
// Use mergeConfig() to add UID configuration after page load
111111
pbjs.mergeConfig(uidConfig);
112112

113-
// Call refreshUserIds() to trigger token generation
114-
await pbjs.refreshUserIds();
113+
console.log(`[${identityName}] Config merged. Calling refreshUserIds for ${userIdName} only...`);
114+
115+
// Call refreshUserIds() with submoduleNames to only refresh UID2/EUID specifically
116+
await pbjs.refreshUserIds({ submoduleNames: [userIdName] });
117+
118+
console.log(`[${identityName}] refreshUserIds complete. Current getUserIds():`, pbjs.getUserIds());
115119

116120
uidConfigured = true;
117121

@@ -121,8 +125,12 @@
121125
}
122126

123127
function handleClearStorage() {
128+
// Clear UID2 identity from browser storage
124129
localStorage.removeItem(storageKey);
125-
uidConfigured = false;
130+
131+
// Page reload is required to clear Prebid's in-memory cache.
132+
// Unlike the UID2 SDK which has disconnect(), Prebid's UID2 module
133+
// doesn't expose a method to clear just UID2 without affecting other ID modules.
126134
location.reload();
127135
}
128136

@@ -247,11 +255,17 @@ <h3>📄 Initial Prebid Config (on page load)</h3>
247255

248256
<!-- Instructions -->
249257
<div id="merge_instructions" class="merge-instructions">
250-
<p><strong>What happens when you click:</strong></p>
258+
<p><strong>What happens when you click "Configure":</strong></p>
251259
<ol>
252260
<li><code>pbjs.mergeConfig(uidConfig)</code> - Merges ${IDENTITY_NAME} user ID module configuration into the existing Prebid config without overwriting other settings. This allows adding ${IDENTITY_NAME} after the page has already loaded.</li>
253-
<li><code>pbjs.refreshUserIds()</code> - Triggers Prebid to re-fetch all configured user IDs, including the newly added ${IDENTITY_NAME} module, which initiates token generation using the provided email and CSTG credentials.</li>
261+
<li><code>pbjs.refreshUserIds({ submoduleNames: ['${IDENTITY_NAME_LOWER}'] })</code> - Triggers Prebid to re-fetch the ${IDENTITY_NAME} user ID specifically, which initiates token generation using the provided email and CSTG credentials.</li>
262+
</ol>
263+
<p><strong>What happens when you click "Clear":</strong></p>
264+
<ol>
265+
<li><code>localStorage.removeItem(storageKey)</code> - Clears the ${IDENTITY_NAME} identity from browser storage.</li>
266+
<li><code>location.reload()</code> - Reloads the page to clear Prebid's in-memory cache, preventing future bid requests from using the old token.</li>
254267
</ol>
268+
<p class="config-note"><strong>Why reload?</strong> ${IDENTITY_NAME} state lives in browser storage and Prebid's memory. Prebid only reads the token—it doesn't provide a method to clear just ${IDENTITY_NAME} without affecting other ID modules. Page reload ensures a clean state.</p>
255269
</div>
256270

257271
<!-- UID Token Status Section -->

0 commit comments

Comments
 (0)