-
Notifications
You must be signed in to change notification settings - Fork 8
Support Sourcepoint GPP consent for EC generation #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ChristianPavilonis
wants to merge
22
commits into
feature/edge-cookies-final
Choose a base branch
from
edge-cookie-sourcepoint-consent
base: feature/edge-cookies-final
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1c14b3d
Add design spec for Sourcepoint GPP consent support (#640)
ChristianPavilonis fca8979
Add implementation plan for Sourcepoint GPP consent support (#640)
ChristianPavilonis a1bc657
Add us_sale_opt_out field to GppConsent
ChristianPavilonis 1964872
Decode US sale opt-out from GPP sections
ChristianPavilonis fbb2457
Recognize GPP US sale opt-out in EC consent gating
ChristianPavilonis ad6e790
Add Sourcepoint JS integration for GPP consent cookie mirroring
ChristianPavilonis e025198
Add design spec for Prebid User ID Module support
ChristianPavilonis 6450637
Add implementation plan for Prebid User ID Module support
ChristianPavilonis a760c4c
Fix ESM path resolution in Prebid User ID plan regression guard
ChristianPavilonis c8abb71
Add Vitest coverage for Prebid ts-eids cookie sync
ChristianPavilonis eee99f0
Bundle Prebid User ID core and submodules in Prebid integration
ChristianPavilonis bd366ad
Correct Prebid User ID plan + spec — drop pubCommonIdSystem (removed …
ChristianPavilonis 05d1700
Drop liveIntentIdSystem from Prebid bundle
ChristianPavilonis 3d59d3d
Make Prebid User ID submodule set configurable at build time
ChristianPavilonis 67e55d5
Clear stale consent cookies and aggregate US GPP opt-outs
ChristianPavilonis f956e8a
Add Secure flag and Max-Age to Sourcepoint GPP cookies
ChristianPavilonis 08440a6
support ec partners map for env overrides
ChristianPavilonis 8e3ff80
Scope Sourcepoint consent PR and address review feedback
ChristianPavilonis fedcc34
Wire request signing to RuntimeServices store primitives (PR 9) (#609…
prk-Jr 24d4515
Remove generated Prebid user ID shim
ChristianPavilonis a2c6d83
Address Sourcepoint consent review feedback
ChristianPavilonis e7b561a
Address Sourcepoint review feedback
ChristianPavilonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { log } from '../../core/log'; | ||
|
|
||
| const SP_CONSENT_PREFIX = '_sp_user_consent_'; | ||
| const GPP_COOKIE_NAME = '__gpp'; | ||
| const GPP_SID_COOKIE_NAME = '__gpp_sid'; | ||
| const GPP_SOURCE_COOKIE_NAME = '_ts_gpp_src'; | ||
| const GPP_SOURCE_SOURCEPOINT = 'sp'; | ||
| const INITIAL_RETRY_DELAY_MS = 500; | ||
|
|
||
| interface SourcepointGppData { | ||
| gppString: string; | ||
| applicableSections: number[]; | ||
| } | ||
|
|
||
| interface SourcepointConsentPayload { | ||
| gppData?: SourcepointGppData; | ||
| } | ||
|
|
||
| let initialized = false; | ||
| let initialRetryDone = false; | ||
| let retryTimer: ReturnType<typeof window.setTimeout> | undefined; | ||
|
|
||
| function findSourcepointConsent(): SourcepointConsentPayload | null { | ||
| // Sourcepoint stores one consent payload per property under `_sp_user_consent_*`. | ||
| // We intentionally take the first valid match and mirror that origin-scoped payload. | ||
| for (let i = 0; i < localStorage.length; i++) { | ||
| const key = localStorage.key(i); | ||
| if (!key?.startsWith(SP_CONSENT_PREFIX)) continue; | ||
|
|
||
| const raw = localStorage.getItem(key); | ||
| if (!raw) continue; | ||
|
|
||
| try { | ||
| const payload = JSON.parse(raw) as SourcepointConsentPayload; | ||
| if (payload.gppData?.gppString) { | ||
| return payload; | ||
| } | ||
| } catch { | ||
| log.debug('sourcepoint: failed to parse localStorage value', { key }); | ||
| } | ||
| } | ||
| return null; | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function readCookie(name: string): string | undefined { | ||
| const prefix = `${name}=`; | ||
| const cookie = document.cookie.split('; ').find((entry) => entry.startsWith(prefix)); | ||
| return cookie?.slice(prefix.length); | ||
| } | ||
|
|
||
| function hasSourcepointMarker(): boolean { | ||
| return readCookie(GPP_SOURCE_COOKIE_NAME) === GPP_SOURCE_SOURCEPOINT; | ||
| } | ||
|
|
||
| function writeCookie(name: string, value: string): void { | ||
| document.cookie = `${name}=${value}; path=/; Secure; SameSite=Lax`; | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function clearCookie(name: string): void { | ||
| document.cookie = `${name}=; path=/; Secure; SameSite=Lax; Max-Age=0`; | ||
| } | ||
|
ChristianPavilonis marked this conversation as resolved.
ChristianPavilonis marked this conversation as resolved.
|
||
|
|
||
| function clearSourcepointCookies(): void { | ||
| if (!hasSourcepointMarker()) { | ||
| return; | ||
| } | ||
|
|
||
| clearCookie(GPP_COOKIE_NAME); | ||
| clearCookie(GPP_SID_COOKIE_NAME); | ||
| clearCookie(GPP_SOURCE_COOKIE_NAME); | ||
| } | ||
|
|
||
| function mirrorOnVisible(): void { | ||
| if (document.visibilityState === 'visible') { | ||
| mirrorSourcepointConsent(); | ||
| } | ||
| } | ||
|
|
||
| function clearInitialRetryTimer(): void { | ||
| if (retryTimer === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| window.clearTimeout(retryTimer); | ||
| retryTimer = undefined; | ||
| } | ||
|
|
||
| function scheduleInitialRetry(): void { | ||
| if (initialRetryDone || retryTimer !== undefined) { | ||
| return; | ||
| } | ||
|
|
||
| const retry = (): void => { | ||
| if (initialRetryDone) { | ||
| return; | ||
| } | ||
|
|
||
| initialRetryDone = true; | ||
| clearInitialRetryTimer(); | ||
| mirrorSourcepointConsent(); | ||
| }; | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', retry, { once: true }); | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| retryTimer = window.setTimeout(retry, INITIAL_RETRY_DELAY_MS); | ||
| } | ||
|
|
||
| /** | ||
| * Reads Sourcepoint consent from localStorage and mirrors it into | ||
| * `__gpp` and `__gpp_sid` cookies for Trusted Server to read. | ||
| * | ||
| * Returns `true` if cookies were written, `false` otherwise. | ||
| */ | ||
| export function mirrorSourcepointConsent(): boolean { | ||
| if (typeof localStorage === 'undefined' || typeof document === 'undefined') { | ||
| return false; | ||
| } | ||
|
|
||
| const payload = findSourcepointConsent(); | ||
| if (!payload?.gppData) { | ||
| clearSourcepointCookies(); | ||
| log.debug('sourcepoint: no GPP data found in localStorage'); | ||
| return false; | ||
| } | ||
|
|
||
| const { gppString, applicableSections } = payload.gppData; | ||
| if (!gppString) { | ||
| clearSourcepointCookies(); | ||
| log.debug('sourcepoint: gppString is empty'); | ||
| return false; | ||
| } | ||
|
|
||
| const existingGppCookie = readCookie(GPP_COOKIE_NAME); | ||
| if (existingGppCookie && existingGppCookie !== gppString && !hasSourcepointMarker()) { | ||
| log.debug('sourcepoint: preserving existing __gpp cookie from another writer'); | ||
| return false; | ||
| } | ||
|
|
||
| writeCookie(GPP_SOURCE_COOKIE_NAME, GPP_SOURCE_SOURCEPOINT); | ||
| writeCookie(GPP_COOKIE_NAME, gppString); | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
|
|
||
| if (Array.isArray(applicableSections) && applicableSections.length > 0) { | ||
| writeCookie(GPP_SID_COOKIE_NAME, applicableSections.join(',')); | ||
| } else { | ||
| clearCookie(GPP_SID_COOKIE_NAME); | ||
| } | ||
|
|
||
| initialRetryDone = true; | ||
| clearInitialRetryTimer(); | ||
|
|
||
| log.info('sourcepoint: mirrored GPP consent to cookies', { | ||
| gppLength: gppString.length, | ||
| sections: applicableSections, | ||
| }); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Initializes Sourcepoint consent mirroring and bounded refresh hooks. | ||
| */ | ||
| export function initializeSourcepointConsentMirror(): void { | ||
| if (initialized || typeof window === 'undefined' || typeof document === 'undefined') { | ||
| return; | ||
| } | ||
|
|
||
| initialized = true; | ||
|
|
||
| if (!mirrorSourcepointConsent()) { | ||
| scheduleInitialRetry(); | ||
| } | ||
|
|
||
| // Sourcepoint persists consent changes to localStorage. Re-mirror when a | ||
| // user returns to the page so session cookies do not remain stale. | ||
| document.addEventListener('visibilitychange', mirrorOnVisible); | ||
| window.addEventListener('focus', mirrorSourcepointConsent); | ||
| } | ||
|
|
||
| initializeSourcepointConsentMirror(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.