diff --git a/src/prebid.js b/src/prebid.js index c00ff1dd499f..16284115220c 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -155,9 +155,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'); @@ -171,7 +172,7 @@ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit) { targeting.resetPresetTargeting(adUnit); // now set new targeting keys - targeting.setTargetingForGPT(targetingSet); + targeting.setTargetingForGPT(targetingSet, customSlotMatching); Object.keys(targetingSet).forEach((adUnitCode) => { Object.keys(targetingSet[adUnitCode]).forEach((targetingKey) => { diff --git a/src/targeting.js b/src/targeting.js index f81949f6d046..e33f1a88f10f 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -160,9 +160,9 @@ export function newTargeting(auctionManager) { * Sets targeting for DFP * @param {Object.>} 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(',');