Skip to content

Commit

Permalink
Merge pull request #21 from blakemcintyre/fix-empty-adSlot-object-cau…
Browse files Browse the repository at this point in the history
…sed-by-ad-blocker

Fix Empty adSlot Object Caused by Ad Blocker
  • Loading branch information
potench authored Mar 23, 2017
2 parents e2d0e33 + b640665 commit 7f9a989
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Bling.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ class Bling extends Component {

clear() {
const adSlot = this._adSlot;
if (adSlot) {
if (adSlot && adSlot.hasOwnProperty("getServices")) {
// googletag.ContentService doesn't clear content
const services = adSlot.getServices();
if (this._divId && services.some(s => !!s.setContent)) {
Expand Down
9 changes: 6 additions & 3 deletions src/createManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,12 @@ export class AdManager extends EventEmitter {
if (!instance.notInViewport()) {
instance.defineSlot();
const adSlot = instance.adSlot;
const services = adSlot.getServices();
if (!hasPubAdsService) {
hasPubAdsService = services.filter(service => !!service.enableAsyncRendering).length > 0;

if (adSlot && adSlot.hasOwnProperty("getServices")) {
const services = adSlot.getServices();
if (!hasPubAdsService) {
hasPubAdsService = services.filter(service => !!service.enableAsyncRendering).length > 0;
}
}
}
});
Expand Down
17 changes: 17 additions & 0 deletions test/Bling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ describe("Bling", () => {
clear.restore();
});

it("handles empty adSlot on clear", () => {
const instance = new Bling();
instance._adSlot = {};

expect(() => {
instance.clear();
}).to.not.throw("adSlot.getServices is not a function");
});

it("calls getServices on adSlot on clear", () => {
const instance = new Bling();
const adSlot = sinon.mock({getServices: () => {}});
adSlot.expects("getServices").once();
instance._adSlot = adSlot;
instance.clear();
});

it("updates correlator", () => {
const updateCorrelator = sinon.stub(Bling._adManager, "updateCorrelator");

Expand Down

0 comments on commit 7f9a989

Please sign in to comment.