Skip to content

Commit

Permalink
update registeredSlots with targeting values and refresh (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
daraclare authored Jul 4, 2021
1 parent a5c3392 commit ade4f3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {

setTargetingArguments(data) {
Object.assign(globalTargetingArguments, data);
const availableKeys = Object.keys(registeredSlots);
availableKeys.forEach((slotId) => {
registeredSlots[slotId].targetingArguments = data;
});
if (managerAlreadyInitialized === true) {
this.getGoogletag().then((googletag) => {
googletag.cmd.push(() => {
Expand Down Expand Up @@ -354,9 +358,8 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {
this.configureOptions(googletag);
googletag.cmd.push(() => {
const pubadsService = googletag.pubads();
pubadsService.refresh(
slots.map(slotId => registeredSlots[slotId].gptSlot),
);
const slotsToRefreshArray = slots.map(slotId => registeredSlots[slotId].slotId);
pubadsService.refresh(slotsToRefreshArray);
});
});
},
Expand Down
11 changes: 8 additions & 3 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
},
setTargetingArguments: function setTargetingArguments(data) {
Object.assign(globalTargetingArguments, data);
var availableKeys = Object.keys(registeredSlots);
availableKeys.forEach(function (slotId) {
registeredSlots[slotId].targetingArguments = data;
});

if (managerAlreadyInitialized === true) {
this.getGoogletag().then(function (googletag) {
Expand Down Expand Up @@ -398,9 +402,10 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {

googletag.cmd.push(function () {
var pubadsService = googletag.pubads();
pubadsService.refresh(slots.map(function (slotId) {
return registeredSlots[slotId].gptSlot;
}));
var slotsToRefreshArray = slots.map(function (slotId) {
return registeredSlots[slotId].slotId;
});
pubadsService.refresh(slotsToRefreshArray);
});
});
},
Expand Down

0 comments on commit ade4f3b

Please sign in to comment.