diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js index 3d89007bbc2..b97252bf9b3 100644 --- a/modules/aolBidAdapter.js +++ b/modules/aolBidAdapter.js @@ -1,7 +1,5 @@ import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; -import { config } from 'src/config'; -import { EVENTS } from 'src/constants.json'; import { BANNER } from 'src/mediaTypes'; const AOL_BIDDERS_CODES = { @@ -43,31 +41,11 @@ const NEXAGE_SERVER = 'hb.nexage.com'; const ONE_DISPLAY_TTL = 60; const ONE_MOBILE_TTL = 3600; -$$PREBID_GLOBAL$$.aolGlobals = { - pixelsDropped: false -}; - const NUMERIC_VALUES = { TRUE: 1, FALSE: 0 }; -let showCpmAdjustmentWarning = (function() { - let showCpmWarning = true; - - return function() { - let bidderSettings = $$PREBID_GLOBAL$$.bidderSettings; - if (showCpmWarning && bidderSettings && bidderSettings.aol && - typeof bidderSettings.aol.bidCpmAdjustment === 'function') { - utils.logWarn( - 'bidCpmAdjustment is active for the AOL adapter. ' + - 'As of Prebid 0.14, AOL can bid in net – please contact your accounts team to enable.' - ); - showCpmWarning = false; // warning is shown at most once - } - }; -})(); - function template(strings, ...keys) { return function(...values) { let dict = values[values.length - 1] || {}; @@ -80,32 +58,6 @@ function template(strings, ...keys) { }; } -function parsePixelItems(pixels) { - let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi; - let tagNameRegExp = /\w*(?=\s)/; - let srcRegExp = /src=("|')(.*?)\1/; - let pixelsItems = []; - - if (pixels) { - let matchedItems = pixels.match(itemsRegExp); - if (matchedItems) { - matchedItems.forEach(item => { - let tagName = item.match(tagNameRegExp)[0]; - let url = item.match(srcRegExp)[2]; - - if (tagName && tagName) { - pixelsItems.push({ - type: tagName === SYNC_TYPES.IMAGE.TAG ? SYNC_TYPES.IMAGE.TYPE : SYNC_TYPES.IFRAME.TYPE, - url: url - }); - } - }); - } - } - - return pixelsItems; -} - function _isMarketplaceBidder(bidder) { return bidder === AOL_BIDDERS_CODES.AOL || bidder === AOL_BIDDERS_CODES.ONEDISPLAY; } @@ -164,8 +116,6 @@ export const spec = { }); }, interpretResponse({body}, bidRequest) { - showCpmAdjustmentWarning(); - if (!body) { utils.logError('Empty bid response', bidRequest.bidderCode, body); } else { @@ -176,15 +126,11 @@ export const spec = { } } }, - getUserSyncs(options, bidResponses) { - let bidResponse = bidResponses[0]; + getUserSyncs(options, serverResponses) { + const bidResponse = !utils.isEmpty(serverResponses) && serverResponses[0].body; - if (config.getConfig('aol.userSyncOn') === EVENTS.BID_RESPONSE) { - if (!$$PREBID_GLOBAL$$.aolGlobals.pixelsDropped && bidResponse && bidResponse.ext && bidResponse.ext.pixels) { - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = true; - - return parsePixelItems(bidResponse.ext.pixels); - } + if (bidResponse && bidResponse.ext && bidResponse.ext.pixels) { + return this.parsePixelItems(bidResponse.ext.pixels); } return []; @@ -357,6 +303,31 @@ export const spec = { return params; }, + parsePixelItems(pixels) { + let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi; + let tagNameRegExp = /\w*(?=\s)/; + let srcRegExp = /src=("|')(.*?)\1/; + let pixelsItems = []; + + if (pixels) { + let matchedItems = pixels.match(itemsRegExp); + if (matchedItems) { + matchedItems.forEach(item => { + let tagName = item.match(tagNameRegExp)[0]; + let url = item.match(srcRegExp)[2]; + + if (tagName && tagName) { + pixelsItems.push({ + type: tagName === SYNC_TYPES.IMAGE.TAG ? SYNC_TYPES.IMAGE.TYPE : SYNC_TYPES.IFRAME.TYPE, + url: url + }); + } + }); + } + } + + return pixelsItems; + }, _parseBidResponse(response, bidRequest) { let bidData; @@ -380,7 +351,7 @@ export const spec = { } } - let bidResponse = { + return { bidderCode: bidRequest.bidderCode, requestId: bidRequest.bidId, ad: bidData.adm, @@ -394,24 +365,6 @@ export const spec = { netRevenue: true, ttl: bidRequest.ttl }; - - if (response.ext && response.ext.pixels) { - if (config.getConfig('aol.userSyncOn') !== EVENTS.BID_RESPONSE) { - bidResponse.ad += this.formatPixels(response.ext.pixels); - } - } - - return bidResponse; - }, - formatPixels(pixels) { - let formattedPixels = pixels.replace(/<\/?script( type=('|")text\/javascript('|")|)?>/g, ''); - - return ''; }, isOneMobileBidder: _isOneMobileBidder, isSecureProtocol() { diff --git a/test/spec/modules/aolBidAdapter_spec.js b/test/spec/modules/aolBidAdapter_spec.js index 396ebf36c7d..53113d0a67c 100644 --- a/test/spec/modules/aolBidAdapter_spec.js +++ b/test/spec/modules/aolBidAdapter_spec.js @@ -97,7 +97,6 @@ describe('AolAdapter', function () { let bidResponse; let bidRequest; let logWarnSpy; - let formatPixelsStub; let isOneMobileBidderStub; beforeEach(function () { @@ -111,14 +110,12 @@ describe('AolAdapter', function () { body: getDefaultBidResponse() }; logWarnSpy = sinon.spy(utils, 'logWarn'); - formatPixelsStub = sinon.stub(spec, 'formatPixels'); isOneMobileBidderStub = sinon.stub(spec, 'isOneMobileBidder'); }); afterEach(function () { $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsBackup; logWarnSpy.restore(); - formatPixelsStub.restore(); isOneMobileBidderStub.restore(); }); @@ -139,27 +136,6 @@ describe('AolAdapter', function () { ttl: bidRequest.ttl }); }); - - it('should add pixels to ad content when pixels are present in the response', function () { - bidResponse.body.ext = { - pixels: 'pixels-content' - }; - - formatPixelsStub.returns('pixels-content'); - let formattedBidResponse = spec.interpretResponse(bidResponse, bidRequest); - - expect(formattedBidResponse.ad).to.equal(DEFAULT_AD_CONTENT + 'pixels-content'); - }); - - it('should show warning in the console', function() { - $$PREBID_GLOBAL$$.bidderSettings = { - aol: { - bidCpmAdjustment: function() {} - } - }; - spec.interpretResponse(bidResponse, bidRequest); - expect(utils.logWarn.calledOnce).to.be.true; - }); }); describe('buildRequests()', function () { @@ -492,69 +468,39 @@ describe('AolAdapter', function () { }); describe('getUserSyncs()', function () { + let serverResponses; let bidResponse; - let bidRequest; beforeEach(function () { - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = false; - config.setConfig({ - aol: { - userSyncOn: 'bidResponse' - }, - }); bidResponse = getDefaultBidResponse(); bidResponse.ext = { pixels: getPixels() }; + + serverResponses = [ + {body: bidResponse} + ]; }); - it('should return user syncs only if userSyncOn equals to "bidResponse"', function () { - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); + it('should return user syncs if pixels are present in the response', function () { + let userSyncs = spec.getUserSyncs({}, serverResponses); - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.true; expect(userSyncs).to.deep.equal([ {type: 'image', url: 'img.org'}, {type: 'iframe', url: 'pixels1.org'} ]); }); - it('should not return user syncs if it has already been returned', function () { - $$PREBID_GLOBAL$$.aolGlobals.pixelsDropped = true; - - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); - - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.true; - expect(userSyncs).to.deep.equal([]); - }); - it('should not return user syncs if pixels are not present', function () { bidResponse.ext.pixels = null; + let userSyncs = spec.getUserSyncs({}, serverResponses); - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); - - expect($$PREBID_GLOBAL$$.aolGlobals.pixelsDropped).to.be.false; expect(userSyncs).to.deep.equal([]); }); }); - describe('formatPixels()', function () { - it('should return pixels wrapped for dropping them once and within nested frames ', function () { - let pixels = ''; - let formattedPixels = spec.formatPixels(pixels); - - expect(formattedPixels).to.equal( - ''); - }); - }); - describe('isOneMobileBidder()', function () { - it('should return false when when bidderCode is not present', function () { + it('should return false when when bidderCode is not present', () => { expect(spec.isOneMobileBidder(null)).to.be.false; });