Skip to content

Commit

Permalink
[fix] configure disableInitialLoad before service initialization (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaanauati authored Feb 11, 2020
1 parent f40136e commit 361a542
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
14 changes: 11 additions & 3 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {
gptLoadAds(slotsToInitialize) {
return new Promise((resolve) => {
this.getGoogletag().then((googletag) => {
this.configureInitialOptions(googletag);
slotsToInitialize.forEach((currentSlotId) => {
registeredSlots[currentSlotId].loading = false;

Expand Down Expand Up @@ -246,6 +247,16 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {
});
},

// configure those gpt parameters that need to be set before pubsads service
// initialization.
configureInitialOptions(googletag) {
googletag.cmd.push(() => {
if (this.disableInitialLoadIsEnabled()) {
googletag.pubads().disableInitialLoad();
}
});
},

configureOptions(googletag) {
googletag.cmd.push(() => {
const pubadsService = googletag.pubads();
Expand Down Expand Up @@ -275,9 +286,6 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {
if (this.singleRequestIsEnabled()) {
pubadsService.enableSingleRequest();
}
if (this.disableInitialLoadIsEnabled()) {
pubadsService.disableInitialLoad();
}
if (this.collapseEmptyDivs === true || this.collapseEmptyDivs === false) {
pubadsService.collapseEmptyDivs(this.collapseEmptyDivs);
}
Expand Down
51 changes: 30 additions & 21 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {

return new Promise(function (resolve) {
_this3.getGoogletag().then(function (googletag) {
_this3.configureInitialOptions(googletag);

slotsToInitialize.forEach(function (currentSlotId) {
registeredSlots[currentSlotId].loading = false;
googletag.cmd.push(function () {
Expand Down Expand Up @@ -279,14 +281,25 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
});
});
},
configureOptions: function configureOptions(googletag) {
// configure those gpt parameters that need to be set before pubsads service
// initialization.
configureInitialOptions: function configureInitialOptions(googletag) {
var _this4 = this;

googletag.cmd.push(function () {
if (_this4.disableInitialLoadIsEnabled()) {
googletag.pubads().disableInitialLoad();
}
});
},
configureOptions: function configureOptions(googletag) {
var _this5 = this;

googletag.cmd.push(function () {
var pubadsService = googletag.pubads();
pubadsService.setRequestNonPersonalizedAds(_this4.personalizedAdsEnabled() ? 0 : 1);
pubadsService.setRequestNonPersonalizedAds(_this5.personalizedAdsEnabled() ? 0 : 1);

var targetingArguments = _this4.getTargetingArguments(); // set global targetting arguments
var targetingArguments = _this5.getTargetingArguments(); // set global targetting arguments


Object.keys(targetingArguments).forEach(function (varName) {
Expand All @@ -295,16 +308,16 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
}
}); // set global adSense attributes

var adSenseAttributes = _this4.getAdSenseAttributes();
var adSenseAttributes = _this5.getAdSenseAttributes();

Object.keys(adSenseAttributes).forEach(function (key) {
pubadsService.set(key, adSenseAttributes[key]);
});

if (_this4.lazyLoadIsEnabled()) {
if (_this5.lazyLoadIsEnabled()) {
var args = [];

var config = _this4.getLazyLoadConfig();
var config = _this5.getLazyLoadConfig();

if (config !== null) {
args.push(config);
Expand All @@ -313,16 +326,12 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
pubadsService.enableLazyLoad.call(args);
}

if (_this4.singleRequestIsEnabled()) {
if (_this5.singleRequestIsEnabled()) {
pubadsService.enableSingleRequest();
}

if (_this4.disableInitialLoadIsEnabled()) {
pubadsService.disableInitialLoad();
}

if (_this4.collapseEmptyDivs === true || _this4.collapseEmptyDivs === false) {
pubadsService.collapseEmptyDivs(_this4.collapseEmptyDivs);
if (_this5.collapseEmptyDivs === true || _this5.collapseEmptyDivs === false) {
pubadsService.collapseEmptyDivs(_this5.collapseEmptyDivs);
}
});
},
Expand Down Expand Up @@ -364,10 +373,10 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
}
},
gptRefreshAds: function gptRefreshAds(slots) {
var _this5 = this;
var _this6 = this;

return this.getGoogletag().then(function (googletag) {
_this5.configureOptions(googletag);
_this6.configureOptions(googletag);

googletag.cmd.push(function () {
var pubadsService = googletag.pubads();
Expand All @@ -378,14 +387,14 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
});
},
reload: function reload() {
var _this6 = this;
var _this7 = this;

return this.destroyGPTSlots.apply(this, arguments).then(function () {
return _this6.load();
return _this7.load();
});
},
destroyGPTSlots: function destroyGPTSlots() {
var _this7 = this;
var _this8 = this;

for (var _len4 = arguments.length, slotsToDestroy = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
slotsToDestroy[_key4] = arguments[_key4];
Expand All @@ -405,7 +414,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
slots.push(slot);
}

_this7.getGoogletag().then(function (googletag) {
_this8.getGoogletag().then(function (googletag) {
googletag.cmd.push(function () {
if (managerAlreadyInitialized === true) {
if (slotsToDestroy.length > 0) {
Expand All @@ -428,7 +437,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
});
},
registerSlot: function registerSlot(_ref) {
var _this8 = this;
var _this9 = this;

var slotId = _ref.slotId,
dfpNetworkId = _ref.dfpNetworkId,
Expand Down Expand Up @@ -467,7 +476,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
gptSlot = slot.gptSlot;

if (loading === false && !gptSlot) {
_this8.load(slotId);
_this9.load(slotId);
}
}
});
Expand Down

0 comments on commit 361a542

Please sign in to comment.