Skip to content
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

Allow user to override which gpt slots should be targeted at invocation #2562

Merged
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
5 changes: 3 additions & 2 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode = function (adUnitCode) {
/**
* Set query string targeting on one or more GPT ad units.
* @param {(string|string[])} adUnit a single `adUnit.code` or multiple.
* @param {function(object)} customSlotMatching gets a GoogleTag slot and returns a filter function for adUnitCode, so you can decide to match on either eg. return slot => { return adUnitCode => { return slot.getSlotElementId() === 'myFavoriteDivId'; } };
* @alias module:pbjs.setTargetingForGPTAsync
*/
$$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit) {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit, customSlotMatching) {
utils.logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForGPTAsync', arguments);
if (!isGptPubadsDefined()) {
utils.logError('window.googletag is not defined on the page');
Expand All @@ -172,7 +173,7 @@ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit) {
targeting.resetPresetTargeting(adUnit);

// now set new targeting keys
targeting.setTargetingForGPT(targetingSet);
targeting.setTargetingForGPT(targetingSet, customSlotMatching);

// emit event
events.emit(SET_TARGETING, targetingSet);
Expand Down
4 changes: 2 additions & 2 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ export function newTargeting(auctionManager) {
* Sets targeting for DFP
* @param {Object.<string,Object.<string,string>>} targetingConfig
*/
targeting.setTargetingForGPT = function(targetingConfig) {
targeting.setTargetingForGPT = function(targetingConfig, customSlotMatching) {
window.googletag.pubads().getSlots().forEach(slot => {
Object.keys(targetingConfig).filter(isAdUnitCodeMatchingSlot(slot))
Object.keys(targetingConfig).filter(customSlotMatching ? customSlotMatching(slot) : isAdUnitCodeMatchingSlot(slot))
.forEach(targetId =>
Object.keys(targetingConfig[targetId]).forEach(key => {
let valueArr = targetingConfig[targetId][key].split(',');
Expand Down