Skip to content

Commit 3958faf

Browse files
Merge pull request #944 from IABTechLab/eee-UID2-5757-add-optout-to-sample-site-prebid
Handle cases for opted out emails
2 parents 3753ae9 + e5c5f74 commit 3958faf

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

static/examples/cstg-prebid-example/index.html

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,33 @@
1818
function updateGuiElements() {
1919
console.log('Updating displayed values.');
2020
const uid2 = pbjs.getUserIds().uid2;
21+
22+
let isOptedOut = false;
23+
const storedToken = localStorage.getItem('__uid2_advertising_token');
24+
if (storedToken) {
25+
try {
26+
const tokenData = JSON.parse(storedToken);
27+
isOptedOut = tokenData.latestToken === 'optout';
28+
} catch (e) {
29+
console.log('Could not parse stored token');
30+
}
31+
}
32+
2133
$('#targeted_advertising_ready').text(uid2 ? 'yes' : 'no');
22-
$('#advertising_token').text(uid2 ? String(uid2.id) : '');
23-
if (!uid2) {
24-
$('#login_form').show();
25-
$('#clear_storage_form').hide();
26-
} else {
34+
35+
if (isOptedOut) {
36+
$('#advertising_token').text('This email has opted out.');
2737
$('#login_form').hide();
2838
$('#clear_storage_form').show();
39+
} else {
40+
$('#advertising_token').text(uid2 ? String(uid2.id) : '');
41+
if (!uid2) {
42+
$('#login_form').show();
43+
$('#clear_storage_form').hide();
44+
} else {
45+
$('#login_form').hide();
46+
$('#clear_storage_form').show();
47+
}
2948
}
3049
}
3150

0 commit comments

Comments
 (0)