Skip to content
29 changes: 24 additions & 5 deletions static/examples/cstg-prebid-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@
function updateGuiElements() {
console.log('Updating displayed values.');
const uid2 = pbjs.getUserIds().uid2;

let isOptedOut = false;
const storedToken = localStorage.getItem('__uid2_advertising_token');
if (storedToken) {
try {
const tokenData = JSON.parse(storedToken);
isOptedOut = tokenData.latestToken === 'optout';
} catch (e) {
console.log('Could not parse stored token');
}
}

$('#targeted_advertising_ready').text(uid2 ? 'yes' : 'no');
$('#advertising_token').text(uid2 ? String(uid2.id) : '');
if (!uid2) {
$('#login_form').show();
$('#clear_storage_form').hide();
} else {

if (isOptedOut) {
$('#advertising_token').text('This email has opted out.');
$('#login_form').hide();
$('#clear_storage_form').show();
} else {
$('#advertising_token').text(uid2 ? String(uid2.id) : '');
if (!uid2) {
$('#login_form').show();
$('#clear_storage_form').hide();
} else {
$('#login_form').hide();
$('#clear_storage_form').show();
}
}
}

Expand Down