Skip to content

Commit afd1356

Browse files
Merge pull request #174 from IABTechLab/eee-UID2-6639-separate-ui-detection
Fix Google Secure Signals UI detection for client-server and server-side
2 parents b40a939 + 96e06ff commit afd1356

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

web-integrations/google-secure-signals/client-server/server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const uidJsSdkName = process.env.UID_JS_SDK_NAME || '__uid2';
1919

2020
// Secure Signals configuration
2121
const secureSignalsSdkUrl = process.env.UID_SECURE_SIGNALS_SDK_URL || 'https://cdn.integ.uidapi.com/uid2SecureSignal.js';
22+
const secureSignalsStorageKey = process.env.UID_SECURE_SIGNALS_STORAGE_KEY || '_GESPSK-uidapi.com';
2223

2324
// UI/Display configuration
2425
const identityName = process.env.IDENTITY_NAME;
@@ -48,7 +49,7 @@ app.get('/', (req, res) => {
4849
uidJsSdkUrl,
4950
uidJsSdkName,
5051
secureSignalsSdkUrl,
51-
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
52+
secureSignalsStorageKey,
5253
identityName,
5354
docsBaseUrl
5455
});
@@ -147,7 +148,7 @@ app.post('/login', async (req, res) => {
147148
uidJsSdkUrl,
148149
uidJsSdkName,
149150
secureSignalsSdkUrl,
150-
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
151+
secureSignalsStorageKey,
151152
identityName,
152153
docsBaseUrl
153154
});
@@ -173,7 +174,7 @@ app.post('/login', async (req, res) => {
173174
uidJsSdkUrl,
174175
uidJsSdkName,
175176
secureSignalsSdkUrl,
176-
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
177+
secureSignalsStorageKey,
177178
identityName,
178179
docsBaseUrl
179180
});

web-integrations/google-secure-signals/client-server/views/index.html

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
<link rel="stylesheet" type="text/css" href="/stylesheets/app.css" />
77
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
88
<link rel="shortcut icon" href="/images/favicon.png" />
9+
910
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
1011
<script src="<%- uidJsSdkUrl %>"></script>
1112
<script src="<%- secureSignalsSdkUrl %>"></script>
1213
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
13-
14+
1415
<script>
1516
$(document).ready(() => {
1617
const sdkName = '<%- uidJsSdkName %>';
@@ -25,8 +26,11 @@
2526
$("#login_required").html(sdk.isLoginRequired() ? "yes" : "no");
2627
$("#identity_state").html(String(JSON.stringify(payload, null, 2)));
2728

28-
// Update Secure Signals values displayed in the GUI
2929
updateSecureSignals();
30+
// Secure Signals SDK usually writes to localStorage shortly after it gets the token.
31+
if (sdk.getAdvertisingToken()) {
32+
setTimeout(updateSecureSignals, 1000);
33+
}
3034

3135
<% if (isOptout) { %>
3236
$("#login_form").hide();
@@ -35,7 +39,7 @@
3539
$("#optout_banner").show();
3640
$('#googleAdContainer').hide();
3741
<% } else { %>
38-
// before token generation, show login form
42+
// before token generation, show login form.
3943
if (sdk.isLoginRequired()) {
4044
$("#login_form").show();
4145
$("#logout_form").hide();
@@ -55,12 +59,17 @@
5559

5660
function updateSecureSignals() {
5761
try {
58-
// Read from localStorage
5962
const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>';
63+
6064
const secureSignalsStorage = localStorage[secureSignalsStorageKey];
61-
65+
const token = sdk.getAdvertisingToken();
66+
// Token valid but Secure Signals not yet written; reload so the SDK gets another chance.
67+
if (token && !secureSignalsStorage) {
68+
location.reload();
69+
return;
70+
}
71+
6272
const secureSignalsStorageJson = secureSignalsStorage && JSON.parse(secureSignalsStorage);
63-
6473
if (secureSignalsStorageJson && secureSignalsStorageJson[1]) {
6574
$("#secure_signals_loaded").html("yes");
6675
$("#secure_signals_value").html(JSON.stringify(secureSignalsStorageJson, null, 2));
@@ -83,16 +92,17 @@
8392
$("#logout").click(() => {
8493
window.googletag.secureSignalProviders.clearAllCache();
8594
sdk.disconnect();
95+
localStorage.removeItem('<%- secureSignalsStorageKey %>');
8696
window.location.href = '/';
8797
});
88-
8998
$("#try_another").click(() => {
9099
window.googletag.secureSignalProviders.clearAllCache();
91100
sdk.disconnect();
101+
localStorage.removeItem('<%- secureSignalsStorageKey %>');
92102
window.location.href = '/';
93103
});
94104

95-
sdk.callbacks.push((eventType, payload) => {
105+
sdk.callbacks.push((eventType, payload) => {
96106
if (eventType === "SdkLoaded") {
97107
sdk.init({
98108
baseUrl: "<%- uidBaseUrl %>",
@@ -160,6 +170,7 @@
160170

161171
<!-- UID2 Integration Status Section -->
162172
<h2><%- identityName %> Integration Status</h2>
173+
<p class="section-summary"><strong>Note:</strong> This is a test-only integration environment—it does not collect data or generate production-level tokens.</p>
163174

164175
<table id="uid_state">
165176
<tr>
@@ -237,7 +248,7 @@ <h2 class="section-teal">Google Secure Signals Status</h2>
237248
</div>
238249
</div>
239250
</td>
240-
<td class="value"><pre id="secure_signals_loaded"></pre></td>
251+
<td class="value"><pre id="secure_signals_loaded">no</pre></td>
241252
</tr>
242253
<tr>
243254
<td class="label">
@@ -251,7 +262,7 @@ <h2 class="section-teal">Google Secure Signals Status</h2>
251262
</div>
252263
</div>
253264
</td>
254-
<td class="value"><pre id="secure_signals_value"></pre></td>
265+
<td class="value"><pre id="secure_signals_value">undefined</pre></td>
255266
</tr>
256267
</table>
257268

web-integrations/google-secure-signals/server-side/views/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@
77
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
88
<link rel="shortcut icon" href="/images/favicon.png" />
99
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
10-
<script async src="<%- secureSignalsSdkUrl %>"></script>
11-
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
12-
1310
<script type="text/javascript">
11+
// For server-side integrations, the token callback must be defined before the SDKs that use it (e.g. Secure Signals) load.
1412
const getUid2AdvertisingToken = async () => {
1513
const response = await fetch('/getFreshToken');
14+
if (!response.ok) return undefined;
1615
const result = await response.json();
17-
console.log(result);
18-
return result.advertising_token;
16+
return result && result.advertising_token;
1917
};
20-
2118
window.getUid2AdvertisingToken = getUid2AdvertisingToken;
22-
23-
// If uid2SecureSignalProvider is initialized before getUid2AdvertisingToken is assigned, call registerSecureSignalProvider
19+
</script>
20+
<script src="<%- secureSignalsSdkUrl %>"></script>
21+
<script type="text/javascript">
2422
if (window.__uid2SecureSignalProvider) {
2523
window.__uid2SecureSignalProvider.registerSecureSignalProvider();
2624
}
2725
</script>
26+
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
2827
<script>
2928
$(document).ready(() => {
3029
const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>';
@@ -48,8 +47,8 @@
4847
}
4948
}
5049

51-
// Update Secure Signals display after SDK has time to load and fetch token
52-
setTimeout(updateSecureSignals, 1000);
50+
// Update Secure Signals display after SDK has time to load and fetch token, allowing for additional tries
51+
[1000, 2000, 3000].forEach((ms) => setTimeout(updateSecureSignals, ms));
5352

5453
$('#logout').click(() => {
5554
if (window.googletag && window.googletag.secureSignalProviders) {
@@ -107,6 +106,7 @@ <h1>Server-Side <%- identityName %> Integration Example with Google Secure Signa
107106

108107
<!-- UID2 Integration Status Section -->
109108
<h2><%- identityName %> Integration Status</h2>
109+
<p class="section-summary"><strong>Note:</strong> This is a test-only integration environment—it does not collect data or generate production-level tokens.</p>
110110

111111
<table id="uid_state">
112112
<tr>

0 commit comments

Comments
 (0)