Skip to content

Commit 23fc456

Browse files
update logic to check for local storage instead
1 parent 291fb58 commit 23fc456

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@
1515
SUBSCRIPTION_ID: '4WvryDGbR5',
1616
};
1717

18-
let attemptedTokenGeneration = false;
19-
2018
function updateGuiElements() {
2119
console.log('Updating displayed values.');
2220
const uid2 = pbjs.getUserIds().uid2;
21+
22+
// Check localStorage for opt-out status
23+
const storedToken = localStorage.getItem('__uid2_advertising_token');
24+
let isOptedOut = false;
25+
if (storedToken) {
26+
try {
27+
const tokenData = JSON.parse(storedToken);
28+
isOptedOut = tokenData.latestToken === 'optout';
29+
} catch (e) {
30+
console.log('Could not parse stored token');
31+
}
32+
}
33+
2334
$('#targeted_advertising_ready').text(uid2 ? 'yes' : 'no');
2435

25-
// If token generation was attempted and uid2 is null, it means opt-out
26-
if (attemptedTokenGeneration && !uid2) {
36+
// Handle opt-out case
37+
if (isOptedOut) {
2738
$('#advertising_token').text('This email has opted out.');
2839
$('#login_form').hide();
2940
$('#clear_storage_form').show();
@@ -37,13 +48,10 @@
3748
$('#clear_storage_form').show();
3849
}
3950
}
40-
41-
attemptedTokenGeneration = false;
4251
}
4352

4453
async function handleLogin() {
4554
const email = $('#email').val();
46-
attemptedTokenGeneration = true;
4755
setUid2Config(email);
4856
await pbjs.refreshUserIds();
4957
updateGuiElements();

0 commit comments

Comments
 (0)