Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const uidJsSdkName = process.env.UID_JS_SDK_NAME || '__uid2';

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

// UI/Display configuration
const identityName = process.env.IDENTITY_NAME;
Expand Down Expand Up @@ -48,7 +49,7 @@ app.get('/', (req, res) => {
uidJsSdkUrl,
uidJsSdkName,
secureSignalsSdkUrl,
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
secureSignalsStorageKey,
identityName,
docsBaseUrl
});
Expand Down Expand Up @@ -147,7 +148,7 @@ app.post('/login', async (req, res) => {
uidJsSdkUrl,
uidJsSdkName,
secureSignalsSdkUrl,
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
secureSignalsStorageKey,
identityName,
docsBaseUrl
});
Expand All @@ -173,7 +174,7 @@ app.post('/login', async (req, res) => {
uidJsSdkUrl,
uidJsSdkName,
secureSignalsSdkUrl,
secureSignalsStorageKey: process.env.UID_SECURE_SIGNALS_STORAGE_KEY,
secureSignalsStorageKey,
identityName,
docsBaseUrl
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
<link rel="stylesheet" type="text/css" href="/stylesheets/app.css" />
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
<link rel="shortcut icon" href="/images/favicon.png" />

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="<%- uidJsSdkUrl %>"></script>
<script src="<%- secureSignalsSdkUrl %>"></script>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>

<script>
$(document).ready(() => {
const sdkName = '<%- uidJsSdkName %>';
Expand All @@ -25,8 +26,11 @@
$("#login_required").html(sdk.isLoginRequired() ? "yes" : "no");
$("#identity_state").html(String(JSON.stringify(payload, null, 2)));

// Update Secure Signals values displayed in the GUI
updateSecureSignals();
// Secure Signals SDK usually writes to localStorage shortly after it gets the token.
if (sdk.getAdvertisingToken()) {
setTimeout(updateSecureSignals, 1000);
}

<% if (isOptout) { %>
$("#login_form").hide();
Expand All @@ -35,7 +39,7 @@
$("#optout_banner").show();
$('#googleAdContainer').hide();
<% } else { %>
// before token generation, show login form
// before token generation, show login form.
if (sdk.isLoginRequired()) {
$("#login_form").show();
$("#logout_form").hide();
Expand All @@ -55,12 +59,17 @@

function updateSecureSignals() {
try {
// Read from localStorage
const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>';

const secureSignalsStorage = localStorage[secureSignalsStorageKey];

const token = sdk.getAdvertisingToken();
// Token valid but Secure Signals not yet written; reload so the SDK gets another chance.
if (token && !secureSignalsStorage) {
location.reload();
return;
}

const secureSignalsStorageJson = secureSignalsStorage && JSON.parse(secureSignalsStorage);

if (secureSignalsStorageJson && secureSignalsStorageJson[1]) {
$("#secure_signals_loaded").html("yes");
$("#secure_signals_value").html(JSON.stringify(secureSignalsStorageJson, null, 2));
Expand All @@ -83,16 +92,17 @@
$("#logout").click(() => {
window.googletag.secureSignalProviders.clearAllCache();
sdk.disconnect();
localStorage.removeItem('<%- secureSignalsStorageKey %>');
window.location.href = '/';
});

$("#try_another").click(() => {
window.googletag.secureSignalProviders.clearAllCache();
sdk.disconnect();
localStorage.removeItem('<%- secureSignalsStorageKey %>');
window.location.href = '/';
});

sdk.callbacks.push((eventType, payload) => {
sdk.callbacks.push((eventType, payload) => {
if (eventType === "SdkLoaded") {
sdk.init({
baseUrl: "<%- uidBaseUrl %>",
Expand Down Expand Up @@ -160,6 +170,7 @@

<!-- UID2 Integration Status Section -->
<h2><%- identityName %> Integration Status</h2>
<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>

<table id="uid_state">
<tr>
Expand Down Expand Up @@ -237,7 +248,7 @@ <h2 class="section-teal">Google Secure Signals Status</h2>
</div>
</div>
</td>
<td class="value"><pre id="secure_signals_loaded"></pre></td>
<td class="value"><pre id="secure_signals_loaded">no</pre></td>
</tr>
<tr>
<td class="label">
Expand All @@ -251,7 +262,7 @@ <h2 class="section-teal">Google Secure Signals Status</h2>
</div>
</div>
</td>
<td class="value"><pre id="secure_signals_value"></pre></td>
<td class="value"><pre id="secure_signals_value">undefined</pre></td>
</tr>
</table>

Expand Down
20 changes: 10 additions & 10 deletions web-integrations/google-secure-signals/server-side/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@
<link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
<link rel="shortcut icon" href="/images/favicon.png" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script async src="<%- secureSignalsSdkUrl %>"></script>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>

<script type="text/javascript">
// For server-side integrations, the token callback must be defined before the SDKs that use it (e.g. Secure Signals) load.
const getUid2AdvertisingToken = async () => {
const response = await fetch('/getFreshToken');
if (!response.ok) return undefined;
const result = await response.json();
console.log(result);
return result.advertising_token;
return result && result.advertising_token;
};

window.getUid2AdvertisingToken = getUid2AdvertisingToken;

// If uid2SecureSignalProvider is initialized before getUid2AdvertisingToken is assigned, call registerSecureSignalProvider
</script>
<script src="<%- secureSignalsSdkUrl %>"></script>
<script type="text/javascript">
if (window.__uid2SecureSignalProvider) {
window.__uid2SecureSignalProvider.registerSecureSignalProvider();
}
</script>
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
$(document).ready(() => {
const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>';
Expand All @@ -48,8 +47,8 @@
}
}

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

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

<!-- UID2 Integration Status Section -->
<h2><%- identityName %> Integration Status</h2>
<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>

<table id="uid_state">
<tr>
Expand Down