|
7 | 7 | <link rel="stylesheet" type="text/css" href="/stylesheets/style.css" /> |
8 | 8 | <link rel="shortcut icon" href="/images/favicon.png" /> |
9 | 9 | <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
| 10 | + <script src="<%- uidJsSdkUrl %>"></script> |
| 11 | + <script src="<%- secureSignalsSdkUrl %>"></script> |
| 12 | + <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script> |
10 | 13 |
|
11 | 14 | <script> |
12 | 15 | $(document).ready(() => { |
|
23 | 26 | $("#login_required").html(sdk.isLoginRequired() ? "yes" : "no"); |
24 | 27 | $("#update_counter").html(callbackCounter); |
25 | 28 | $("#identity_state").html(String(JSON.stringify(payload, null, 2))); |
| 29 | + |
| 30 | + // Update Secure Signals values displayed in the GUI |
| 31 | + updateSecureSignals(); |
26 | 32 |
|
| 33 | + <% if (isOptout) { %> |
| 34 | + $("#login_form").hide(); |
| 35 | + $("#logout_form").hide(); |
| 36 | + $("#optout_form").show(); |
| 37 | + $("#optout_banner").show(); |
| 38 | + $('#googleAdContainer').hide(); |
| 39 | + <% } else { %> |
| 40 | + // before token generation, show login form |
27 | 41 | if (sdk.isLoginRequired()) { |
28 | 42 | $("#login_form").show(); |
29 | 43 | $("#logout_form").hide(); |
| 44 | + $("#optout_form").hide(); |
| 45 | + $("#optout_banner").hide(); |
30 | 46 | $('#googleAdContainer').hide(); |
31 | 47 | } else { |
| 48 | + // Success case - token generated, show logout form |
32 | 49 | $("#login_form").hide(); |
33 | 50 | $("#logout_form").show(); |
| 51 | + $("#optout_form").hide(); |
| 52 | + $("#optout_banner").hide(); |
34 | 53 | $('#googleAdContainer').show(); |
35 | 54 | } |
| 55 | + <% } %> |
| 56 | + } |
| 57 | + |
| 58 | + function updateSecureSignals() { |
| 59 | + try { |
| 60 | + // Read from localStorage |
| 61 | + const secureSignalsStorageKey = '<%- secureSignalsStorageKey %>'; |
| 62 | + const secureSignalsStorage = localStorage[secureSignalsStorageKey]; |
| 63 | + const token = sdk.getAdvertisingToken(); |
| 64 | + |
| 65 | + // Safety net: If token exists but Secure Signals haven't loaded yet, reload the page |
| 66 | + if (token && !secureSignalsStorage && !<%= isOptout %>) { |
| 67 | + console.log("Token exists but Secure Signals not loaded yet, reloading page..."); |
| 68 | + location.reload(); |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + const secureSignalsStorageJson = secureSignalsStorage && JSON.parse(secureSignalsStorage); |
| 73 | + |
| 74 | + if (secureSignalsStorageJson && secureSignalsStorageJson[1]) { |
| 75 | + $("#secure_signals_loaded").html("yes"); |
| 76 | + $("#secure_signals_value").html(JSON.stringify(secureSignalsStorageJson, null, 2)); |
| 77 | + } else { |
| 78 | + $("#secure_signals_loaded").html("no"); |
| 79 | + $("#secure_signals_value").html("undefined"); |
| 80 | + } |
| 81 | + } catch (e) { |
| 82 | + console.log("Secure signals not yet available", e); |
| 83 | + $("#secure_signals_loaded").html("no"); |
| 84 | + $("#secure_signals_value").html("undefined"); |
| 85 | + } |
36 | 86 | } |
37 | 87 |
|
38 | 88 | function onIdentityUpdated(eventType, payload) { |
|
42 | 92 | ) { |
43 | 93 | ++callbackCounter; |
44 | 94 | } |
45 | | - updateGuiElements(payload); |
| 95 | + // Allow secure signals time to load |
| 96 | + setTimeout(() => updateGuiElements(payload), 1000); |
46 | 97 | } |
47 | 98 |
|
48 | 99 | $("#logout").click(() => { |
49 | | - sdk.disconnect(); |
50 | 100 | window.googletag.secureSignalProviders.clearAllCache(); |
51 | | - updateGuiElements(undefined); |
| 101 | + sdk.disconnect(); |
| 102 | + window.location.href = '/'; |
52 | 103 | }); |
53 | | - $("#login").click(() => { |
| 104 | + |
| 105 | + $("#try_another").click(() => { |
54 | 106 | window.googletag.secureSignalProviders.clearAllCache(); |
| 107 | + sdk.disconnect(); |
| 108 | + window.location.href = '/'; |
55 | 109 | }); |
| 110 | + |
56 | 111 | sdk.callbacks.push((eventType, payload) => { |
57 | 112 | if (eventType === "SdkLoaded") { |
58 | 113 | sdk.init({ |
59 | 114 | baseUrl: "<%- uidBaseUrl %>", |
60 | | - enableSecureSignals: true, |
61 | 115 | }); |
62 | 116 | } |
63 | 117 | }); |
| 118 | + |
| 119 | + sdk.callbacks.push((eventType, payload) => { |
| 120 | + if (eventType === 'InitCompleted') { |
| 121 | + <% if (identity !== null && typeof identity !== 'undefined') { %> |
| 122 | + // Server provided an identity, set it |
| 123 | + if (sdk.isLoginRequired()) { |
| 124 | + sdk.setIdentity(<%- JSON.stringify(identity) %>); |
| 125 | + } else { |
| 126 | + // Identity already exists, just update GUI |
| 127 | + updateGuiElements(payload); |
| 128 | + } |
| 129 | + <% } else { %> |
| 130 | + // No identity from server (including opt-out case) |
| 131 | + // SDK will naturally remain in "login required" state |
| 132 | + updateGuiElements(payload); |
| 133 | + <% if (isOptout) { %> |
| 134 | + $("#optout_banner").show(); |
| 135 | + <% } %> |
| 136 | + <% } %> |
| 137 | + } |
| 138 | + }); |
| 139 | + |
64 | 140 | sdk.callbacks.push(onIdentityUpdated); |
65 | 141 | }); |
66 | 142 | </script> |
67 | 143 | </head> |
68 | 144 | <body> |
| 145 | + <%- include('intro.html'); -%> |
| 146 | + <p> |
| 147 | + <strong>Note:</strong> This is a <em>test-only</em> integration environment—not for production |
| 148 | + use. It does not perform real user authentication or generate production-level tokens. Do not |
| 149 | + use real user data on this page. |
| 150 | + </p> |
69 | 151 | <div id="googleAdContainer" style="display: none"> |
70 | 152 | <div id="mainContainer"> |
71 | 153 | <div id="content"> |
|
77 | 159 | </div> |
78 | 160 | <button id="playButton">Play</button> |
79 | 161 | <script type="text/javascript" src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script> |
80 | | - <script async src="<%- secureSignalsSdkUrl %>"></script> |
81 | | - <script async src="<%- uidJsSdkUrl %>"></script> |
82 | | - <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script> |
83 | 162 | <script type="text/javascript" src="ads.js"></script> |
84 | 163 | </div> |
85 | | - <%- include('intro.html'); -%> |
86 | | - <p> |
87 | | - <strong>Note:</strong> This is a <em>test-only</em> integration environment—not for production |
88 | | - use. It does not perform real user authentication or generate production-level tokens. Do not |
89 | | - use real user data on this page. |
90 | | - </p> |
91 | 164 | <table id="uid2_state"> |
92 | 165 | <tr> |
93 | 166 | <td class="label">Ready for Targeted Advertising:</td> |
|
109 | 182 | <td class="label"><%- identityName %> Identity Callback State:</td> |
110 | 183 | <td class="value"><pre id="identity_state"></pre></td> |
111 | 184 | </tr> |
| 185 | + <tr> |
| 186 | + <td class="label">Secure Signals Loaded?</td> |
| 187 | + <td class="value"><pre id="secure_signals_loaded"></pre></td> |
| 188 | + </tr> |
| 189 | + <tr> |
| 190 | + <td class="label">Secure Signals Value:</td> |
| 191 | + <td class="value"><pre id="secure_signals_value"></pre></td> |
| 192 | + </tr> |
112 | 193 | </table> |
| 194 | + <div id="optout_banner" style="display: none; border: 3px solid #ffc107; padding: 15px; margin: 20px 0;"> |
| 195 | + <p style="margin: 0;">The email address you entered has opted out of <%- identityName %>.</p> |
| 196 | + </div> |
113 | 197 | <div id="login_form" style="display: none" class="form"> |
114 | 198 | <form action="/login" method="POST"> |
115 | 199 | <div class="email_prompt"> |
|
121 | 205 | style="border-style: none" |
122 | 206 | /> |
123 | 207 | </div> |
124 | | - <div><input type="submit" value="Generate <%- identityName %>" class="button" id="login" /></div> |
| 208 | + <div><input type="submit" value="Generate <%- identityName %>" class="button" /></div> |
125 | 209 | </form> |
126 | 210 | </div> |
127 | 211 | <div id="logout_form" style="display: none" class="form"> |
128 | | - <form> |
129 | | - <button type="button" class="button" id="logout">Clear <%- identityName %></button> |
130 | | - </form> |
| 212 | + <button type="button" class="button" id="logout">Clear <%- identityName %></button> |
| 213 | + </div> |
| 214 | + <div id="optout_form" style="display: none" class="form"> |
| 215 | + <button type="button" class="button" id="try_another">Try Another Email</button> |
131 | 216 | </div> |
132 | 217 | </body> |
133 | 218 | </html> |
0 commit comments