gpt: add targeting, contextual and EID-derived secure signal helpers - #319
Closed
mosherBT wants to merge 1 commit into
Closed
gpt: add targeting, contextual and EID-derived secure signal helpers#319mosherBT wants to merge 1 commit into
mosherBT wants to merge 1 commit into
Conversation
Adds three methods to the GPT addon, covering googletag calls that
integrations currently have to write themselves:
- setGPTTargeting(keyValues) merges page-level custom targeting via
googletag.setConfig(), so it composes with a publisher's own targeting.
- setGPTContextualTargeting(taxonomyKeys?, options?) pushes the contextual
key-values cached on the instance to pubads().setTargeting(). It does not
fetch, so it can be driven from the initContextual callback without a
second ctxSegments() request.
- installGPTSecureSignalsFromEIDs(eids, filter?) derives {provider, id}
pairs from ORTB2 EIDs and registers them through installGPTSecureSignals().
sources/inserters/matchers are allow-lists; an omitted or empty list places
no constraint on that field, matching the matcherFilter convention in the
RTD module. A provider is registered at most once per page load, since GPT
keeps one collector function per provider id.
All three queue on googletag.cmd and create window.googletag if absent, so
they are safe to call before GPT loads, and both new googletag calls are
wrapped so a failure cannot propagate into the host page.
Also corrects the installGPTEventListeners and installGPTSecureSignals
declarations, which were typed as () => void despite both taking arguments.
Adds lib/addons/gpt.md and links it from the GAM360 section of the README.
Contributor
Author
|
Closing this will reopen when ready to test and prepare the PR |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds three methods to the GPT addon, covering
googletagcalls that integrations currently have to write themselves.What's added
setGPTTargeting(keyValues)— writes page-level custom targeting viagoogletag.setConfig(), which merges the supplied keys into existing page-level targeting rather than replacing it. Safe to call alongside a publisher's own targeting and more than once with different keys. Values may be a string or a list of strings.setGPTContextualTargeting(taxonomyKeys?, options?)— pushes the contextual key-values already cached on the instance topubads().setTargeting(). Both arguments are forwarded toctxTargetingKeyValues()unchanged.This method deliberately does not fetch. Reading the cached response means it can be driven straight from the
initContextualcallback, whichInitConfigalready supports for exactly this purpose, without issuing a secondctxSegments()request:installGPTSecureSignalsFromEIDs(eids, filter?)— derives{ provider, id }pairs from ORTB2 EIDs and registers them through the existinginstallGPTSecureSignals(), so a targeting response can be handed over directly:sources,insertersandmatchersare allow-lists over the corresponding EID fields. An omitted or empty list places no constraint on that field, matching thematcherFilterconvention in the RTD module (lib/core/prebid/rtd.ts:312) rather than filtering everything out.A provider is registered at most once per page load. GPT keeps one collector function per provider id, so re-registering the same provider would install a duplicate collector. This means a refreshed token does not replace an already-registered signal — noted in the addon docs.
Notes
googletag.cmdand createwindow.googletagif absent, so they are safe to call before GPT has loaded.googletagcalls are wrapped so a failure cannot propagate into the host page, consistent withinstallGPTEventListeners.installGPTEventListenersandinstallGPTSecureSignalsdeclarations were typed() => voiddespite both taking arguments. Corrected — type-only, no behaviour change.Docs
New
lib/addons/gpt.mdcovering all five addon methods, filtering rules, contextual wiring and a full example, following theabTestAssignment.mdlayout. Linked from the GAM360 section of the main README.Tests
11 new cases in
lib/addons/gpt.test.jscovering targeting merge behaviour, contextual push and argument forwarding, secure-signal derivation, each filter dimension, empty-list semantics, once-per-provider registration, and the no-op paths.Suite passes at 21 suites / 338 tests. (
npx jestalso picks up stale copies under.claude/worktrees/; those 4 failures pre-exist onmasterand are unrelated.)