|
216 | 216 | return null; |
217 | 217 | } |
218 | 218 |
|
| 219 | + // src/consent/consent.ts |
| 220 | + var SURFACE_CONSENT_MESSAGE_TYPE = "surface:consent"; |
| 221 | + var consent = null; |
| 222 | + var onChange = null; |
| 223 | + var getSurfaceConsent = () => consent; |
| 224 | + var onSurfaceConsentChange = (callback) => { |
| 225 | + onChange = callback; |
| 226 | + }; |
| 227 | + var setSurfaceConsent = (granted) => { |
| 228 | + consent = { |
| 229 | + adTracking: granted?.adTracking === true, |
| 230 | + surfaceAnalytics: granted?.surfaceAnalytics === true |
| 231 | + }; |
| 232 | + onChange?.(); |
| 233 | + }; |
| 234 | + |
219 | 235 | // src/utils/debug.ts |
220 | 236 | var cached = null; |
221 | 237 | function isDebugMode() { |
|
496 | 512 | } |
497 | 513 | if (event.data.type === "SEND_DATA") { |
498 | 514 | store.sendPayloadToIframes("STORE_UPDATE"); |
| 515 | + store.sendConsentToIframes(); |
499 | 516 | const envId = getEnvironmentId(); |
500 | 517 | if (envId) { |
501 | 518 | const identify = store.config?.customOrigin ? identifyLead(envId, store.config) : identifyLead(envId); |
|
756 | 773 | notifyIframe(iframe, type) { |
757 | 774 | const target = iframe || document.querySelector("#surface-iframe"); |
758 | 775 | if (!target) return; |
| 776 | + this.postToSurfaceIframe(target, { |
| 777 | + type, |
| 778 | + payload: this.getPayload(), |
| 779 | + sender: "surface_tag" |
| 780 | + }); |
| 781 | + } |
| 782 | + postToSurfaceIframe(target, message) { |
759 | 783 | try { |
760 | 784 | const targetOrigin = new URL(target.src).origin; |
761 | 785 | if (!this.surfaceDomains.includes(targetOrigin)) return; |
762 | | - target.contentWindow?.postMessage( |
763 | | - { type, payload: this.getPayload(), sender: "surface_tag" }, |
764 | | - targetOrigin |
765 | | - ); |
| 786 | + target.contentWindow?.postMessage(message, targetOrigin); |
766 | 787 | } catch { |
767 | 788 | } |
768 | 789 | } |
| 790 | + // Relays the page's consent answer to every Surface form on it. Forms with a |
| 791 | + // category set to "On consent" stay dark until this arrives, so it is also |
| 792 | + // re-sent on each SEND_DATA handshake for frames that mount later. |
| 793 | + sendConsentToIframes() { |
| 794 | + const consent2 = getSurfaceConsent(); |
| 795 | + if (!consent2) return; |
| 796 | + document.querySelectorAll("iframe").forEach( |
| 797 | + (iframe) => this.postToSurfaceIframe(iframe, { |
| 798 | + type: SURFACE_CONSENT_MESSAGE_TYPE, |
| 799 | + sender: "surface_tag", |
| 800 | + consent: consent2 |
| 801 | + }) |
| 802 | + ); |
| 803 | + } |
769 | 804 | getUrlParams() { |
770 | 805 | return getUrlParams(); |
771 | 806 | } |
|
2473 | 2508 | w2.SurfaceSetLeadDataWithTTL = setLeadDataWithTTL; |
2474 | 2509 | w2.SurfaceGetLeadDataWithTTL = getLeadDataWithTTL; |
2475 | 2510 | w2.SurfaceGetSiteIdFromScript = getSiteIdFromScript; |
| 2511 | + w2.SurfaceSetConsent = setSurfaceConsent; |
| 2512 | + onSurfaceConsentChange(() => { |
| 2513 | + SurfaceTagStore.sendConsentToIframes(); |
| 2514 | + SurfaceTagStore.sendPayloadToIframes("STORE_UPDATE"); |
| 2515 | + }); |
2476 | 2516 | void resolveOpenTriggersOnLoad(environmentId2, runtimeConfig2); |
2477 | 2517 | initReview(); |
2478 | 2518 | })(); |
0 commit comments