Skip to content

Commit 5d1c628

Browse files
handle opt out emails
1 parent e465d49 commit 5d1c628

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

web-integrations/prebid-integrations/client-server/README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,13 @@ For the client-side Prebid.js integration example, see [../client-side](../clien
66

77
> **NOTE:** While the server side of this example is implemented in JavaScript using Node.js, it is not a requirement. You can use any technology of your choice and refer to this example for illustration of the functionality that needs to be implemented.
88
9-
## Prerequisites
10-
11-
- Node.js (version 20.x or later recommended)
12-
- UID2 API credentials (API Key and Client Secret)
13-
- A local UID2 Operator instance **OR** access to the UID2 integration environment
149

1510
## Run Locally for Testing
1611

1712
### 1. Set Up Environment Variables
1813

1914
Create a `.env` file in the **root of the uid2-examples repository** (not in this folder) with the following variables:
2015

21-
```bash
22-
# UID2 Operator configuration
23-
UID2_BASE_URL=http://localhost:8080
24-
UID2_API_KEY=your-api-key-here
25-
UID2_CLIENT_SECRET=your-client-secret-here
26-
27-
# Port for this example (optional, defaults to 3000)
28-
PORT=3005
29-
```
30-
3116
**For local operator testing:**
3217
- Use `UID2_BASE_URL=http://localhost:8080`
3318
- Use API credentials from your local operator's configuration

web-integrations/prebid-integrations/client-server/public/index.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,26 @@
113113
body: JSON.stringify({ email: email })
114114
});
115115

116+
const data = await response.json();
117+
118+
// Check for opt-out (server returns 400 with status: 'optout')
116119
if (!response.ok) {
117-
const errorData = await response.json();
118-
console.error('Token generation failed:', errorData);
119-
alert('Failed to generate UID2 token: ' + (errorData.error || 'Unknown error'));
120+
if (data.status === 'optout') {
121+
console.log('User has opted out');
122+
localStorage.setItem(UID2_STORAGE_KEY, JSON.stringify({ status: 'optout' }));
123+
currentIdentity = null;
124+
updateGuiElements();
125+
return;
126+
}
127+
// Other errors
128+
console.error('Token generation failed:', data);
129+
alert('Failed to generate UID2 token: ' + (data.error || 'Unknown error'));
120130
return;
121131
}
122132

123-
const data = await response.json();
124133
console.log('UID2 token received:', data);
125134

126-
// Check for opt-out
127-
if (data.identity && data.identity.advertising_token === 'optout') {
128-
console.log('User has opted out');
129-
localStorage.setItem(UID2_STORAGE_KEY, JSON.stringify({ status: 'optout' }));
130-
currentIdentity = null;
131-
} else if (data.identity) {
135+
if (data.identity) {
132136
// Store the identity
133137
currentIdentity = data.identity;
134138
localStorage.setItem(UID2_STORAGE_KEY, JSON.stringify(currentIdentity));

0 commit comments

Comments
 (0)