Skip to content

Commit

Permalink
Allow user to override which gpt slots should be targeted at invocati…
Browse files Browse the repository at this point in the history
…on (prebid#2562)

* Allow user to override which gpt slots should be targeted at invocation time

* Added filter example
  • Loading branch information
ptomasroos authored and dluxemburg committed Jul 17, 2018
1 parent 7332e2f commit 65ff1f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,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

0 comments on commit 65ff1f0

Please sign in to comment.