From 9e464ebb9b20c376feae96b5fb4a0a8bdde1bd08 Mon Sep 17 00:00:00 2001 From: vzhukovsky Date: Wed, 29 Aug 2018 19:07:09 +0300 Subject: [PATCH 1/2] Switched to native Prebid user syncs support. --- modules/aolBidAdapter.js | 89 +++++++++---------------- test/spec/modules/aolBidAdapter_spec.js | 60 +++-------------- 2 files changed, 38 insertions(+), 111 deletions(-) diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js index 28e8cb0b46e..ebf5706eb76 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,10 +41,6 @@ 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 @@ -80,32 +74,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; } @@ -176,15 +144,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 +321,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 +369,7 @@ export const spec = { } } - let bidResponse = { + return { bidderCode: bidRequest.bidderCode, requestId: bidRequest.bidId, ad: bidData.adm, @@ -394,24 +383,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 bc42f69ce63..41639af8844 100644 --- a/test/spec/modules/aolBidAdapter_spec.js +++ b/test/spec/modules/aolBidAdapter_spec.js @@ -97,7 +97,6 @@ describe('AolAdapter', () => { let bidResponse; let bidRequest; let logWarnSpy; - let formatPixelsStub; let isOneMobileBidderStub; beforeEach(() => { @@ -111,14 +110,12 @@ describe('AolAdapter', () => { body: getDefaultBidResponse() }; logWarnSpy = sinon.spy(utils, 'logWarn'); - formatPixelsStub = sinon.stub(spec, 'formatPixels'); isOneMobileBidderStub = sinon.stub(spec, 'isOneMobileBidder'); }); afterEach(() => { $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsBackup; logWarnSpy.restore(); - formatPixelsStub.restore(); isOneMobileBidderStub.restore(); }); @@ -140,17 +137,6 @@ describe('AolAdapter', () => { }); }); - it('should add pixels to ad content when pixels are present in the response', () => { - 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: { @@ -492,67 +478,37 @@ describe('AolAdapter', () => { }); describe('getUserSyncs()', () => { + let serverResponses; let bidResponse; - let bidRequest; beforeEach(() => { - $$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"', () => { - let userSyncs = spec.getUserSyncs({}, [bidResponse], bidRequest); + it('should return user syncs if pixels are present in the response', () => { + 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', () => { - $$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', () => { 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()', () => { - it('should return pixels wrapped for dropping them once and within nested frames ', () => { - let pixels = ''; - let formattedPixels = spec.formatPixels(pixels); - - expect(formattedPixels).to.equal( - ''); - }); - }); - describe('isOneMobileBidder()', () => { it('should return false when when bidderCode is not present', () => { expect(spec.isOneMobileBidder(null)).to.be.false; From 299f23fa87c5fae351c46bc23c58c44b3d18f91c Mon Sep 17 00:00:00 2001 From: vzhukovsky Date: Thu, 20 Sep 2018 16:22:01 +0300 Subject: [PATCH 2/2] Removed bid CPM adjustment warning to prevent using globals. --- modules/aolBidAdapter.js | 18 ------------------ test/spec/modules/aolBidAdapter_spec.js | 10 ---------- 2 files changed, 28 deletions(-) diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js index a1a1a606f48..b97252bf9b3 100644 --- a/modules/aolBidAdapter.js +++ b/modules/aolBidAdapter.js @@ -46,22 +46,6 @@ const NUMERIC_VALUES = { 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] || {}; @@ -132,8 +116,6 @@ export const spec = { }); }, interpretResponse({body}, bidRequest) { - showCpmAdjustmentWarning(); - if (!body) { utils.logError('Empty bid response', bidRequest.bidderCode, body); } else { diff --git a/test/spec/modules/aolBidAdapter_spec.js b/test/spec/modules/aolBidAdapter_spec.js index 4b235a75404..53113d0a67c 100644 --- a/test/spec/modules/aolBidAdapter_spec.js +++ b/test/spec/modules/aolBidAdapter_spec.js @@ -136,16 +136,6 @@ describe('AolAdapter', function () { ttl: bidRequest.ttl }); }); - - 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 () {