From 3d4a1391f4fc50763c6e30168c313d01d370bdfe Mon Sep 17 00:00:00 2001 From: WlsLogan <77974248+WlsLogan@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:22:15 +0300 Subject: [PATCH 01/19] Logan Bid Adapter: add new bid adapter (#7223) * initial * change vasturl to vastxml * fixes Co-authored-by: Aiholkin Co-authored-by: Mykhailo Yaremchuk --- modules/loganBidAdapter.js | 159 ++++++++++ modules/loganBidAdapter.md | 6 +- test/spec/modules/loganBidAdapter_spec.js | 337 ++++++++++++++++++++++ 3 files changed, 499 insertions(+), 3 deletions(-) create mode 100644 modules/loganBidAdapter.js create mode 100644 test/spec/modules/loganBidAdapter_spec.js diff --git a/modules/loganBidAdapter.js b/modules/loganBidAdapter.js new file mode 100644 index 00000000000..ae6d7a344d3 --- /dev/null +++ b/modules/loganBidAdapter.js @@ -0,0 +1,159 @@ +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; +import {config} from '../src/config.js'; + +const BIDDER_CODE = 'logan'; +const AD_URL = 'https://USeast2.logan.ai/pbjs'; +const SYNC_URL = 'https://ssp-cookie.logan.ai' + +function isBidResponseValid(bid) { + if (!bid.requestId || !bid.cpm || !bid.creativeId || + !bid.ttl || !bid.currency || !bid.meta) { + return false; + } + switch (bid.mediaType) { + case BANNER: + return Boolean(bid.width && bid.height && bid.ad); + case VIDEO: + return Boolean(bid.vastXml || bid.vastUrl); + case NATIVE: + return Boolean(bid.native && bid.native.impressionTrackers); + default: + return false; + } +} + +function getBidFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); + } + + try { + const bidFloor = bid.getFloor({ + currency: 'USD', + mediaType: '*', + size: '*', + }); + return bidFloor.floor; + } catch (_) { + return 0 + } +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + isBidRequestValid: (bid) => { + return Boolean(bid.bidId && bid.params && bid.params.placementId); + }, + + buildRequests: (validBidRequests = [], bidderRequest) => { + const winTop = utils.getWindowTop(); + const location = winTop.location; + const placements = []; + const request = { + deviceWidth: winTop.screen.width, + deviceHeight: winTop.screen.height, + language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '', + secure: 1, + host: location.host, + page: location.pathname, + placements: placements + }; + + if (bidderRequest) { + if (bidderRequest.uspConsent) { + request.ccpa = bidderRequest.uspConsent; + } + if (bidderRequest.gdprConsent) { + request.gdpr = bidderRequest.gdprConsent + } + } + + const len = validBidRequests.length; + for (let i = 0; i < len; i++) { + const bid = validBidRequests[i]; + const placement = { + placementId: bid.params.placementId, + bidId: bid.bidId, + schain: bid.schain || {}, + bidfloor: getBidFloor(bid) + }; + const mediaType = bid.mediaTypes + + if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) { + placement.sizes = mediaType[BANNER].sizes; + placement.adFormat = BANNER; + } else if (mediaType && mediaType[VIDEO] && mediaType[VIDEO].playerSize) { + placement.wPlayer = mediaType[VIDEO].playerSize[0]; + placement.hPlayer = mediaType[VIDEO].playerSize[1]; + placement.minduration = mediaType[VIDEO].minduration; + placement.maxduration = mediaType[VIDEO].maxduration; + placement.mimes = mediaType[VIDEO].mimes; + placement.protocols = mediaType[VIDEO].protocols; + placement.startdelay = mediaType[VIDEO].startdelay; + placement.placement = mediaType[VIDEO].placement; + placement.skip = mediaType[VIDEO].skip; + placement.skipafter = mediaType[VIDEO].skipafter; + placement.minbitrate = mediaType[VIDEO].minbitrate; + placement.maxbitrate = mediaType[VIDEO].maxbitrate; + placement.delivery = mediaType[VIDEO].delivery; + placement.playbackmethod = mediaType[VIDEO].playbackmethod; + placement.api = mediaType[VIDEO].api; + placement.linearity = mediaType[VIDEO].linearity; + placement.adFormat = VIDEO; + } else if (mediaType && mediaType[NATIVE]) { + placement.native = mediaType[NATIVE]; + placement.adFormat = NATIVE; + } + placements.push(placement); + } + + return { + method: 'POST', + url: AD_URL, + data: request + }; + }, + + interpretResponse: (serverResponse) => { + let response = []; + for (let i = 0; i < serverResponse.body.length; i++) { + let resItem = serverResponse.body[i]; + if (isBidResponseValid(resItem)) { + const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; + resItem.meta = { ...resItem.meta, advertiserDomains }; + + response.push(resItem); + } + } + return response; + }, + + getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { + let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image'; + let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`; + if (gdprConsent && gdprConsent.consentString) { + if (typeof gdprConsent.gdprApplies === 'boolean') { + syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; + } + } + if (uspConsent && uspConsent.consentString) { + syncUrl += `&ccpa_consent=${uspConsent.consentString}`; + } + + const coppa = config.getConfig('coppa') ? 1 : 0; + syncUrl += `&coppa=${coppa}`; + + return [{ + type: syncType, + url: syncUrl + }]; + } +}; + +registerBidder(spec); diff --git a/modules/loganBidAdapter.md b/modules/loganBidAdapter.md index 3c628cdacc2..a4e082e47c2 100644 --- a/modules/loganBidAdapter.md +++ b/modules/loganBidAdapter.md @@ -24,7 +24,7 @@ Module that connects to logan demand sources { bidder: 'logan', params: { - placementId: 0 + placementId: 'testBanner' } } ] @@ -41,7 +41,7 @@ Module that connects to logan demand sources { bidder: 'logan', params: { - placementId: 0 + placementId: 'testVideo' } } ] @@ -63,7 +63,7 @@ Module that connects to logan demand sources { bidder: 'logan', params: { - placementId: 0 + placementId: 'testNative' } } ] diff --git a/test/spec/modules/loganBidAdapter_spec.js b/test/spec/modules/loganBidAdapter_spec.js new file mode 100644 index 00000000000..a9859bbd4ae --- /dev/null +++ b/test/spec/modules/loganBidAdapter_spec.js @@ -0,0 +1,337 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/loganBidAdapter.js'; +import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; + +describe('LoganBidAdapter', function () { + const bid = { + bidId: '23fhj33i987f', + bidder: 'logan', + mediaTypes: { + [BANNER]: { + sizes: [[300, 250]] + } + }, + params: { + placementId: 783, + } + }; + + const bidderRequest = { + refererInfo: { + referer: 'test.com' + } + }; + + describe('isBidRequestValid', function () { + it('Should return true if there are bidId, params and key parameters present', function () { + expect(spec.isBidRequestValid(bid)).to.be.true; + }); + it('Should return false if at least one of parameters is not present', function () { + delete bid.params.placementId; + expect(spec.isBidRequestValid(bid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests([bid], bidderRequest); + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('https://USeast2.logan.ai/pbjs'); + }); + it('Returns valid data if array of bids is valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.language).to.be.a('string'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + expect(data.gdpr).to.not.exist; + expect(data.ccpa).to.not.exist; + let placement = data['placements'][0]; + expect(placement).to.have.keys('placementId', 'bidId', 'adFormat', 'sizes', 'schain', 'bidfloor'); + expect(placement.placementId).to.equal(783); + expect(placement.bidId).to.equal('23fhj33i987f'); + expect(placement.adFormat).to.equal(BANNER); + expect(placement.schain).to.be.an('object'); + expect(placement.sizes).to.be.an('array'); + expect(placement.bidfloor).to.exist.and.to.equal(0); + }); + + it('Returns valid data for mediatype video', function () { + const playerSize = [300, 300]; + bid.mediaTypes = {}; + bid.mediaTypes[VIDEO] = { + playerSize + }; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('placementId', 'bidId', 'adFormat', 'wPlayer', 'hPlayer', 'schain', 'minduration', 'maxduration', 'mimes', 'protocols', 'startdelay', 'placement', 'skip', 'skipafter', 'minbitrate', 'maxbitrate', 'delivery', 'playbackmethod', 'api', 'linearity', 'bidfloor'); + expect(placement.adFormat).to.equal(VIDEO); + expect(placement.wPlayer).to.equal(playerSize[0]); + expect(placement.hPlayer).to.equal(playerSize[1]); + expect(placement.bidfloor).to.exist.and.to.equal(0); + }); + + it('Returns valid data for mediatype native', function () { + const native = { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + }; + + bid.mediaTypes = {}; + bid.mediaTypes[NATIVE] = native; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('placementId', 'bidId', 'adFormat', 'native', 'schain', 'bidfloor'); + expect(placement.adFormat).to.equal(NATIVE); + expect(placement.native).to.equal(native); + expect(placement.bidfloor).to.exist.and.to.equal(0); + }); + + it('Returns data with gdprConsent and without uspConsent', function () { + bidderRequest.gdprConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.gdpr).to.exist; + expect(data.gdpr).to.be.a('string'); + expect(data.gdpr).to.equal(bidderRequest.gdprConsent); + expect(data.ccpa).to.not.exist; + delete bidderRequest.gdprConsent; + }); + + it('Returns data with uspConsent and without gdprConsent', function () { + bidderRequest.uspConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.ccpa).to.exist; + expect(data.ccpa).to.be.a('string'); + expect(data.ccpa).to.equal(bidderRequest.uspConsent); + expect(data.gdpr).to.not.exist; + }); + + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([]); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + describe('interpretResponse', function () { + it('Should interpret banner response', function () { + const banner = { + body: [{ + mediaType: 'banner', + width: 300, + height: 250, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1', + meta: {} + }] + }; + let bannerResponses = spec.interpretResponse(banner); + expect(bannerResponses).to.be.an('array').that.is.not.empty; + let dataItem = bannerResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.width).to.equal(300); + expect(dataItem.height).to.equal(250); + expect(dataItem.ad).to.equal('Test'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret video response', function () { + const video = { + body: [{ + vastUrl: 'test.com', + vastXml: '', + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1', + meta: {} + }] + }; + let videoResponses = spec.interpretResponse(video); + expect(videoResponses).to.be.an('array').that.is.not.empty; + + let dataItem = videoResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'vastXml', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.5); + expect(dataItem.vastUrl).to.equal('test.com'); + expect(dataItem.vastXml).to.equal(''); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret native response', function () { + const native = { + body: [{ + mediaType: 'native', + native: { + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], + }, + ttl: 120, + cpm: 0.4, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + meta: {} + }] + }; + let nativeResponses = spec.interpretResponse(native); + expect(nativeResponses).to.be.an('array').that.is.not.empty; + + let dataItem = nativeResponses[0]; + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); + expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.native.clickUrl).to.equal('test.com'); + expect(dataItem.native.title).to.equal('Test'); + expect(dataItem.native.image).to.equal('test.com'); + expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should return an empty array if invalid banner response is passed', function () { + const invBanner = { + body: [{ + width: 300, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + + let serverResponses = spec.interpretResponse(invBanner); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid video response is passed', function () { + const invVideo = { + body: [{ + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invVideo); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid native response is passed', function () { + const invNative = { + body: [{ + mediaType: 'native', + clickUrl: 'test.com', + title: 'Test', + impressionTrackers: ['test.com'], + ttl: 120, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let serverResponses = spec.interpretResponse(invNative); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid response is passed', function () { + const invalid = { + body: [{ + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invalid); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); + describe('getUserSyncs', function() { + it('Should return array of objects with proper sync config , include GDPR', function() { + const syncData = spec.getUserSyncs({}, {}, { + consentString: 'ALL', + gdprApplies: true, + }, {}); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('image') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://ssp-cookie.logan.ai/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') + }); + it('Should return array of objects with proper sync config , include CCPA', function() { + const syncData = spec.getUserSyncs({}, {}, {}, { + consentString: '1NNN' + }); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('image') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://ssp-cookie.logan.ai/image?pbjs=1&ccpa_consent=1NNN&coppa=0') + }); + }); +}); From 376b0e719aa6a2db3c80f41d55ad397b66571706 Mon Sep 17 00:00:00 2001 From: Sacha <35510349+thebraveio@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:45:33 +0300 Subject: [PATCH 02/19] Brave Bid Adapter: add new bid adapter (#7271) * added Brave bidder adapter with test and docs Commit has standard bidder adapter 2 new files adapter js, adapter md * added test spec file witch covered code least 80 % --- modules/braveBidAdapter.js | 267 ++++++++++++++++ modules/braveBidAdapter.md | 135 ++++++++ test/spec/modules/braveBidAdapter_spec.js | 363 ++++++++++++++++++++++ 3 files changed, 765 insertions(+) create mode 100644 modules/braveBidAdapter.js create mode 100644 modules/braveBidAdapter.md create mode 100644 test/spec/modules/braveBidAdapter_spec.js diff --git a/modules/braveBidAdapter.js b/modules/braveBidAdapter.js new file mode 100644 index 00000000000..7ea3eb9cd9b --- /dev/null +++ b/modules/braveBidAdapter.js @@ -0,0 +1,267 @@ +import * as utils from '../src/utils.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import { config } from '../src/config.js'; + +const BIDDER_CODE = 'brave'; +const DEFAULT_CUR = 'USD'; +const ENDPOINT_URL = `https://point.bravegroup.tv/?t=2&partner=hash`; + +const NATIVE_ASSETS_IDS = { 1: 'title', 2: 'icon', 3: 'image', 4: 'body', 5: 'sponsoredBy', 6: 'cta' }; +const NATIVE_ASSETS = { + title: { id: 1, name: 'title' }, + icon: { id: 2, type: 1, name: 'img' }, + image: { id: 3, type: 3, name: 'img' }, + body: { id: 4, type: 2, name: 'data' }, + sponsoredBy: { id: 5, type: 1, name: 'data' }, + cta: { id: 6, type: 12, name: 'data' } +}; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + /** + * Determines whether or not the given bid request is valid. + * + * @param {object} bid The bid to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: (bid) => { + return !!(bid.params.placementId && bid.params.placementId.toString().length === 32); + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: (validBidRequests, bidderRequest) => { + if (validBidRequests.length === 0 || !bidderRequest) return []; + + const endpointURL = ENDPOINT_URL.replace('hash', validBidRequests[0].params.placementId); + + let imp = validBidRequests.map(br => { + let impObject = { + id: br.bidId, + secure: 1 + }; + + if (br.mediaTypes.banner) { + impObject.banner = createBannerRequest(br); + } else if (br.mediaTypes.video) { + impObject.video = createVideoRequest(br); + } else if (br.mediaTypes.native) { + impObject.native = { + id: br.transactionId, + ver: '1.2', + request: createNativeRequest(br) + }; + } + return impObject; + }); + + let w = window; + let l = w.document.location.href; + let r = w.document.referrer; + + let loopChecker = 0; + while (w !== w.parent) { + if (++loopChecker == 10) break; + try { + w = w.parent; + l = w.location.href; + r = w.document.referrer; + } catch (e) { + break; + } + } + + let page = l || bidderRequest.refererInfo.referer; + + let data = { + id: bidderRequest.bidderRequestId, + cur: [ DEFAULT_CUR ], + device: { + w: screen.width, + h: screen.height, + language: (navigator && navigator.language) ? navigator.language.indexOf('-') != -1 ? navigator.language.split('-')[0] : navigator.language : '', + ua: navigator.userAgent, + }, + site: { + domain: utils.parseUrl(page).hostname, + page: page, + }, + tmax: bidderRequest.timeout || config.getConfig('bidderTimeout') || 500, + imp + }; + + if (r) { + data.site.ref = r; + } + + if (bidderRequest.gdprConsent) { + data['regs'] = {'ext': {'gdpr': bidderRequest.gdprConsent.gdprApplies ? 1 : 0}}; + data['user'] = {'ext': {'consent': bidderRequest.gdprConsent.consentString ? bidderRequest.gdprConsent.consentString : ''}}; + } + + if (bidderRequest.uspConsent !== undefined) { + if (!data['regs'])data['regs'] = {'ext': {}}; + data['regs']['ext']['us_privacy'] = bidderRequest.uspConsent; + } + + if (config.getConfig('coppa') === true) { + if (!data['regs'])data['regs'] = {'coppa': 1}; + else data['regs']['coppa'] = 1; + } + + if (validBidRequests[0].schain) { + data['source'] = {'ext': {'schain': validBidRequests[0].schain}}; + } + + return { + method: 'POST', + url: endpointURL, + data: data + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: (serverResponse) => { + if (!serverResponse || utils.isEmpty(serverResponse.body)) return []; + + let bids = []; + serverResponse.body.seatbid.forEach(response => { + response.bid.forEach(bid => { + let mediaType = bid.ext && bid.ext.mediaType ? bid.ext.mediaType : 'banner'; + + let bidObj = { + requestId: bid.impid, + cpm: bid.price, + width: bid.w, + height: bid.h, + ttl: 1200, + currency: DEFAULT_CUR, + netRevenue: true, + creativeId: bid.crid, + dealId: bid.dealid || null, + mediaType: mediaType + }; + + switch (mediaType) { + case 'video': + bidObj.vastUrl = bid.adm; + break; + case 'native': + bidObj.native = parseNative(bid.adm); + break; + default: + bidObj.ad = bid.adm; + } + + bids.push(bidObj); + }); + }); + + return bids; + }, + + onBidWon: (bid) => { + if (utils.isStr(bid.nurl) && bid.nurl !== '') { + utils.triggerPixel(bid.nurl); + } + } +}; + +const parseNative = adm => { + let bid = { + clickUrl: adm.native.link && adm.native.link.url, + impressionTrackers: adm.native.imptrackers || [], + clickTrackers: (adm.native.link && adm.native.link.clicktrackers) || [], + jstracker: adm.native.jstracker || [] + }; + adm.native.assets.forEach(asset => { + let kind = NATIVE_ASSETS_IDS[asset.id]; + let content = kind && asset[NATIVE_ASSETS[kind].name]; + if (content) { + bid[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h }; + } + }); + + return bid; +} + +const createNativeRequest = br => { + let impObject = { + ver: '1.2', + assets: [] + }; + + let keys = Object.keys(br.mediaTypes.native); + + for (let key of keys) { + const props = NATIVE_ASSETS[key]; + if (props) { + const asset = { + required: br.mediaTypes.native[key].required ? 1 : 0, + id: props.id, + [props.name]: {} + }; + + if (props.type) asset[props.name]['type'] = props.type; + if (br.mediaTypes.native[key].len) asset[props.name]['len'] = br.mediaTypes.native[key].len; + if (br.mediaTypes.native[key].sizes && br.mediaTypes.native[key].sizes[0]) { + asset[props.name]['w'] = br.mediaTypes.native[key].sizes[0]; + asset[props.name]['h'] = br.mediaTypes.native[key].sizes[1]; + } + + impObject.assets.push(asset); + } + } + + return impObject; +} + +const createBannerRequest = br => { + let size = []; + + if (br.mediaTypes.banner.sizes && Array.isArray(br.mediaTypes.banner.sizes)) { + if (Array.isArray(br.mediaTypes.banner.sizes[0])) { size = br.mediaTypes.banner.sizes[0]; } else { size = br.mediaTypes.banner.sizes; } + } else size = [300, 250]; + + return { id: br.transactionId, w: size[0], h: size[1] }; +}; + +const createVideoRequest = br => { + let videoObj = {id: br.transactionId}; + let supportParamsList = ['mimes', 'minduration', 'maxduration', 'protocols', 'startdelay', 'skip', 'minbitrate', 'maxbitrate', 'api', 'linearity']; + + for (let param of supportParamsList) { + if (br.mediaTypes.video[param] !== undefined) { + videoObj[param] = br.mediaTypes.video[param]; + } + } + + if (br.mediaTypes.video.playerSize && Array.isArray(br.mediaTypes.video.playerSize)) { + if (Array.isArray(br.mediaTypes.video.playerSize[0])) { + videoObj.w = br.mediaTypes.video.playerSize[0][0]; + videoObj.h = br.mediaTypes.video.playerSize[0][1]; + } else { + videoObj.w = br.mediaTypes.video.playerSize[0]; + videoObj.h = br.mediaTypes.video.playerSize[1]; + } + } else { + videoObj.w = 640; + videoObj.h = 480; + } + + return videoObj; +} + +registerBidder(spec); diff --git a/modules/braveBidAdapter.md b/modules/braveBidAdapter.md new file mode 100644 index 00000000000..77d2338ff16 --- /dev/null +++ b/modules/braveBidAdapter.md @@ -0,0 +1,135 @@ +# Overview + +``` +Module Name: Brave Bidder Adapter +Module Type: Bidder Adapter +Maintainer: support@thebrave.io +``` + +# Description + +Module which connects to Brave SSP demand sources + +# Test Parameters + + +250x300 banner test +``` +var adUnits = [{ + code: 'brave-prebid', + mediaTypes: { + banner: { + sizes: [[300, 250]] + } + }, + bids: [{ + bidder: 'brave', + params : { + placementId : "to0QI2aPgkbBZq6vgf0oHitouZduz0qw" // test placementId, please replace after test + } + }] +}]; +``` + +native test +``` +var adUnits = [{ + code: 'brave-native-prebid', + mediaTypes: { + native: { + title: { + required: true, + len: 800 + }, + image: { + required: true, + len: 80 + }, + sponsoredBy: { + required: true + }, + clickUrl: { + required: true + }, + privacyLink: { + required: false + }, + body: { + required: true + }, + icon: { + required: true, + sizes: [50, 50] + } + } + }, + bids: [{ + bidder: 'brave', + params: { + placementId : "to0QI2aPgkbBZq6vgf0oHitouZduz0qw" // test placementId, please replace after test + } + }] +}]; +``` + +video test +``` +var adUnits = [{ + code: 'brave-video-prebid', + mediaTypes: { + video: { + minduration:1, + maxduration:999, + boxingallowed:1, + skip:0, + mimes:[ + 'application/javascript', + 'video/mp4' + ], + playerSize: [[768, 1024]], + protocols:[ + 2,3 + ], + linearity:1, + api:[ + 1, + 2 + ] + } + }, + bids: [{ + bidder: 'brave', + params: { + placementId : "to0QI2aPgkbBZq6vgf0oHitouZduz0qw" // test placementId, please replace after test + } + }] +}]; +``` + +# Bid Parameters +## Banner + +| Name | Scope | Type | Description | Example +| ---- | ----- | ---- | ----------- | ------- +| `placementId` | required | String | The placement ID from Brave | "to0QI2aPgkbBZq6vgf0oHitouZduz0qw" + + +# Ad Unit and page Setup: + +```html + + + +``` diff --git a/test/spec/modules/braveBidAdapter_spec.js b/test/spec/modules/braveBidAdapter_spec.js new file mode 100644 index 00000000000..392f3b9f263 --- /dev/null +++ b/test/spec/modules/braveBidAdapter_spec.js @@ -0,0 +1,363 @@ +import { expect } from 'chai'; +import { spec } from 'modules/braveBidAdapter.js'; + +const request_native = { + code: 'brave-native-prebid', + mediaTypes: { + native: { + title: { + required: true, + len: 800 + }, + image: { + required: true, + len: 80 + }, + sponsoredBy: { + required: true + }, + clickUrl: { + required: true + }, + privacyLink: { + required: false + }, + body: { + required: true + }, + icon: { + required: true, + sizes: [50, 50] + } + } + }, + bidder: 'brave', + params: { + placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' + } +}; + +const request_banner = { + code: 'brave-prebid', + mediaTypes: { + banner: { + sizes: [[300, 250]] + } + }, + bidder: 'brave', + params: { + placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' + } +} + +const bidRequest = { + gdprConsent: { + consentString: 'HFIDUYFIUYIUYWIPOI87392DSU', + gdprApplies: true + }, + uspConsent: 'uspConsentString', + bidderRequestId: 'testid', + refererInfo: { + referer: 'testdomain.com' + }, + timeout: 700 +} + +const request_video = { + code: 'brave-video-prebid', + mediaTypes: { video: { + minduration: 1, + maxduration: 999, + boxingallowed: 1, + skip: 0, + mimes: [ + 'application/javascript', + 'video/mp4' + ], + playerSize: [[768, 1024]], + protocols: [ + 2, 3 + ], + linearity: 1, + api: [ + 1, + 2 + ] + } + }, + + bidder: 'brave', + params: { + placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' + } + +} + +const response_banner = { + id: 'request_id', + bidid: 'request_imp_id', + seatbid: [{ + bid: [{ + id: 'bid_id', + impid: 'request_imp_id', + price: 5, + adomain: ['example.com'], + adm: 'admcode', + crid: 'crid', + ext: { + mediaType: 'banner' + } + }] + }] +}; + +const response_video = { + id: 'request_id', + bidid: 'request_imp_id', + seatbid: [{ + bid: [{ + id: 'bid_id', + impid: 'request_imp_id', + price: 5, + adomain: ['example.com'], + adm: 'admcode', + crid: 'crid', + ext: { + mediaType: 'video' + } + }], + }], +}; + +let imgData = { + url: `https://example.com/image`, + w: 1200, + h: 627 +}; + +const response_native = { + id: 'request_id', + bidid: 'request_imp_id', + seatbid: [{ + bid: [{ + id: 'bid_id', + impid: 'request_imp_id', + price: 5, + adomain: ['example.com'], + adm: { native: + { + assets: [ + {id: 1, title: 'dummyText'}, + {id: 3, image: imgData}, + { + id: 5, + data: {value: 'organization.name'} + } + ], + link: {url: 'example.com'}, + imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'], + jstracker: 'tracker1.com' + } + }, + crid: 'crid', + ext: { + mediaType: 'native' + } + }], + }], +}; + +describe('BraveBidAdapter', function() { + describe('isBidRequestValid', function() { + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(request_banner)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, request_banner); + bid.params = { + 'IncorrectParam': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('build Native Request', function () { + const request = spec.buildRequests([request_native], bidRequest); + + it('Creates a ServerRequest object with method, URL and data', function () { + expect(request).to.exist; + expect(request.method).to.exist; + expect(request.url).to.exist; + expect(request.data).to.exist; + }); + + it('sends bid request to our endpoint via POST', function () { + expect(request.method).to.equal('POST'); + }); + + it('Returns valid URL', function () { + expect(request.url).to.equal('https://point.bravegroup.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); + }); + + it('Returns empty data if no valid requests are passed', function () { + let serverRequest = spec.buildRequests([]); + expect(serverRequest).to.be.an('array').that.is.empty; + }); + }); + + describe('build Banner Request', function () { + const request = spec.buildRequests([request_banner], bidRequest); + + it('Creates a ServerRequest object with method, URL and data', function () { + expect(request).to.exist; + expect(request.method).to.exist; + expect(request.url).to.exist; + expect(request.data).to.exist; + }); + + it('sends bid request to our endpoint via POST', function () { + expect(request.method).to.equal('POST'); + }); + + it('Returns valid URL', function () { + expect(request.url).to.equal('https://point.bravegroup.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); + }); + }); + + describe('build Video Request', function () { + const request = spec.buildRequests([request_video], bidRequest); + + it('Creates a ServerRequest object with method, URL and data', function () { + expect(request).to.exist; + expect(request.method).to.exist; + expect(request.url).to.exist; + expect(request.data).to.exist; + }); + + it('sends bid request to our endpoint via POST', function () { + expect(request.method).to.equal('POST'); + }); + + it('Returns valid URL', function () { + expect(request.url).to.equal('https://point.bravegroup.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); + }); + }); + + describe('interpretResponse', function () { + it('Empty response must return empty array', function() { + const emptyResponse = null; + let response = spec.interpretResponse(emptyResponse); + + expect(response).to.be.an('array').that.is.empty; + }) + + it('Should interpret banner response', function () { + const bannerResponse = { + body: response_banner + } + + const expectedBidResponse = { + requestId: response_banner.seatbid[0].bid[0].impid, + cpm: response_banner.seatbid[0].bid[0].price, + width: response_banner.seatbid[0].bid[0].w, + height: response_banner.seatbid[0].bid[0].h, + ttl: response_banner.ttl || 1200, + currency: response_banner.cur || 'USD', + netRevenue: true, + creativeId: response_banner.seatbid[0].bid[0].crid, + dealId: response_banner.seatbid[0].bid[0].dealid, + mediaType: 'banner', + ad: response_banner.seatbid[0].bid[0].adm + } + + let bannerResponses = spec.interpretResponse(bannerResponse); + + expect(bannerResponses).to.be.an('array').that.is.not.empty; + let dataItem = bannerResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType'); + expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); + expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); + expect(dataItem.ad).to.equal(expectedBidResponse.ad); + expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); + expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal(expectedBidResponse.currency); + expect(dataItem.width).to.equal(expectedBidResponse.width); + expect(dataItem.height).to.equal(expectedBidResponse.height); + }); + + it('Should interpret video response', function () { + const videoResponse = { + body: response_video + } + + const expectedBidResponse = { + requestId: response_video.seatbid[0].bid[0].impid, + cpm: response_video.seatbid[0].bid[0].price, + width: response_video.seatbid[0].bid[0].w, + height: response_video.seatbid[0].bid[0].h, + ttl: response_video.ttl || 1200, + currency: response_video.cur || 'USD', + netRevenue: true, + creativeId: response_video.seatbid[0].bid[0].crid, + dealId: response_video.seatbid[0].bid[0].dealid, + mediaType: 'video', + vastUrl: response_video.seatbid[0].bid[0].adm + } + + let videoResponses = spec.interpretResponse(videoResponse); + + expect(videoResponses).to.be.an('array').that.is.not.empty; + let dataItem = videoResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastUrl', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType'); + expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); + expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); + expect(dataItem.vastUrl).to.equal(expectedBidResponse.vastUrl) + expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); + expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal(expectedBidResponse.currency); + expect(dataItem.width).to.equal(expectedBidResponse.width); + expect(dataItem.height).to.equal(expectedBidResponse.height); + }); + + it('Should interpret native response', function () { + const nativeResponse = { + body: response_native + } + + const expectedBidResponse = { + requestId: response_native.seatbid[0].bid[0].impid, + cpm: response_native.seatbid[0].bid[0].price, + width: response_native.seatbid[0].bid[0].w, + height: response_native.seatbid[0].bid[0].h, + ttl: response_native.ttl || 1200, + currency: response_native.cur || 'USD', + netRevenue: true, + creativeId: response_native.seatbid[0].bid[0].crid, + dealId: response_native.seatbid[0].bid[0].dealid, + mediaType: 'native', + native: {clickUrl: response_native.seatbid[0].bid[0].adm.native.link.url} + } + + let nativeResponses = spec.interpretResponse(nativeResponse); + + expect(nativeResponses).to.be.an('array').that.is.not.empty; + let dataItem = nativeResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'native', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType'); + expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); + expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); + expect(dataItem.native.clickUrl).to.equal(expectedBidResponse.native.clickUrl) + expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); + expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal(expectedBidResponse.currency); + expect(dataItem.width).to.equal(expectedBidResponse.width); + expect(dataItem.height).to.equal(expectedBidResponse.height); + }); + }); +}) From d7f6802be668f230955d06785c24abe075cf62eb Mon Sep 17 00:00:00 2001 From: Vitali Ioussoupov <84333122+pixfuture-media@users.noreply.github.com> Date: Mon, 9 Aug 2021 10:40:30 -0400 Subject: [PATCH 03/19] Changed directory path in the line #115 (#7278) Changed directory path in the line #115 from url: `${hostname}/auc/auc.php` to ${hostname}/ --- modules/pixfutureBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pixfutureBidAdapter.js b/modules/pixfutureBidAdapter.js index edf6a35e997..e5422f36358 100644 --- a/modules/pixfutureBidAdapter.js +++ b/modules/pixfutureBidAdapter.js @@ -112,7 +112,7 @@ export const spec = { } const ret = { - url: `${hostname}/auc/auc.php`, + url: `${hostname}/`, method: 'POST', options: {withCredentials: false}, data: { From c06dca570cd85b5f82e47c13798b038c956f78c2 Mon Sep 17 00:00:00 2001 From: Denis Logachov Date: Tue, 10 Aug 2021 10:42:42 +0300 Subject: [PATCH 04/19] Adkernel Bid Adapter: RtbAnalytica alias (#7281) --- modules/adkernelBidAdapter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js index 3d868bb91d2..5cfb44f7127 100644 --- a/modules/adkernelBidAdapter.js +++ b/modules/adkernelBidAdapter.js @@ -69,7 +69,8 @@ export const spec = { {code: 'engageadx'}, {code: 'converge', gvlid: 248}, {code: 'adomega'}, - {code: 'denakop'} + {code: 'denakop'}, + {code: 'rtbanalytica'} ], supportedMediaTypes: [BANNER, VIDEO, NATIVE], From dc6f54dd0b5da11da76c3fa2a5cfe1e2d16f1b2d Mon Sep 17 00:00:00 2001 From: AdmixerTech <35560933+AdmixerTech@users.noreply.github.com> Date: Tue, 10 Aug 2021 11:01:42 +0300 Subject: [PATCH 05/19] add-adsyield-alias (#7282) Co-authored-by: atkachov --- modules/admixerBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/admixerBidAdapter.js b/modules/admixerBidAdapter.js index 1aecc85fe5a..5c01152200e 100644 --- a/modules/admixerBidAdapter.js +++ b/modules/admixerBidAdapter.js @@ -3,7 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'admixer'; -const ALIASES = ['go2net', 'adblender']; +const ALIASES = ['go2net', 'adblender', 'adsyield']; const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx'; export const spec = { code: BIDDER_CODE, From 6ab8791db1b09d1a7b56d80f0dcc8bb04c4cc7cb Mon Sep 17 00:00:00 2001 From: Krushmedia <71434282+Krushmedia@users.noreply.github.com> Date: Tue, 10 Aug 2021 14:04:21 +0300 Subject: [PATCH 06/19] Krushmedia Bid Adapter: updates for Prebid 5.0 (#7266) * inital * fix * fix * fix * fix * fix * fix * add maintener to md * Added native support * add syncing * updates for prebid 5 compliance Co-authored-by: Aiholkin --- modules/krushmediaBidAdapter.js | 158 +++++++++ .../spec/modules/krushmediaBidAdapter_spec.js | 334 ++++++++++++++++++ 2 files changed, 492 insertions(+) create mode 100644 modules/krushmediaBidAdapter.js create mode 100644 test/spec/modules/krushmediaBidAdapter_spec.js diff --git a/modules/krushmediaBidAdapter.js b/modules/krushmediaBidAdapter.js new file mode 100644 index 00000000000..db024230e2a --- /dev/null +++ b/modules/krushmediaBidAdapter.js @@ -0,0 +1,158 @@ +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; + +const BIDDER_CODE = 'krushmedia'; +const AD_URL = 'https://ads4.krushmedia.com/?c=rtb&m=hb'; +const SYNC_URL = 'https://cs.krushmedia.com/html?src=pbjs' + +function isBidResponseValid(bid) { + if (!bid.requestId || !bid.cpm || !bid.creativeId || + !bid.ttl || !bid.currency) { + return false; + } + switch (bid.mediaType) { + case BANNER: + return Boolean(bid.width && bid.height && bid.ad); + case VIDEO: + return Boolean(bid.vastUrl); + case NATIVE: + return Boolean(bid.native && bid.native.impressionTrackers); + default: + return false; + } +} + +function getBidFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); + } + + try { + const bidFloor = bid.getFloor({ + currency: 'USD', + mediaType: '*', + size: '*', + }); + return bidFloor.floor; + } catch (_) { + return 0 + } +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + isBidRequestValid: (bid) => { + return Boolean(bid.bidId && bid.params && !isNaN(parseInt(bid.params.key))); + }, + + buildRequests: (validBidRequests = [], bidderRequest) => { + let winTop = window; + let location; + try { + location = new URL(bidderRequest.refererInfo.referer) + winTop = window.top; + } catch (e) { + location = winTop.location; + utils.logMessage(e); + }; + + const placements = []; + const request = { + deviceWidth: winTop.screen.width, + deviceHeight: winTop.screen.height, + language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '', + secure: 1, + host: location.host, + page: location.pathname, + placements: placements + }; + + if (bidderRequest) { + if (bidderRequest.uspConsent) { + request.ccpa = bidderRequest.uspConsent; + } + if (bidderRequest.gdprConsent) { + request.gdpr = bidderRequest.gdprConsent + } + } + + const len = validBidRequests.length; + for (let i = 0; i < len; i++) { + const bid = validBidRequests[i]; + const placement = { + key: bid.params.key, + bidId: bid.bidId, + traffic: bid.params.traffic || BANNER, + schain: bid.schain || {}, + bidFloor: getBidFloor(bid) + }; + + if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { + placement.sizes = bid.mediaTypes[BANNER].sizes; + } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { + placement.wPlayer = bid.mediaTypes[VIDEO].playerSize[0]; + placement.hPlayer = bid.mediaTypes[VIDEO].playerSize[1]; + placement.minduration = bid.mediaTypes[VIDEO].minduration; + placement.maxduration = bid.mediaTypes[VIDEO].maxduration; + placement.mimes = bid.mediaTypes[VIDEO].mimes; + placement.protocols = bid.mediaTypes[VIDEO].protocols; + placement.startdelay = bid.mediaTypes[VIDEO].startdelay; + placement.placement = bid.mediaTypes[VIDEO].placement; + placement.skip = bid.mediaTypes[VIDEO].skip; + placement.skipafter = bid.mediaTypes[VIDEO].skipafter; + placement.minbitrate = bid.mediaTypes[VIDEO].minbitrate; + placement.maxbitrate = bid.mediaTypes[VIDEO].maxbitrate; + placement.delivery = bid.mediaTypes[VIDEO].delivery; + placement.playbackmethod = bid.mediaTypes[VIDEO].playbackmethod; + placement.api = bid.mediaTypes[VIDEO].api; + placement.linearity = bid.mediaTypes[VIDEO].linearity; + } else if (bid.mediaTypes && bid.mediaTypes[NATIVE]) { + placement.native = bid.mediaTypes[NATIVE]; + } + placements.push(placement); + } + + return { + method: 'POST', + url: AD_URL, + data: request + }; + }, + + interpretResponse: (serverResponse) => { + let response = []; + for (let i = 0; i < serverResponse.body.length; i++) { + let resItem = serverResponse.body[i]; + if (isBidResponseValid(resItem)) { + const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; + resItem.meta = { ...resItem.meta, advertiserDomains }; + + response.push(resItem); + } + } + return response; + }, + + getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { + let syncUrl = SYNC_URL + if (gdprConsent && gdprConsent.consentString) { + if (typeof gdprConsent.gdprApplies === 'boolean') { + syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; + } + } + if (uspConsent && uspConsent.consentString) { + syncUrl += `&ccpa_consent=${uspConsent.consentString}`; + } + return [{ + type: 'iframe', + url: syncUrl + }]; + } +}; + +registerBidder(spec); diff --git a/test/spec/modules/krushmediaBidAdapter_spec.js b/test/spec/modules/krushmediaBidAdapter_spec.js new file mode 100644 index 00000000000..fcdcc942290 --- /dev/null +++ b/test/spec/modules/krushmediaBidAdapter_spec.js @@ -0,0 +1,334 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/krushmediaBidAdapter.js'; +import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; + +describe('KrushmediabBidAdapter', function () { + const bid = { + bidId: '23fhj33i987f', + bidder: 'krushmedia', + mediaTypes: { + [BANNER]: { + sizes: [[300, 250]] + } + }, + params: { + key: 783, + traffic: BANNER + } + }; + + const bidderRequest = { + refererInfo: { + referer: 'test.com' + } + }; + + describe('isBidRequestValid', function () { + it('Should return true if there are bidId, params and key parameters present', function () { + expect(spec.isBidRequestValid(bid)).to.be.true; + }); + it('Should return false if at least one of parameters is not present', function () { + delete bid.params.key; + expect(spec.isBidRequestValid(bid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests([bid], bidderRequest); + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('https://ads4.krushmedia.com/?c=rtb&m=hb'); + }); + it('Returns valid data if array of bids is valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.language).to.be.a('string'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + expect(data.gdpr).to.not.exist; + expect(data.ccpa).to.not.exist; + let placement = data['placements'][0]; + expect(placement).to.have.keys('key', 'bidId', 'traffic', 'sizes', 'schain', 'bidFloor'); + expect(placement.key).to.equal(783); + expect(placement.bidId).to.equal('23fhj33i987f'); + expect(placement.traffic).to.equal(BANNER); + expect(placement.schain).to.be.an('object'); + expect(placement.sizes).to.be.an('array'); + }); + + it('Returns valid data for mediatype video', function () { + const playerSize = [300, 300]; + bid.mediaTypes = {}; + bid.params.traffic = VIDEO; + bid.mediaTypes[VIDEO] = { + playerSize + }; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('key', 'bidId', 'traffic', 'wPlayer', 'hPlayer', 'schain', 'bidFloor', + 'minduration', 'maxduration', 'mimes', 'protocols', 'startdelay', 'placement', 'skip', + 'skipafter', 'minbitrate', 'maxbitrate', 'delivery', 'playbackmethod', 'api', 'linearity'); + expect(placement.traffic).to.equal(VIDEO); + expect(placement.wPlayer).to.equal(playerSize[0]); + expect(placement.hPlayer).to.equal(playerSize[1]); + }); + + it('Returns valid data for mediatype native', function () { + const native = { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + }; + + bid.mediaTypes = {}; + bid.params.traffic = NATIVE; + bid.mediaTypes[NATIVE] = native; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data).to.be.an('object'); + let placement = data['placements'][0]; + expect(placement).to.be.an('object'); + expect(placement).to.have.keys('key', 'bidId', 'traffic', 'native', 'schain', 'bidFloor'); + expect(placement.traffic).to.equal(NATIVE); + expect(placement.native).to.equal(native); + }); + + it('Returns data with gdprConsent and without uspConsent', function () { + bidderRequest.gdprConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.gdpr).to.exist; + expect(data.gdpr).to.be.a('string'); + expect(data.gdpr).to.equal(bidderRequest.gdprConsent); + expect(data.ccpa).to.not.exist; + delete bidderRequest.gdprConsent; + }); + + it('Returns data with uspConsent and without gdprConsent', function () { + bidderRequest.uspConsent = 'test'; + serverRequest = spec.buildRequests([bid], bidderRequest); + let data = serverRequest.data; + expect(data.ccpa).to.exist; + expect(data.ccpa).to.be.a('string'); + expect(data.ccpa).to.equal(bidderRequest.uspConsent); + expect(data.gdpr).to.not.exist; + }); + + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([]); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + describe('interpretResponse', function () { + it('Should interpret banner response', function () { + const banner = { + body: [{ + mediaType: 'banner', + width: 300, + height: 250, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let bannerResponses = spec.interpretResponse(banner); + expect(bannerResponses).to.be.an('array').that.is.not.empty; + let dataItem = bannerResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.width).to.equal(300); + expect(dataItem.height).to.equal(250); + expect(dataItem.ad).to.equal('Test'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret video response', function () { + const video = { + body: [{ + vastUrl: 'test.com', + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let videoResponses = spec.interpretResponse(video); + expect(videoResponses).to.be.an('array').that.is.not.empty; + + let dataItem = videoResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.5); + expect(dataItem.vastUrl).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret native response', function () { + const native = { + body: [{ + mediaType: 'native', + native: { + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], + }, + ttl: 120, + cpm: 0.4, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let nativeResponses = spec.interpretResponse(native); + expect(nativeResponses).to.be.an('array').that.is.not.empty; + + let dataItem = nativeResponses[0]; + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); + expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.native.clickUrl).to.equal('test.com'); + expect(dataItem.native.title).to.equal('Test'); + expect(dataItem.native.image).to.equal('test.com'); + expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should return an empty array if invalid banner response is passed', function () { + const invBanner = { + body: [{ + width: 300, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + + let serverResponses = spec.interpretResponse(invBanner); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid video response is passed', function () { + const invVideo = { + body: [{ + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invVideo); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid native response is passed', function () { + const invNative = { + body: [{ + mediaType: 'native', + clickUrl: 'test.com', + title: 'Test', + impressionTrackers: ['test.com'], + ttl: 120, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let serverResponses = spec.interpretResponse(invNative); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid response is passed', function () { + const invalid = { + body: [{ + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invalid); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); + describe('getUserSyncs', function() { + it('Should return array of objects with proper sync config , include GDPR', function() { + const syncData = spec.getUserSyncs({}, {}, { + consentString: 'ALL', + gdprApplies: true, + }, {}); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('iframe') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://cs.krushmedia.com/html?src=pbjs&gdpr=1&gdpr_consent=ALL') + }); + it('Should return array of objects with proper sync config , include CCPA', function() { + const syncData = spec.getUserSyncs({}, {}, {}, { + consentString: '1NNN' + }); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('iframe') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://cs.krushmedia.com/html?src=pbjs&ccpa_consent=1NNN') + }); + }); +}); From 3f568a57dca96b7756f1f62bfee72cebd3cd47b9 Mon Sep 17 00:00:00 2001 From: Arne Schulz Date: Tue, 10 Aug 2021 13:29:47 +0200 Subject: [PATCH 07/19] [ORBIDDER] set gvlid to otto vendor id at orbidder adapter spec (#7276) --- modules/orbidderBidAdapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/orbidderBidAdapter.js b/modules/orbidderBidAdapter.js index 907efd3dba8..edd44385d52 100644 --- a/modules/orbidderBidAdapter.js +++ b/modules/orbidderBidAdapter.js @@ -38,6 +38,7 @@ function isBidResponseValid(bidResponse) { export const spec = { code: 'orbidder', + gvlid: 559, hostname: 'https://orbidder.otto.de', supportedMediaTypes: [BANNER, NATIVE], From 20d92436765b6caf7a6de54972abf821ae29450d Mon Sep 17 00:00:00 2001 From: contentexchange <87769951+contentexchange@users.noreply.github.com> Date: Tue, 10 Aug 2021 16:32:16 +0300 Subject: [PATCH 08/19] ContentExchange Bid Adapter: add new bid adapter (#7213) * add contentexchange bid adapter * fixes * fix * fix test * validate meta * fix --- modules/contentexchangeBidAdapter.js | 209 +++++++++ modules/contentexchangeBidAdapter.md | 83 ++++ .../modules/contentexchangeBidAdapter_spec.js | 399 ++++++++++++++++++ 3 files changed, 691 insertions(+) create mode 100644 modules/contentexchangeBidAdapter.js create mode 100644 modules/contentexchangeBidAdapter.md create mode 100644 test/spec/modules/contentexchangeBidAdapter_spec.js diff --git a/modules/contentexchangeBidAdapter.js b/modules/contentexchangeBidAdapter.js new file mode 100644 index 00000000000..de4cf8df933 --- /dev/null +++ b/modules/contentexchangeBidAdapter.js @@ -0,0 +1,209 @@ +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; +import {config} from '../src/config.js'; + +const BIDDER_CODE = 'contentexchange'; +const AD_URL = 'https://eu2.adnetwork.agency/pbjs'; +const SYNC_URL = 'https://sync2.adnetwork.agency'; + +function isBidResponseValid (bid) { + if (!bid.requestId || !bid.cpm || !bid.creativeId || + !bid.ttl || !bid.currency || !bid.meta) { + return false; + } + + switch (bid.mediaType) { + case BANNER: + return Boolean(bid.width && bid.height && bid.ad); + case VIDEO: + return Boolean(bid.vastUrl || bid.vastXml); + case NATIVE: + return Boolean(bid.native && bid.native.impressionTrackers && bid.native.impressionTrackers.length); + default: + return false; + } +} + +function getPlacementReqData (bid) { + const { params, bidId, mediaTypes } = bid; + const schain = bid.schain || {}; + const { placementId, adFormat } = params; + const bidfloor = getBidFloor(bid); + + const placement = { + placementId, + bidId, + adFormat, + schain, + bidfloor + }; + + switch (adFormat) { + case BANNER: + placement.sizes = mediaTypes[BANNER].sizes; + break; + case VIDEO: + placement.playerSize = mediaTypes[VIDEO].playerSize; + placement.minduration = mediaTypes[VIDEO].minduration; + placement.maxduration = mediaTypes[VIDEO].maxduration; + placement.mimes = mediaTypes[VIDEO].mimes; + placement.protocols = mediaTypes[VIDEO].protocols; + placement.startdelay = mediaTypes[VIDEO].startdelay; + placement.placement = mediaTypes[VIDEO].placement; + placement.skip = mediaTypes[VIDEO].skip; + placement.skipafter = mediaTypes[VIDEO].skipafter; + placement.minbitrate = mediaTypes[VIDEO].minbitrate; + placement.maxbitrate = mediaTypes[VIDEO].maxbitrate; + placement.delivery = mediaTypes[VIDEO].delivery; + placement.playbackmethod = mediaTypes[VIDEO].playbackmethod; + placement.api = mediaTypes[VIDEO].api; + placement.linearity = mediaTypes[VIDEO].linearity; + break; + case NATIVE: + placement.native = mediaTypes[NATIVE]; + break; + } + + return placement; +} + +function getBidFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); + } + + try { + const bidFloor = bid.getFloor({ + currency: 'USD', + mediaType: '*', + size: '*', + }); + return bidFloor.floor; + } catch (_) { + return 0 + } +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO, NATIVE], + + isBidRequestValid: (bid = {}) => { + const { params, bidId, mediaTypes } = bid; + let valid = Boolean(bidId && + params && + params.placementId && + params.adFormat + ); + switch (params.adFormat) { + case BANNER: + valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes); + break; + case VIDEO: + valid = valid && Boolean(mediaTypes[VIDEO] && mediaTypes[VIDEO].playerSize); + break; + case NATIVE: + valid = valid && Boolean(mediaTypes[NATIVE]); + break; + default: + valid = false; + } + return valid; + }, + + buildRequests: (validBidRequests = [], bidderRequest = {}) => { + let deviceWidth = 0; + let deviceHeight = 0; + + let winLocation; + try { + const winTop = window.top; + deviceWidth = winTop.screen.width; + deviceHeight = winTop.screen.height; + winLocation = winTop.location; + } catch (e) { + utils.logMessage(e); + winLocation = window.location; + } + + const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + let refferLocation; + try { + refferLocation = refferUrl && new URL(refferUrl); + } catch (e) { + utils.logMessage(e); + } + + let location = refferLocation || winLocation; + const language = (navigator && navigator.language) ? navigator.language.split('-')[0] : ''; + const host = location.host; + const page = location.pathname; + const secure = location.protocol === 'https:' ? 1 : 0; + const placements = []; + const request = { + deviceWidth, + deviceHeight, + language, + secure, + host, + page, + placements, + coppa: config.getConfig('coppa') === true ? 1 : 0, + ccpa: bidderRequest.uspConsent || undefined, + gdpr: bidderRequest.gdprConsent || undefined, + tmax: config.getConfig('bidderTimeout') + }; + + const len = validBidRequests.length; + for (let i = 0; i < len; i++) { + const bid = validBidRequests[i]; + placements.push(getPlacementReqData(bid)); + } + + return { + method: 'POST', + url: AD_URL, + data: request + }; + }, + + interpretResponse: (serverResponse) => { + let response = []; + for (let i = 0; i < serverResponse.body.length; i++) { + let resItem = serverResponse.body[i]; + if (isBidResponseValid(resItem)) { + const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; + resItem.meta = { ...resItem.meta, advertiserDomains }; + + response.push(resItem); + } + } + return response; + }, + + getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { + let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image'; + let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`; + if (gdprConsent && gdprConsent.consentString) { + if (typeof gdprConsent.gdprApplies === 'boolean') { + syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; + } + } + if (uspConsent && uspConsent.consentString) { + syncUrl += `&ccpa_consent=${uspConsent.consentString}`; + } + + const coppa = config.getConfig('coppa') ? 1 : 0; + syncUrl += `&coppa=${coppa}`; + + return [{ + type: syncType, + url: syncUrl + }]; + } +}; + +registerBidder(spec); diff --git a/modules/contentexchangeBidAdapter.md b/modules/contentexchangeBidAdapter.md new file mode 100644 index 00000000000..445d9c928bf --- /dev/null +++ b/modules/contentexchangeBidAdapter.md @@ -0,0 +1,83 @@ +# Overview + +``` +Module Name: Contentexchange Bidder Adapter +Module Type: Contentexchange Bidder Adapter +Maintainer: no-reply@vsn.si +``` + +# Description + +Connects to Contentexchange exchange for bids. + +Contentexchange bid adapter supports Banner, Video (instream and outstream) and Native. + +# Test Parameters +``` + var adUnits = [ + // Will return static test banner + { + code: 'adunit1', + mediaTypes: { + banner: { + sizes: [ [300, 250], [320, 50] ], + } + }, + bids: [ + { + bidder: 'contentexchange', + params: { + placementId: '0', + adFormat: 'banner' + } + } + ] + }, + { + code: 'addunit2', + mediaTypes: { + video: { + playerSize: [ [640, 480] ], + context: 'instream', + minduration: 5, + maxduration: 60, + } + }, + bids: [ + { + bidder: 'contentexchange', + params: { + placementId: '0', + adFormat: 'video' + } + } + ] + }, + { + code: 'addunit3', + mediaTypes: { + native: { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + } + }, + bids: [ + { + bidder: 'contentexchange', + params: { + placementId: '0', + adFormat: 'native' + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/test/spec/modules/contentexchangeBidAdapter_spec.js b/test/spec/modules/contentexchangeBidAdapter_spec.js new file mode 100644 index 00000000000..368ca8d9e3f --- /dev/null +++ b/test/spec/modules/contentexchangeBidAdapter_spec.js @@ -0,0 +1,399 @@ +import { expect } from 'chai'; +import { spec } from '../../../modules/contentexchangeBidAdapter.js'; +import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; +import { getUniqueIdentifierStr } from '../../../src/utils.js'; + +const bidder = 'contentexchange' + +describe('ContentexchangeBidAdapter', function () { + const bids = [ + { + bidId: getUniqueIdentifierStr(), + bidder: bidder, + mediaTypes: { + [BANNER]: { + sizes: [[300, 250]] + } + }, + params: { + placementId: 'test', + adFormat: BANNER + } + }, + { + bidId: getUniqueIdentifierStr(), + bidder: bidder, + mediaTypes: { + [VIDEO]: { + playerSize: [[300, 300]], + minduration: 5, + maxduration: 60 + } + }, + params: { + placementId: 'test', + adFormat: VIDEO + } + }, + { + bidId: getUniqueIdentifierStr(), + bidder: bidder, + mediaTypes: { + [NATIVE]: { + native: { + title: { + required: true + }, + body: { + required: true + }, + icon: { + required: true, + size: [64, 64] + } + } + } + }, + params: { + placementId: 'test', + adFormat: NATIVE + } + } + ]; + + const invalidBid = { + bidId: getUniqueIdentifierStr(), + bidder: bidder, + mediaTypes: { + [BANNER]: { + sizes: [[300, 250]] + } + }, + params: { + adFormat: BANNER + } + } + + const bidderRequest = { + uspConsent: '1---', + gdprConsent: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', + refererInfo: { + referer: 'https://test.com' + } + }; + + describe('isBidRequestValid', function () { + it('Should return true if there are bidId, params and key parameters present', function () { + expect(spec.isBidRequestValid(bids[0])).to.be.true; + }); + it('Should return false if at least one of parameters is not present', function () { + expect(spec.isBidRequestValid(invalidBid)).to.be.false; + }); + }); + + describe('buildRequests', function () { + let serverRequest = spec.buildRequests(bids, bidderRequest); + + it('Creates a ServerRequest object with method, URL and data', function () { + expect(serverRequest).to.exist; + expect(serverRequest.method).to.exist; + expect(serverRequest.url).to.exist; + expect(serverRequest.data).to.exist; + }); + + it('Returns POST method', function () { + expect(serverRequest.method).to.equal('POST'); + }); + + it('Returns valid URL', function () { + expect(serverRequest.url).to.equal('https://eu2.adnetwork.agency/pbjs'); + }); + + it('Returns general data valid', function () { + let data = serverRequest.data; + expect(data).to.be.an('object'); + expect(data).to.have.all.keys('deviceWidth', + 'deviceHeight', + 'language', + 'secure', + 'host', + 'page', + 'placements', + 'coppa', + 'ccpa', + 'gdpr', + 'tmax' + ); + expect(data.deviceWidth).to.be.a('number'); + expect(data.deviceHeight).to.be.a('number'); + expect(data.language).to.be.a('string'); + expect(data.secure).to.be.within(0, 1); + expect(data.host).to.be.a('string'); + expect(data.page).to.be.a('string'); + expect(data.coppa).to.be.a('number'); + expect(data.gdpr).to.be.a('string'); + expect(data.ccpa).to.be.a('string'); + expect(data.tmax).to.be.a('number'); + expect(data.placements).to.have.lengthOf(3); + }); + + it('Returns valid placements', function () { + const { placements } = serverRequest.data; + for (let i = 0, len = placements.length; i < len; i++) { + const placement = placements[i]; + expect(placement.placementId).to.be.equal('test'); + expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); + expect(placement.bidId).to.be.a('string'); + expect(placement.schain).to.be.an('object'); + expect(placement.bidfloor).to.exist.and.to.equal(0); + + if (placement.adFormat === BANNER) { + expect(placement.sizes).to.be.an('array'); + } + switch (placement.adFormat) { + case BANNER: + expect(placement.sizes).to.be.an('array'); + break; + case VIDEO: + expect(placement.playerSize).to.be.an('array'); + expect(placement.minduration).to.be.an('number'); + expect(placement.maxduration).to.be.an('number'); + break; + case NATIVE: + expect(placement.native).to.be.an('object'); + break; + } + } + }); + + it('Returns data with gdprConsent and without uspConsent', function () { + delete bidderRequest.uspConsent; + serverRequest = spec.buildRequests(bids, bidderRequest); + let data = serverRequest.data; + expect(data.gdpr).to.exist; + expect(data.gdpr).to.be.a('string'); + expect(data.gdpr).to.equal(bidderRequest.gdprConsent); + expect(data.ccpa).to.not.exist; + delete bidderRequest.gdprConsent; + }); + + it('Returns data with uspConsent and without gdprConsent', function () { + bidderRequest.uspConsent = '1---'; + delete bidderRequest.gdprConsent; + serverRequest = spec.buildRequests(bids, bidderRequest); + let data = serverRequest.data; + expect(data.ccpa).to.exist; + expect(data.ccpa).to.be.a('string'); + expect(data.ccpa).to.equal(bidderRequest.uspConsent); + expect(data.gdpr).to.not.exist; + }); + + it('Returns empty data if no valid requests are passed', function () { + serverRequest = spec.buildRequests([], bidderRequest); + let data = serverRequest.data; + expect(data.placements).to.be.an('array').that.is.empty; + }); + }); + + describe('interpretResponse', function () { + it('Should interpret banner response', function () { + const banner = { + body: [{ + mediaType: 'banner', + width: 300, + height: 250, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1', + meta: { + advertiserDomains: ['google.com'], + advertiserId: 1234 + } + }] + }; + let bannerResponses = spec.interpretResponse(banner); + expect(bannerResponses).to.be.an('array').that.is.not.empty; + let dataItem = bannerResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal(banner.body[0].requestId); + expect(dataItem.cpm).to.equal(banner.body[0].cpm); + expect(dataItem.width).to.equal(banner.body[0].width); + expect(dataItem.height).to.equal(banner.body[0].height); + expect(dataItem.ad).to.equal(banner.body[0].ad); + expect(dataItem.ttl).to.equal(banner.body[0].ttl); + expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal(banner.body[0].currency); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret video response', function () { + const video = { + body: [{ + vastUrl: 'test.com', + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1', + meta: { + advertiserDomains: ['google.com'], + advertiserId: 1234 + } + }] + }; + let videoResponses = spec.interpretResponse(video); + expect(videoResponses).to.be.an('array').that.is.not.empty; + + let dataItem = videoResponses[0]; + expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', + 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.5); + expect(dataItem.vastUrl).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should interpret native response', function () { + const native = { + body: [{ + mediaType: 'native', + native: { + clickUrl: 'test.com', + title: 'Test', + image: 'test.com', + impressionTrackers: ['test.com'], + }, + ttl: 120, + cpm: 0.4, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + meta: { + advertiserDomains: ['google.com'], + advertiserId: 1234 + } + }] + }; + let nativeResponses = spec.interpretResponse(native); + expect(nativeResponses).to.be.an('array').that.is.not.empty; + + let dataItem = nativeResponses[0]; + expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); + expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') + expect(dataItem.requestId).to.equal('23fhj33i987f'); + expect(dataItem.cpm).to.equal(0.4); + expect(dataItem.native.clickUrl).to.equal('test.com'); + expect(dataItem.native.title).to.equal('Test'); + expect(dataItem.native.image).to.equal('test.com'); + expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; + expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); + expect(dataItem.ttl).to.equal(120); + expect(dataItem.creativeId).to.equal('2'); + expect(dataItem.netRevenue).to.be.true; + expect(dataItem.currency).to.equal('USD'); + expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); + }); + it('Should return an empty array if invalid banner response is passed', function () { + const invBanner = { + body: [{ + width: 300, + cpm: 0.4, + ad: 'Test', + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + + let serverResponses = spec.interpretResponse(invBanner); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid video response is passed', function () { + const invVideo = { + body: [{ + mediaType: 'video', + cpm: 0.5, + requestId: '23fhj33i987f', + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invVideo); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid native response is passed', function () { + const invNative = { + body: [{ + mediaType: 'native', + clickUrl: 'test.com', + title: 'Test', + impressionTrackers: ['test.com'], + ttl: 120, + requestId: '23fhj33i987f', + creativeId: '2', + netRevenue: true, + currency: 'USD', + }] + }; + let serverResponses = spec.interpretResponse(invNative); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + it('Should return an empty array if invalid response is passed', function () { + const invalid = { + body: [{ + ttl: 120, + creativeId: '2', + netRevenue: true, + currency: 'USD', + dealId: '1' + }] + }; + let serverResponses = spec.interpretResponse(invalid); + expect(serverResponses).to.be.an('array').that.is.empty; + }); + }); + describe('getUserSyncs', function() { + it('Should return array of objects with proper sync config , include GDPR', function() { + const syncData = spec.getUserSyncs({}, {}, { + consentString: 'ALL', + gdprApplies: true, + }, {}); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('image') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://sync2.adnetwork.agency/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') + }); + it('Should return array of objects with proper sync config , include CCPA', function() { + const syncData = spec.getUserSyncs({}, {}, {}, { + consentString: '1---' + }); + expect(syncData).to.be.an('array').which.is.not.empty; + expect(syncData[0]).to.be.an('object') + expect(syncData[0].type).to.be.a('string') + expect(syncData[0].type).to.equal('image') + expect(syncData[0].url).to.be.a('string') + expect(syncData[0].url).to.equal('https://sync2.adnetwork.agency/image?pbjs=1&ccpa_consent=1---&coppa=0') + }); + }); +}); From ecd7845df73933bf157578eb417a2a8d30f6c8f0 Mon Sep 17 00:00:00 2001 From: jsut Date: Tue, 10 Aug 2021 10:16:50 -0400 Subject: [PATCH 09/19] bidViewablityIO Module: add new submodule for detecting viewability without ad server dependancies (#7151) * Add bidViewablityIO module - Emits a BID_VIEWABLE event for banner ads when a bid meets IAB viewable specifications, using the browsers IntersectionObserver API, if it is available - adds the new module, markdown documentation, an integration example, and tests * fix issues in integration example and tests * only register the event handler if the module is configured * fix config example in markdown * use getConfig's subscribe functionality * use indexOf instead of includes * wrap logMessage to prefix MODULE_NAME on messages --- .../postbid/bidViewabilityIO_example.html | 136 ++++++++++++++++ modules/bidViewabilityIO.js | 91 +++++++++++ modules/bidViewabilityIO.md | 41 +++++ test/spec/modules/bidViewabilityIO_spec.js | 145 ++++++++++++++++++ 4 files changed, 413 insertions(+) create mode 100644 integrationExamples/postbid/bidViewabilityIO_example.html create mode 100644 modules/bidViewabilityIO.js create mode 100644 modules/bidViewabilityIO.md create mode 100644 test/spec/modules/bidViewabilityIO_spec.js diff --git a/integrationExamples/postbid/bidViewabilityIO_example.html b/integrationExamples/postbid/bidViewabilityIO_example.html new file mode 100644 index 00000000000..2703013b29a --- /dev/null +++ b/integrationExamples/postbid/bidViewabilityIO_example.html @@ -0,0 +1,136 @@ + + + + + + + +
+ +
+ + + +
+ + + +
+ + + diff --git a/modules/bidViewabilityIO.js b/modules/bidViewabilityIO.js new file mode 100644 index 00000000000..4651e424d00 --- /dev/null +++ b/modules/bidViewabilityIO.js @@ -0,0 +1,91 @@ +import { config } from '../src/config.js'; +import * as events from '../src/events.js'; +import { EVENTS } from '../src/constants.json'; +import * as utils from '../src/utils.js'; + +const MODULE_NAME = 'bidViewabilityIO'; +const CONFIG_ENABLED = 'enabled'; + +// IAB numbers from: https://support.google.com/admanager/answer/4524488?hl=en +const IAB_VIEWABLE_DISPLAY_TIME = 1000; +const IAB_VIEWABLE_DISPLAY_LARGE_PX = 242000; +export const IAB_VIEWABLE_DISPLAY_THRESHOLD = 0.5 +export const IAB_VIEWABLE_DISPLAY_LARGE_THRESHOLD = 0.3; + +const CLIENT_SUPPORTS_IO = window.IntersectionObserver && window.IntersectionObserverEntry && window.IntersectionObserverEntry.prototype && + 'intersectionRatio' in window.IntersectionObserverEntry.prototype; + +const supportedMediaTypes = [ + 'banner' +]; + +export let isSupportedMediaType = (bid) => { + return supportedMediaTypes.indexOf(bid.mediaType) > -1; +} + +let logMessage = (message) => { + return utils.logMessage(`${MODULE_NAME}: ${message}`); +} + +// returns options for the iO that detects if the ad is viewable +export let getViewableOptions = (bid) => { + if (bid.mediaType === 'banner') { + return { + root: null, + rootMargin: '0px', + threshold: bid.width * bid.height > IAB_VIEWABLE_DISPLAY_LARGE_PX ? IAB_VIEWABLE_DISPLAY_LARGE_THRESHOLD : IAB_VIEWABLE_DISPLAY_THRESHOLD + } + } +} + +// markViewed returns a function what will be executed when an ad satisifes the viewable iO +export let markViewed = (bid, entry, observer) => { + return () => { + observer.unobserve(entry.target); + events.emit(EVENTS.BID_VIEWABLE, bid); + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); + } +} + +// viewCallbackFactory creates the callback used by the viewable IntersectionObserver. +// When an ad comes into view, it sets a timeout for a function to be executed +// when that ad would be considered viewed per the IAB specs. The bid that was rendered +// is passed into the factory, so it can pass it into markViewed, so that it can be included +// in the BID_VIEWABLE event data. If the ad leaves view before the timer goes off, the setTimeout +// is cancelled, an the bid will not be marked as viewed. There's probably some kind of race-ish +// thing going on between IO and setTimeout but this isn't going to be perfect, it's just going to +// be pretty good. +export let viewCallbackFactory = (bid) => { + return (entries, observer) => { + entries.forEach(entry => { + if (entry.isIntersecting) { + logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + entry.target.view_tracker = setTimeout(markViewed(bid, entry, observer), IAB_VIEWABLE_DISPLAY_TIME); + } else { + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); + if (entry.target.view_tracker) { + clearTimeout(entry.target.view_tracker); + logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + } + } + }); + }; +}; + +export let init = () => { + config.getConfig(MODULE_NAME, conf => { + if (conf[MODULE_NAME][CONFIG_ENABLED] && CLIENT_SUPPORTS_IO) { + // if the module is enabled and the browser supports Intersection Observer, + // then listen to AD_RENDER_SUCCEEDED to setup IO's for supported mediaTypes + events.on(EVENTS.AD_RENDER_SUCCEEDED, ({doc, bid, id}) => { + if (isSupportedMediaType(bid)) { + let viewable = new IntersectionObserver(viewCallbackFactory(bid), getViewableOptions(bid)); + let element = document.getElementById(bid.adUnitCode); + viewable.observe(element); + } + }); + } + }); +} + +init() diff --git a/modules/bidViewabilityIO.md b/modules/bidViewabilityIO.md new file mode 100644 index 00000000000..ad04cf38681 --- /dev/null +++ b/modules/bidViewabilityIO.md @@ -0,0 +1,41 @@ +# Overview + +Module Name: bidViewabilityIO + +Purpose: Emit a BID_VIEWABLE event when a bid becomes viewable using the browsers IntersectionObserver API + +Maintainer: adam.prime@alum.utoronto.ca + +# Description +- This module will trigger a BID_VIEWABLE event which other modules, adapters or publisher code can use to get a sense of viewability +- You can check if this module is part of the final build and whether it is enabled or not by accessing ```pbjs.getConfig('bidViewabilityIO')``` +- Viewability, as measured by this module is not perfect, nor should it be expected to be. +- The module does not require any specific ad server, or an adserver at all. + +# Limitations + +- Currently only supports the banner mediaType +- Assumes that the adUnitCode of the ad is also the id attribute of the element that the ad is rendered into. +- Does not make any attempt to ensure that the ad inside that element is itself visible. It assumes that the publisher is operating in good faith. + +# Params +- enabled [required] [type: boolean, default: false], when set to true, the module will emit BID_VIEWABLE when applicable + +# Example of consuming BID_VIEWABLE event +``` + pbjs.onEvent('bidViewable', function(bid){ + console.log('got bid details in bidViewable event', bid); + }); + +``` + +# Example of using config +``` + pbjs.setConfig({ + bidViewabilityIO: { + enabled: true, + } + }); +``` + +An example implmentation without an ad server can be found in integrationExamples/postbid/bidViewabilityIO_example.html diff --git a/test/spec/modules/bidViewabilityIO_spec.js b/test/spec/modules/bidViewabilityIO_spec.js new file mode 100644 index 00000000000..b59dbc867c1 --- /dev/null +++ b/test/spec/modules/bidViewabilityIO_spec.js @@ -0,0 +1,145 @@ +import * as bidViewabilityIO from 'modules/bidViewabilityIO.js'; +import * as events from 'src/events.js'; +import * as utils from 'src/utils.js'; +import * as sinon from 'sinon'; +import { expect } from 'chai'; +import { EVENTS } from 'src/constants.json'; + +describe('#bidViewabilityIO', function() { + const makeElement = (id) => { + const el = document.createElement('div'); + el.setAttribute('id', id); + return el; + } + const banner_bid = { + adUnitCode: 'banner_id', + mediaType: 'banner', + width: 728, + height: 90 + }; + + const large_banner_bid = { + adUnitCode: 'large_banner_id', + mediaType: 'banner', + width: 970, + height: 250 + }; + + const video_bid = { + mediaType: 'video', + }; + + const native_bid = { + mediaType: 'native', + }; + + it('init to be a function', function() { + expect(bidViewabilityIO.init).to.be.a('function') + }); + + describe('isSupportedMediaType tests', function() { + it('banner to be supported', function() { + expect(bidViewabilityIO.isSupportedMediaType(banner_bid)).to.be.true + }); + + it('video not to be supported', function() { + expect(bidViewabilityIO.isSupportedMediaType(video_bid)).to.be.false + }); + + it('native not to be supported', function() { + expect(bidViewabilityIO.isSupportedMediaType(native_bid)).to.be.false + }); + }) + + describe('getViewableOptions tests', function() { + it('normal banner has expected threshold in options object', function() { + expect(bidViewabilityIO.getViewableOptions(banner_bid).threshold).to.equal(bidViewabilityIO.IAB_VIEWABLE_DISPLAY_THRESHOLD); + }); + + it('large banner has expected threshold in options object', function() { + expect(bidViewabilityIO.getViewableOptions(large_banner_bid).threshold).to.equal(bidViewabilityIO.IAB_VIEWABLE_DISPLAY_LARGE_THRESHOLD) + }); + + it('video bid has undefined viewable options', function() { + expect(bidViewabilityIO.getViewableOptions(video_bid)).to.be.undefined + }); + + it('native bid has undefined viewable options', function() { + expect(bidViewabilityIO.getViewableOptions(native_bid)).to.be.undefined + }); + }) + + describe('markViewed tests', function() { + let sandbox; + const mockObserver = { + unobserve: sinon.spy() + }; + const mockEntry = { + target: makeElement('target_id') + }; + + beforeEach(function() { + sandbox = sinon.sandbox.create(); + }) + + afterEach(function() { + sandbox.restore() + }) + + it('markViewed returns a function', function() { + expect(bidViewabilityIO.markViewed(banner_bid, mockEntry, mockObserver)).to.be.a('function') + }); + + it('markViewed unobserves', function() { + const emitSpy = sandbox.spy(events, ['emit']); + const func = bidViewabilityIO.markViewed(banner_bid, mockEntry, mockObserver); + func(); + expect(mockObserver.unobserve.calledOnce).to.be.true; + expect(emitSpy.calledOnce).to.be.true; + // expect(emitSpy.firstCall.args).to.be.false; + expect(emitSpy.firstCall.args[0]).to.eq(EVENTS.BID_VIEWABLE); + }); + }) + + describe('viewCallbackFactory tests', function() { + let sandbox; + + beforeEach(function() { + sandbox = sinon.sandbox.create(); + }) + + afterEach(function() { + sandbox.restore() + }) + + it('viewCallbackFactory returns a function', function() { + expect(bidViewabilityIO.viewCallbackFactory(banner_bid)).to.be.a('function') + }); + + it('viewCallbackFactory function does stuff', function() { + const logMessageSpy = sandbox.spy(utils, ['logMessage']); + const mockObserver = { + unobserve: sandbox.spy() + }; + const mockEntries = [{ + isIntersecting: true, + target: makeElement('true_id') + }, + { + isIntersecting: false, + target: makeElement('false_id') + }, + { + isIntersecting: false, + target: makeElement('false_id') + }]; + mockEntries[2].target.view_tracker = 8; + + const func = bidViewabilityIO.viewCallbackFactory(banner_bid); + func(mockEntries, mockObserver); + expect(mockEntries[0].target.view_tracker).to.be.a('number'); + expect(mockEntries[1].target.view_tracker).to.be.undefined; + expect(logMessageSpy.lastCall.lastArg).to.eq('bidViewabilityIO: viewable timer stopped for id: false_id code: banner_id'); + }); + }) +}); From e679fe75480a06082606f443ea1954ee657d7aab Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Tue, 10 Aug 2021 07:30:00 -0700 Subject: [PATCH 10/19] Between Bid Adapter: add sharedid for Prebid 5.0 (#7222) * Add back in sharedid #7221 * fix linting * add tests for sharedid * remove trailing spaces --- modules/betweenBidAdapter.js | 13 +++++- test/spec/modules/betweenBidAdapter_spec.js | 47 +++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/modules/betweenBidAdapter.js b/modules/betweenBidAdapter.js index feb6cae437a..5a351def958 100644 --- a/modules/betweenBidAdapter.js +++ b/modules/betweenBidAdapter.js @@ -1,5 +1,5 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { getAdUnitSizes, parseSizesInput } from '../src/utils.js'; +import { getAdUnitSizes, parseSizesInput, deepAccess } from '../src/utils.js'; import { getRefererInfo } from '../src/refererDetection.js'; const BIDDER_CODE = 'between'; @@ -37,6 +37,8 @@ export const spec = { tz: getTz(), fl: getFl(), rr: getRr(), + shid: getSharedId(i)('id'), + shid3: getSharedId(i)('third'), s: i.params.s, bidid: i.bidId, transactionid: i.transactionId, @@ -147,6 +149,15 @@ export const spec = { } } +function getSharedId(bid) { + const id = deepAccess(bid, 'userId.sharedid.id'); + const third = deepAccess(bid, 'userId.sharedid.third'); + return function(kind) { + if (kind === 'id') return id || ''; + return third || ''; + } +} + function getRr() { try { var td = top.document; diff --git a/test/spec/modules/betweenBidAdapter_spec.js b/test/spec/modules/betweenBidAdapter_spec.js index 62f36182d55..44d0752d4b2 100644 --- a/test/spec/modules/betweenBidAdapter_spec.js +++ b/test/spec/modules/betweenBidAdapter_spec.js @@ -222,6 +222,53 @@ describe('betweenBidAdapterTests', function () { expect(req_data.sizes).to.deep.equal(['970x250', '240x400', '728x90']) }); + it('check sharedId with id and third', function() { + const bidRequestData = [{ + bidId: 'bid123', + bidder: 'between', + mediaTypes: { + banner: { + sizes: [[728, 90]] + } + }, + params: { + s: 1112, + }, + userId: { + sharedid: { + id: '01EXQE7JKNDRDDVATB0S2GX1NT', + third: '01EXQE7JKNDRDDVATB0S2GX1NT' + } + } + }]; + const shid = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid; + const shid3 = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid3; + expect(shid).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT') && expect(shid3).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT'); + }); + + it('check sharedId with only id', function() { + const bidRequestData = [{ + bidId: 'bid123', + bidder: 'between', + mediaTypes: { + banner: { + sizes: [[728, 90]] + } + }, + params: { + s: 1112, + }, + userId: { + sharedid: { + id: '01EXQE7JKNDRDDVATB0S2GX1NT', + } + } + }]; + const shid = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid; + const shid3 = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid3; + expect(shid).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT') && expect(shid3).to.equal(''); + }); + it('check adomain', function() { const serverResponse = { body: [{ From 11df18dff4bf10f05ed01da62f214ce13690a2d2 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Tue, 10 Aug 2021 11:20:06 -0700 Subject: [PATCH 11/19] PubMatic: if multi-format ad-unit does not have outstreamAU or renderer (for out-stream) then continue w/o video (#7275) * Bug fix to still bid banner and/or native when no outstream renderer is available --- modules/pubmaticBidAdapter.js | 15 +++- test/spec/modules/pubmaticBidAdapter_spec.js | 83 ++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index df22f8713cd..f6e6e67444a 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -975,8 +975,19 @@ export const spec = { !utils.isStr(bid.params.outstreamAU) && !bid.hasOwnProperty('renderer') && !bid.mediaTypes[VIDEO].hasOwnProperty('renderer')) { - utils.logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid); - return false; + // we are here since outstream ad-unit is provided without outstreamAU and renderer + // so it is not a valid video ad-unit + // but it may be valid banner or native ad-unit + // so if mediaType banner or Native is present then we will remove media-type video and return true + + if (bid.mediaTypes.hasOwnProperty(BANNER) || bid.mediaTypes.hasOwnProperty(NATIVE)) { + delete bid.mediaTypes[VIDEO]; + utils.logWarn(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting mediatype Video of bid: `, bid); + return true; + } else { + utils.logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid); + return false; + } } } return true; diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index d22acabd4cf..23c5f01e520 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -930,6 +930,89 @@ describe('PubMatic adapter', function () { delete bid.params.video.mimes; // Undefined expect(spec.isBidRequestValid(bid)).to.equal(false); }); + + it('checks on bid.params.outstreamAU & bid.renderer & bid.mediaTypes.video.renderer', function() { + const getThebid = function() { + let bid = utils.deepClone(validOutstreamBidRequest.bids[0]); + bid.params.outstreamAU = 'pubmatic-test'; + bid.renderer = ' '; // we are only checking if this key is set or not + bid.mediaTypes.video.renderer = ' '; // we are only checking if this key is set or not + return bid; + } + + // true: when all are present + // mdiatype: outstream + // bid.params.outstreamAU : Y + // bid.renderer : Y + // bid.mediaTypes.video.renderer : Y + let bid = getThebid(); + expect(spec.isBidRequestValid(bid)).to.equal(true); + + // true: atleast one is present; 3 cases + // mdiatype: outstream + // bid.params.outstreamAU : Y + // bid.renderer : N + // bid.mediaTypes.video.renderer : N + bid = getThebid(); + delete bid.renderer; + delete bid.mediaTypes.video.renderer; + expect(spec.isBidRequestValid(bid)).to.equal(true); + + // true: atleast one is present; 3 cases + // mdiatype: outstream + // bid.params.outstreamAU : N + // bid.renderer : Y + // bid.mediaTypes.video.renderer : N + bid = getThebid(); + delete bid.params.outstreamAU; + delete bid.mediaTypes.video.renderer; + expect(spec.isBidRequestValid(bid)).to.equal(true); + + // true: atleast one is present; 3 cases + // mdiatype: outstream + // bid.params.outstreamAU : N + // bid.renderer : N + // bid.mediaTypes.video.renderer : Y + bid = getThebid(); + delete bid.params.outstreamAU; + delete bid.renderer; + expect(spec.isBidRequestValid(bid)).to.equal(true); + + // false: none present; only outstream + // mdiatype: outstream + // bid.params.outstreamAU : N + // bid.renderer : N + // bid.mediaTypes.video.renderer : N + bid = getThebid(); + delete bid.params.outstreamAU; + delete bid.renderer; + delete bid.mediaTypes.video.renderer; + expect(spec.isBidRequestValid(bid)).to.equal(false); + + // true: none present; outstream + Banner + // mdiatype: outstream, banner + // bid.params.outstreamAU : N + // bid.renderer : N + // bid.mediaTypes.video.renderer : N + bid = getThebid(); + delete bid.params.outstreamAU; + delete bid.renderer; + delete bid.mediaTypes.video.renderer; + bid.mediaTypes.banner = {sizes: [ [300, 250], [300, 600] ]}; + expect(spec.isBidRequestValid(bid)).to.equal(true); + + // true: none present; outstream + Native + // mdiatype: outstream, native + // bid.params.outstreamAU : N + // bid.renderer : N + // bid.mediaTypes.video.renderer : N + bid = getThebid(); + delete bid.params.outstreamAU; + delete bid.renderer; + delete bid.mediaTypes.video.renderer; + bid.mediaTypes.native = {} + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); }); describe('Request formation', function () { From 6df0219586416e9a1aa2c959addabb0528536ff3 Mon Sep 17 00:00:00 2001 From: IOTiagoFaria <76956619+IOTiagoFaria@users.noreply.github.com> Date: Wed, 11 Aug 2021 15:41:46 +0100 Subject: [PATCH 12/19] InteractiveOffers : parameters changed & dynamic endpoint (#7286) * InteractiveOffers BidAdapter: New endpoint * InteractiveOffers - Parameters changed & dynamic endpoint * InteractiveOffers - Fix lint errors * InteractiveOffers - Change the spec file * InteractiveOffers - Fix spec file Co-authored-by: EC2 Default User --- modules/interactiveOffersBidAdapter.js | 68 ++++++++++++------- modules/interactiveOffersBidAdapter.md | 4 +- .../interactiveOffersBidAdapter_spec.js | 12 ++-- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/modules/interactiveOffersBidAdapter.js b/modules/interactiveOffersBidAdapter.js index 66949be8a52..958c671e4b9 100644 --- a/modules/interactiveOffersBidAdapter.js +++ b/modules/interactiveOffersBidAdapter.js @@ -4,7 +4,7 @@ import {config} from '../src/config.js'; import * as utils from '../src/utils.js'; const BIDDER_CODE = 'interactiveOffers'; -const ENDPOINT = 'https://prebid.ioadx.com/bidRequest/?partnerId=4a3bab187a74ac4862920cca864d6eff195ff5e4'; +const ENDPOINT = 'https://prebid.ioadx.com/bidRequest/?partnerId='; const DEFAULT = { 'OpenRTBBidRequest': {}, @@ -35,8 +35,8 @@ export const spec = { isBidRequestValid: function(bid) { let ret = true; if (bid && bid.params) { - if (!utils.isNumber(bid.params.pubid)) { - utils.logWarn('pubid must be a valid numeric ID'); + if (!bid.params.partnerId) { + utils.logWarn('partnerId must be a valid ID'); ret = false; } if (bid.params.tmax && !utils.isNumber(bid.params.tmax)) { @@ -50,10 +50,11 @@ export const spec = { return ret; }, buildRequests: function(validBidRequests, bidderRequest) { - let payload = parseRequestPrebidjsToOpenRTB(bidderRequest); + let aux = parseRequestPrebidjsToOpenRTB(bidderRequest); + let payload = aux.payload; return { method: 'POST', - url: ENDPOINT, + url: ENDPOINT + aux.partnerId, data: JSON.stringify(payload), bidderRequest: bidderRequest }; @@ -61,7 +62,10 @@ export const spec = { interpretResponse: function(response, request) { let bidResponses = []; - if (response.body && response.body.length) { + if (response.body) { + if (!response.body.length) { + response.body = [response.body]; + } bidResponses = parseResponseOpenRTBToPrebidjs(response.body); } return bidResponses; @@ -69,6 +73,10 @@ export const spec = { }; function parseRequestPrebidjsToOpenRTB(prebidRequest) { + let ret = { + payload: {}, + partnerId: null + }; let pageURL = window.location.href; let domain = window.location.hostname; let secure = (window.location.protocol == 'https:' ? 1 : 0); @@ -105,12 +113,15 @@ function parseRequestPrebidjsToOpenRTB(prebidRequest) { openRTBRequest.imp = []; prebidRequest.bids.forEach(function(bid, impId) { impId++; + if (!ret.partnerId) { + ret.partnerId = bid.params.partnerId; + } let imp = JSON.parse(JSON.stringify(DEFAULT['OpenRTBBidRequestImp'])); imp.id = impId; imp.secure = secure; imp.tagid = bid.bidId; - openRTBRequest.site.publisher.id = openRTBRequest.site.publisher.id || bid.params.pubid; + openRTBRequest.site.publisher.id = openRTBRequest.site.publisher.id || 0; openRTBRequest.tmax = openRTBRequest.tmax || bid.params.tmax || 0; Object.keys(bid.mediaTypes).forEach(function(mediaType) { @@ -130,31 +141,36 @@ function parseRequestPrebidjsToOpenRTB(prebidRequest) { }); openRTBRequest.imp.push(imp); }); - return openRTBRequest; + ret.payload = openRTBRequest; + return ret; } function parseResponseOpenRTBToPrebidjs(openRTBResponse) { let prebidResponse = []; openRTBResponse.forEach(function(response) { - response.seatbid.forEach(function(seatbid) { - seatbid.bid.forEach(function(bid) { - let prebid = JSON.parse(JSON.stringify(DEFAULT['PrebidBid'])); - prebid.requestId = bid.ext.tagid; - prebid.ad = bid.adm; - prebid.creativeId = bid.crid; - prebid.cpm = bid.price; - prebid.width = bid.w; - prebid.height = bid.h; - prebid.mediaType = 'banner'; - prebid.meta = { - advertiserDomains: bid.adomain, - advertiserId: bid.adid, - mediaType: 'banner', - primaryCatId: bid.cat[0] || '', - secondaryCatIds: bid.cat + if (response.seatbid && response.seatbid.forEach) { + response.seatbid.forEach(function(seatbid) { + if (seatbid.bid && seatbid.bid.forEach) { + seatbid.bid.forEach(function(bid) { + let prebid = JSON.parse(JSON.stringify(DEFAULT['PrebidBid'])); + prebid.requestId = bid.ext.tagid; + prebid.ad = bid.adm; + prebid.creativeId = bid.crid; + prebid.cpm = bid.price; + prebid.width = bid.w; + prebid.height = bid.h; + prebid.mediaType = 'banner'; + prebid.meta = { + advertiserDomains: bid.adomain, + advertiserId: bid.adid, + mediaType: 'banner', + primaryCatId: bid.cat[0] || '', + secondaryCatIds: bid.cat + } + prebidResponse.push(prebid); + }); } - prebidResponse.push(prebid); }); - }); + } }); return prebidResponse; } diff --git a/modules/interactiveOffersBidAdapter.md b/modules/interactiveOffersBidAdapter.md index 581b2e49a68..b96572fbf94 100644 --- a/modules/interactiveOffersBidAdapter.md +++ b/modules/interactiveOffersBidAdapter.md @@ -8,7 +8,7 @@ Maintainer: dev@interactiveoffers.com # Description -Module that connects to interactiveOffers demand sources. Param pubid is required. +Module that connects to interactiveOffers demand sources. Param partnerId is required. # Test Parameters ``` @@ -24,7 +24,7 @@ Module that connects to interactiveOffers demand sources. Param pubid is require { bidder: "interactiveOffers", params: { - pubid: 10, + partnerId: "abcd1234", tmax: 250 } } diff --git a/test/spec/modules/interactiveOffersBidAdapter_spec.js b/test/spec/modules/interactiveOffersBidAdapter_spec.js index 2ea620dc30c..ff9ca123def 100644 --- a/test/spec/modules/interactiveOffersBidAdapter_spec.js +++ b/test/spec/modules/interactiveOffersBidAdapter_spec.js @@ -3,7 +3,7 @@ import {spec} from 'modules/interactiveOffersBidAdapter.js'; describe('Interactive Offers Prebbid.js Adapter', function() { describe('isBidRequestValid function', function() { - let bid = {bidder: 'interactiveOffers', params: {pubid: 100, tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}; + let bid = {bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}; it('returns true if all the required params are present and properly formatted', function() { expect(spec.isBidRequestValid(bid)).to.be.true; @@ -15,15 +15,15 @@ describe('Interactive Offers Prebbid.js Adapter', function() { }); it('returns false if any if the required params is not properly formatted', function() { - bid.params = {pubid: 'abcd123', tmax: 250}; + bid.params = {partnerid: '100', tmax: 250}; expect(spec.isBidRequestValid(bid)).to.be.false; - bid.params = {pubid: 100, tmax: '+250'}; + bid.params = {partnerId: '100', tmax: '+250'}; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); describe('buildRequests function', function() { - let validBidRequests = [{bidder: 'interactiveOffers', params: {pubid: 100, tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}]; - let bidderRequest = {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {pubid: 100, tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://www.google.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://www.google.com'], canonicalUrl: null}}; + let validBidRequests = [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}]; + let bidderRequest = {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://www.google.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://www.google.com'], canonicalUrl: null}}; it('returns a Prebid.js request object with a valid json string at the "data" property', function() { let request = spec.buildRequests(validBidRequests, bidderRequest); @@ -32,7 +32,7 @@ describe('Interactive Offers Prebbid.js Adapter', function() { }); describe('interpretResponse function', function() { let openRTBResponse = {body: [{cur: 'USD', id: '2052afa35febb79baa9893cc3ae8b83b89740df65fe98b1bd358dbae6e912801', seatbid: [{seat: 1493, bid: [{ext: {tagid: '227faa83f86546'}, crid: '24477', adm: '', nurl: '', adid: '1138', adomain: ['url.com'], price: '1.53', w: 300, h: 250, iurl: 'http://url.com', cat: ['IAB13-11'], id: '5507ced7a39c06942d3cb260197112ba712e4180', attr: [], impid: 1, cid: '13280'}]}], 'bidid': '0959b9d58ba71b3db3fa29dce3b117c01fc85de0'}], 'headers': {}}; - let prebidRequest = {method: 'POST', url: 'https://url.com', data: '{"id": "1aad860c-e04b-482b-acac-0da55ed491c8", "site": {"id": "url.com", "name": "url.com", "domain": "url.com", "page": "http://url.com", "ref": "http://url.com", "publisher": {"id": 100, "name": "http://url.com", "domain": "url.com"}, "content": {"language": "pt-PT"}}, "source": {"fd": 0, "tid": "1aad860c-e04b-482b-acac-0da55ed491c8", "pchain": ""}, "device": {"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36", "language": "pt-PT"}, "user": {}, "imp": [{"id":1, "secure": 0, "tagid": "227faa83f86546", "banner": {"pos": 0, "w": 300, "h": 250, "format": [{"w": 300, "h": 250}]}}], "tmax": 300}', bidderRequest: {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {pubid: 100, tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://url.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://url.com'], canonicalUrl: null}}}; + let prebidRequest = {method: 'POST', url: 'https://url.com', data: '{"id": "1aad860c-e04b-482b-acac-0da55ed491c8", "site": {"id": "url.com", "name": "url.com", "domain": "url.com", "page": "http://url.com", "ref": "http://url.com", "publisher": {"id": 100, "name": "http://url.com", "domain": "url.com"}, "content": {"language": "pt-PT"}}, "source": {"fd": 0, "tid": "1aad860c-e04b-482b-acac-0da55ed491c8", "pchain": ""}, "device": {"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36", "language": "pt-PT"}, "user": {}, "imp": [{"id":1, "secure": 0, "tagid": "227faa83f86546", "banner": {"pos": 0, "w": 300, "h": 250, "format": [{"w": 300, "h": 250}]}}], "tmax": 300}', bidderRequest: {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://url.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://url.com'], canonicalUrl: null}}}; it('returns an array of Prebid.js response objects', function() { let prebidResponses = spec.interpretResponse(openRTBResponse, prebidRequest); From 17aa2646d00e04bed38dae595dca124f9c341fe6 Mon Sep 17 00:00:00 2001 From: MK Platform <88486298+mediakeys-platform@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:27:49 +0200 Subject: [PATCH 13/19] Mediakeys: add bidder adapter (#7268) * Mediakeys: add bidder adapter * Removed superfluous argument Co-authored-by: Jean-Paul COSAL --- modules/mediakeysBidAdapter.js | 380 +++++++++++++ modules/mediakeysBidAdapter.md | 31 + test/spec/modules/mediakeysBidAdapter_spec.js | 538 ++++++++++++++++++ 3 files changed, 949 insertions(+) create mode 100644 modules/mediakeysBidAdapter.js create mode 100644 modules/mediakeysBidAdapter.md create mode 100644 test/spec/modules/mediakeysBidAdapter_spec.js diff --git a/modules/mediakeysBidAdapter.js b/modules/mediakeysBidAdapter.js new file mode 100644 index 00000000000..539d2f6c9cf --- /dev/null +++ b/modules/mediakeysBidAdapter.js @@ -0,0 +1,380 @@ +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { config } from '../src/config.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; +import { createEidsArray } from './userId/eids.js'; + +const AUCTION_TYPE = 1; +const BIDDER_CODE = 'mediakeys'; +const ENDPOINT = 'https://prebid.eu-central-1.bidder.mediakeys.io/bids'; +const GVLID = 498; +const SUPPORTED_MEDIA_TYPES = [BANNER]; +const DEFAULT_CURRENCY = 'USD'; +const NET_REVENUE = true; + +/** + * Detects the capability to reach window.top. + * + * @returns {boolean} + */ +function canAccessTopWindow() { + try { + return !!utils.getWindowTop().location.href; + } catch (error) { + return false; + } +} + +/** + * Returns the OpenRtb deviceType id detected from User Agent + * Voluntary limited to phone, tablet, desktop. + * + * @returns {number} + */ +function getDeviceType() { + if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()))) { + return 5; + } + if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(navigator.userAgent.toLowerCase()))) { + return 4; + } + return 2; +} + +/** + * Returns the OS name detected from User Agent. + * + * @returns {number} + */ +function getOS() { + if (navigator.userAgent.indexOf('Android') != -1) return 'Android'; + if (navigator.userAgent.indexOf('like Mac') != -1) return 'iOS'; + if (navigator.userAgent.indexOf('Win') != -1) return 'Windows'; + if (navigator.userAgent.indexOf('Mac') != -1) return 'Macintosh'; + if (navigator.userAgent.indexOf('Linux') != -1) return 'Linux'; + if (navigator.appVersion.indexOf('X11') != -1) return 'Unix'; + return 'Others'; +} + +/** + * Returns floor from priceFloors module or MediaKey default value. + * + * @param {*} bid a Prebid.js bid (request) object + * @param {string} mediaType the mediaType or the wildcard '*' + * @param {string|array} size the size array or the wildcard '*' + * @returns {number|boolean} + */ +function getFloor(bid, mediaType, size = '*') { + if (!utils.isFn(bid.getFloor)) { + return false; + } + + if (SUPPORTED_MEDIA_TYPES.indexOf(mediaType) === -1) { + utils.logWarn(`${BIDDER_CODE}: Unable to detect floor price for unsupported mediaType ${mediaType}. No floor will be used.`); + return false; + } + + const floor = bid.getFloor({ + currency: DEFAULT_CURRENCY, + mediaType, + size + }) + + return (!isNaN(floor.floor) && floor.currency === DEFAULT_CURRENCY) ? floor.floor : false +} + +/** + * Returns an openRTB 2.5 object. + * This one will be populated at each step of the buildRequest process. + * + * @returns {object} + */ +function createOrtbTemplate() { + return { + id: '', + at: AUCTION_TYPE, + cur: [DEFAULT_CURRENCY], + imp: [], + site: {}, // computed in buildRequest() + device: { + ip: '', + js: 1, + dnt: utils.getDNT(), + ua: navigator.userAgent, + devicetype: getDeviceType(), + os: getOS(), + h: screen.height, + w: screen.width, + language: navigator.language, + make: navigator.vendor ? navigator.vendor : '' + }, + user: {}, + regs: { + ext: { + gdpr: 0 // not applied by default + } + }, + ext: { + is_secure: 1 + } + }; +} + +/** + * Returns an openRtb 2.5 banner object. + * + * @param {object} bid Prebid bid object from request + * @returns {object} + */ +function createBannerImp(bid) { + let sizes = bid.mediaTypes.banner.sizes; + const params = utils.deepAccess(bid, 'params', {}); + + if (!utils.isArray(sizes) || !sizes.length) { + utils.logWarn(`${BIDDER_CODE}: mediaTypes.banner.size missing for adunit: ${bid.params.adUnit}. Ignoring the banner impression in the adunit.`); + } else { + const banner = {}; + + banner.w = parseInt(sizes[0][0], 10); + banner.h = parseInt(sizes[0][1], 10); + + const format = []; + sizes.forEach(function (size) { + if (size.length && size.length > 1) { + format.push({w: size[0], h: size[1]}); + } + }); + banner.format = format; + + banner.topframe = utils.inIframe() ? 0 : 1; + banner.pos = params.pos || 0; + + return banner; + } +} + +/** + * Create the OpenRTB 2.5 imp object. + * + * @param {*} bid Prebid bid object from request + * @returns + */ +function createImp(bid) { + const imp = { + id: bid.bidId, + tagid: bid.params.adUnit || undefined, + bidfloorcur: DEFAULT_CURRENCY, + secure: 1, + }; + + // Only supports proper mediaTypes definition… + for (let mediaType in bid.mediaTypes) { + // There is no default floor. bidfloor is set only + // if the priceFloors module is activated and returns a valid floor. + const floor = getFloor(bid, mediaType); + if (floor) { + imp.bidfloor = floor; + } + + if (mediaType === BANNER) { + const banner = createBannerImp(bid); + if (banner) { + imp.banner = banner; + } + } + } + + // handle FPD for imp. + const ortb2Imp = utils.deepAccess(bid, 'ortb2Imp.ext.data'); + if (ortb2Imp) { + const fpd = { ...bid.ortb2Imp }; + utils.mergeDeep(imp, fpd); + } + + return imp; +} + +/** + * If array, extract the first IAB category from provided list + * If string just return it + * + * @param {string|Array} cat IAB Category + * @returns {string|null} + */ +function getPrimaryCatFromResponse(cat) { + if (!cat || (utils.isArray(cat) && !cat.length)) { + return; + } + + if (utils.isArray(cat)) { + return cat[0]; + } else if (utils.isStr(cat)) { + return cat; + } +} + +export const spec = { + code: BIDDER_CODE, + + gvlid: GVLID, + + supportedMediaTypes: SUPPORTED_MEDIA_TYPES, + + isBidRequestValid: function(bid) { + return !!(bid && !utils.isEmpty(bid)); + }, + + buildRequests: function(validBidRequests, bidderRequest) { + const payload = createOrtbTemplate(); + + // Pass the auctionId as ortb2 id + // See https://github.com/prebid/Prebid.js/issues/6563 + utils.deepSetValue(payload, 'id', bidderRequest.auctionId); + utils.deepSetValue(payload, 'source.tid', bidderRequest.auctionId); + + validBidRequests.forEach(validBid => { + let bid = utils.deepClone(validBid); + + // No additional params atm. + const imp = createImp(bid); + + payload.imp.push(imp); + }); + + if (validBidRequests[0].schain) { + utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + } + + if (bidderRequest && bidderRequest.gdprConsent) { + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + } + + if (bidderRequest && bidderRequest.uspConsent) { + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + } + + if (config.getConfig('coppa') === true) { + utils.deepSetValue(payload, 'regs.coppa', 1); + } + + if (utils.deepAccess(validBidRequests[0], 'userId')) { + utils.deepSetValue(payload, 'user.ext.eids', createEidsArray(validBidRequests[0].userId)); + } + + // Assign payload.site from refererinfo + if (bidderRequest.refererInfo) { + if (bidderRequest.refererInfo.reachedTop) { + const sitePage = bidderRequest.refererInfo.referer; + utils.deepSetValue(payload, 'site.page', sitePage); + utils.deepSetValue(payload, 'site.domain', utils.parseUrl(sitePage, { + noDecodeWholeURL: true + }).hostname); + + if (canAccessTopWindow()) { + utils.deepSetValue(payload, 'site.ref', utils.getWindowTop().document.referrer); + } + } + } + + // Handle First Party Data (need publisher fpd setup) + const fpd = config.getConfig('ortb2') || {}; + if (fpd.site) { + utils.mergeDeep(payload, { site: fpd.site }); + } + if (fpd.user) { + utils.mergeDeep(payload, { user: fpd.user }); + } + // Here we can handle device.geo prop + const deviceGeo = utils.deepAccess(fpd, 'device.geo'); + if (deviceGeo) { + utils.mergeDeep(payload.device, { geo: deviceGeo }); + } + + const request = { + method: 'POST', + url: ENDPOINT, + data: payload, + options: { + withCredentials: false + } + } + + return request; + }, + + interpretResponse(serverResponse, bidRequest) { + const bidResponses = []; + + try { + if (serverResponse.body && serverResponse.body.seatbid && utils.isArray(serverResponse.body.seatbid)) { + const currency = serverResponse.body.cur || DEFAULT_CURRENCY; + const referrer = bidRequest.site && bidRequest.site.ref ? bidRequest.site.ref : ''; + + serverResponse.body.seatbid.forEach(bidderSeat => { + if (!utils.isArray(bidderSeat.bid) || !bidderSeat.bid.length) { + return; + } + + bidderSeat.bid.forEach(bid => { + let mediaType; + // Actually only BANNER is supported, but other types will be added soon. + switch (utils.deepAccess(bid, 'ext.prebid.type')) { + case 'V': + mediaType = VIDEO; + break; + case 'N': + mediaType = NATIVE; + break; + default: + mediaType = BANNER; + } + + const meta = { + advertiserDomains: (Array.isArray(bid.adomain) && bid.adomain.length) ? bid.adomain : [], + advertiserName: utils.deepAccess(bid, 'ext.advertiser_name', null), + agencyName: utils.deepAccess(bid, 'ext.agency_name', null), + primaryCatId: getPrimaryCatFromResponse(bid.cat), + mediaType + } + + const newBid = { + requestId: bid.impid, + cpm: (parseFloat(bid.price) || 0), + width: bid.w, + height: bid.h, + creativeId: bid.crid || bid.id, + dealId: bid.dealid || null, + currency, + netRevenue: NET_REVENUE, + ttl: 360, // seconds. https://docs.prebid.org/dev-docs/faq.html#does-prebidjs-cache-bids + referrer, + ad: bid.adm, + mediaType, + burl: bid.burl, + meta: utils.cleanObj(meta) + }; + + bidResponses.push(newBid); + }); + }); + } + } catch (e) { + utils.logError(BIDDER_CODE, e); + } + + return bidResponses; + }, + + onBidWon: function (bid) { + if (!bid.burl) { + return; + } + + const url = bid.burl.replace(/\$\{AUCTION_PRICE\}/, bid.cpm); + + utils.triggerPixel(url); + } +} + +registerBidder(spec) diff --git a/modules/mediakeysBidAdapter.md b/modules/mediakeysBidAdapter.md new file mode 100644 index 00000000000..75e69659c8a --- /dev/null +++ b/modules/mediakeysBidAdapter.md @@ -0,0 +1,31 @@ +# Overview + +``` +Module Name: Mediakeys Bid Adapter +Module Type: Bidder Adapter +Maintainer: prebidjs@mediakeys.com +``` + +# Description + +Connects to Mediakeys demand source to fetch bids. + +# Test Parameters + +## Banner only Ad Unit + +``` +var adUnits = [ +{ + code: 'test', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]], + } + }, + bids: [{ + bidder: 'mediakeys', + params: {} // no params required. + }] +}, +``` diff --git a/test/spec/modules/mediakeysBidAdapter_spec.js b/test/spec/modules/mediakeysBidAdapter_spec.js new file mode 100644 index 00000000000..040c0abd566 --- /dev/null +++ b/test/spec/modules/mediakeysBidAdapter_spec.js @@ -0,0 +1,538 @@ +import { expect } from 'chai'; +import { spec } from 'modules/mediakeysBidAdapter.js'; +import { newBidder } from 'src/adapters/bidderFactory.js'; +import * as utils from 'src/utils.js'; +import { config } from 'src/config.js'; +import { BANNER, NATIVE, VIDEO } from '../../../src/mediaTypes.js'; + +describe('mediakeysBidAdapter', function () { + const adapter = newBidder(spec); + let utilsMock; + let sandbox; + + const bid = { + bidder: 'mediakeys', + params: {}, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600], + ], + }, + }, + adUnitCode: 'div-gpt-ad-1460505748561-0', + transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', + sizes: [ + [300, 250], + [300, 600], + ], + bidId: '299320f4de980d', + bidderRequestId: '1c1b642f803242', + auctionId: '84212956-c377-40e8-b000-9885a06dc692', + src: 'client', + bidRequestsCount: 1, + bidderRequestsCount: 1, + bidderWinsCount: 0, + ortb2Imp: { + ext: { data: { something: 'test' } } + } + }; + + const bidderRequest = { + bidderCode: 'mediakeys', + auctionId: '84212956-c377-40e8-b000-9885a06dc692', + bidderRequestId: '1c1b642f803242', + bids: [ + { + bidder: 'mediakeys', + params: {}, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600], + ], + }, + }, + adUnitCode: 'div-gpt-ad-1460505748561-0', + transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', + sizes: [ + [300, 250], + [300, 600], + ], + bidId: '299320f4de980d', + bidderRequestId: '1c1b642f803242', + auctionId: '84212956-c377-40e8-b000-9885a06dc692', + src: 'client', + bidRequestsCount: 1, + bidderRequestsCount: 1, + bidderWinsCount: 0, + ortb2Imp: { + ext: { data: { something: 'test' } } + } + }, + ], + auctionStart: 1620973766319, + timeout: 1000, + refererInfo: { + referer: + 'https://local.url/integrationExamples/gpt/hello_world.html?pbjs_debug=true', + reachedTop: true, + isAmp: false, + numIframes: 0, + stack: [ + 'https://local.url/integrationExamples/gpt/hello_world.html?pbjs_debug=true', + ], + canonicalUrl: null, + }, + start: 1620973766325, + }; + + beforeEach(function () { + utilsMock = sinon.mock(utils); + sandbox = sinon.createSandbox(); + }); + + afterEach(function () { + utilsMock.restore(); + sandbox.restore(); + }); + + describe('isBidRequestValid', function () { + it('should returns true when bid is provided even with empty params', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should returns false when bid is falsy or empty', function () { + const emptyBid = {}; + expect(spec.isBidRequestValid()).to.equal(false); + expect(spec.isBidRequestValid(false)).to.equal(false); + expect(spec.isBidRequestValid(emptyBid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + it('should create imp for supported mediaType only', function() { + const bidRequests = [utils.deepClone(bid)]; + const bidderRequestCopy = utils.deepClone(bidderRequest); + + bidRequests[0].mediaTypes.video = { + playerSize: [300, 250], + context: 'outstream' + } + + bidRequests[0].mediaTypes.native = { + type: 'image' + } + + const request = spec.buildRequests(bidRequests, bidderRequestCopy); + const data = request.data; + + expect(data.imp.length).to.equal(1); + expect(data.imp[0].banner).to.exist; + expect(data.imp[0].video).to.not.exist; + expect(data.imp[0].native).to.not.exist; + }); + + it('should get expected properties with default values (no params set)', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + + // openRTB 2.5 + expect(data.at).to.equal(1); + expect(data.cur[0]).to.equal('USD'); // default currency + expect(data.source.tid).to.equal(bidderRequest.auctionId); + + expect(data.imp.length).to.equal(1); + expect(data.imp[0].id).to.equal(bidRequests[0].bidId); + expect(data.imp[0].banner.w).to.equal(300); + expect(data.imp[0].banner.h).to.equal(250); + expect(data.imp[0].banner.format[0].w).to.equal(300); + expect(data.imp[0].banner.format[0].h).to.equal(250); + expect(data.imp[0].banner.format[1].w).to.equal(300); + expect(data.imp[0].banner.format[1].h).to.equal(600); + expect(data.imp[0].banner.topframe).to.equal(0); + expect(data.imp[0].banner.pos).to.equal(0); + + // Ortb2Imp ext + expect(data.imp[0].ext).to.exist; + expect(data.imp[0].ext.data.something).to.equal('test'); + }); + + it('should get expected properties with values from params', function () { + const bidRequests = [utils.deepClone(bid)]; + bidRequests[0].params = { + pos: 2, + }; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + expect(data.imp[0].banner.pos).to.equal(2); + }); + + it('should get expected properties with schain', function () { + const schain = { + ver: '1.0', + complete: 1, + nodes: [ + { + asi: 'ssp.test', + sid: '00001', + hp: 1, + }, + ], + }; + const bidRequests = [utils.deepClone(bid)]; + bidRequests[0].schain = schain; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + expect(data.source.ext.schain).to.equal(schain); + }); + + it('should get expected properties with coppa', function () { + sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); + + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + expect(data.regs.coppa).to.equal(1); + + config.getConfig.restore(); + }); + + it('should get expected properties with US privacy', function () { + const consent = 'Y11N'; + const bidRequests = [utils.deepClone(bid)]; + const bidderRequestWithUsPrivcay = utils.deepClone(bidderRequest); + bidderRequestWithUsPrivcay.uspConsent = consent; + const request = spec.buildRequests( + bidRequests, + bidderRequestWithUsPrivcay + ); + const data = request.data; + expect(data.regs.ext.us_privacy).to.equal(consent); + }); + + it('should get expected properties with GDPR', function () { + const consent = { + consentString: 'kjfdniwjnifwenrif3', + gdprApplies: true, + }; + const bidRequests = [utils.deepClone(bid)]; + const bidderRequestWithGDPR = utils.deepClone(bidderRequest); + bidderRequestWithGDPR.gdprConsent = consent; + const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); + const data = request.data; + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal(consent.consentString); + }); + + describe('PriceFloors module support', function() { + const getFloorTest = (options) => { + switch (options.mediaType) { + case BANNER: + return { floor: 1, currency: 'USD' } + case VIDEO: + return { floor: 5, currency: 'USD' } + case NATIVE: + return { floor: 3, currency: 'USD' } + default: + return false + } + }; + + it('should not set `imp[]bidfloor` property when priceFloors module is not available', function () { + const bidRequests = [bid]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + expect(data.imp[0].banner).to.exist; + expect(data.imp[0].bidfloor).to.not.exist + }); + + it('should not set `imp[]bidfloor` property when priceFloors module returns false', function () { + const bidWithPriceFloors = utils.deepClone(bid); + + bidWithPriceFloors.getFloor = () => { + return false; + }; + + const bidRequests = [bidWithPriceFloors]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + + expect(data.imp[0].banner).to.exist; + expect(data.imp[0].bidfloor).to.not.exist; + }); + + it('should get and set floor by mediatype', function() { + const bidWithPriceFloors = utils.deepClone(bid); + + bidWithPriceFloors.mediaTypes.video = { + playerSize: [600, 480] + }; + + bidWithPriceFloors.getFloor = getFloorTest; + + const bidRequests = [bidWithPriceFloors]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + + expect(data.imp[0].banner).to.exist; + expect(data.imp[0].bidfloor).to.equal(1); + + // expect(data.imp[1].video).to.exist; + // expect(data.imp[1].bidfloor).to.equal(5); + }); + + it('should set properties at payload level from FPD', function() { + sandbox.stub(config, 'getConfig').callsFake(key => { + const config = { + ortb2: { + site: { + domain: 'domain.example', + cat: ['IAB12'], + ext: { + data: { + category: 'sport', + } + } + }, + user: { + yob: 1985, + gender: 'm' + }, + device: { + geo: { + country: 'FR', + city: 'Marseille' + } + } + } + }; + return utils.deepAccess(config, key); + }); + + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const data = request.data; + expect(data.site.domain).to.equal('domain.example'); + expect(data.site.cat[0]).to.equal('IAB12'); + expect(data.site.ext.data.category).to.equal('sport'); + expect(data.user.yob).to.equal(1985); + expect(data.user.gender).to.equal('m'); + expect(data.device.geo.country).to.equal('FR'); + expect(data.device.geo.city).to.equal('Marseille'); + }); + }); + + describe('should support userId modules', function() { + const userId = { + pubcid: '01EAJWWNEPN3CYMM5N8M5VXY22', + unsuported: '666' + }; + + it('should send "user.eids" in the request for Prebid.js supported modules only', function() { + const bidCopy = utils.deepClone(bid); + bidCopy.userId = userId; + + const bidderRequestCopy = utils.deepClone(bidderRequest); + bidderRequestCopy.bids[0].userId = userId; + + const bidRequests = [utils.deepClone(bidCopy)]; + const request = spec.buildRequests(bidRequests, bidderRequestCopy); + const data = request.data; + + const expected = [{ + source: 'pubcid.org', + uids: [ + { + atype: 1, + id: '01EAJWWNEPN3CYMM5N8M5VXY22' + } + ] + }]; + expect(data.user.ext).to.exist; + expect(data.user.ext.eids).to.have.lengthOf(1); + expect(data.user.ext.eids).to.deep.equal(expected); + }); + }); + }); + + describe('intrepretResponse', function () { + const rawServerResponse = { + body: { + id: '60839f99-d5f2-3ab3-b6ac-736b4fe9d0ae', + seatbid: [ + { + bid: [ + { + id: '60839f99-d5f2-3ab3-b6ac-736b4fe9d0ae_0_0', + impid: '1', + price: 0.4319, + nurl: 'https://local.url/notif?index=ab-cd-ef&price=${AUCTION_PRICE}', + burl: 'https://local.url/notif?index=ab-cd-ef&price=${AUCTION_PRICE}', + adm: '', + adomain: ['domain.io'], + iurl: 'https://local.url', + cid: 'string-id', + crid: 'string-id', + cat: ['IAB2'], + attr: [], + w: 300, + h: 250, + ext: { + advertiser_name: 'Advertiser', + agency_name: 'mediakeys', + prebid: { + type: 'B' + } + }, + }, + ], + seat: '337', + }, + ], + cur: 'USD', + ext: { protocol: '5.3' }, + } + } + + it('Returns empty array if no bid', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const response01 = spec.interpretResponse({ body: { seatbid: [{ bid: [] }] } }, request); + const response02 = spec.interpretResponse({ body: { seatbid: [] } }, request); + const response03 = spec.interpretResponse({ body: { seatbid: null } }, request); + const response04 = spec.interpretResponse({ body: { seatbid: null } }, request); + const response05 = spec.interpretResponse({ body: {} }, request); + const response06 = spec.interpretResponse({}, request); + + expect(response01.length).to.equal(0); + expect(response02.length).to.equal(0); + expect(response03.length).to.equal(0); + expect(response04.length).to.equal(0); + expect(response05.length).to.equal(0); + expect(response06.length).to.equal(0); + }); + + it('Log an error', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + sinon.stub(utils, 'isArray').throws(); + spec.interpretResponse(rawServerResponse, request); + utilsMock.expects('logError').once(); + utils.isArray.restore(); + }); + + it('Meta Primary category handling', function() { + const rawServerResponseCopy = utils.deepClone(rawServerResponse); + const rawServerResponseCopy2 = utils.deepClone(rawServerResponse); + const rawServerResponseCopy3 = utils.deepClone(rawServerResponse); + const rawServerResponseCopy4 = utils.deepClone(rawServerResponse); + const rawServerResponseCopy5 = utils.deepClone(rawServerResponse); + const rawServerResponseCopy6 = utils.deepClone(rawServerResponse); + rawServerResponseCopy.body.seatbid[0].bid[0].cat = 'IAB12-1'; + rawServerResponseCopy2.body.seatbid[0].bid[0].cat = ['IAB12', 'IAB12-1']; + rawServerResponseCopy3.body.seatbid[0].bid[0].cat = ''; + rawServerResponseCopy4.body.seatbid[0].bid[0].cat = []; + rawServerResponseCopy5.body.seatbid[0].bid[0].cat = 123; + delete rawServerResponseCopy6.body.seatbid[0].bid[0].cat; + + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const response = spec.interpretResponse(rawServerResponseCopy, request); + const response2 = spec.interpretResponse(rawServerResponseCopy2, request); + const response3 = spec.interpretResponse(rawServerResponseCopy3, request); + const response4 = spec.interpretResponse(rawServerResponseCopy4, request); + const response5 = spec.interpretResponse(rawServerResponseCopy5, request); + const response6 = spec.interpretResponse(rawServerResponseCopy6, request); + expect(response[0].meta.primaryCatId).to.equal('IAB12-1'); + expect(response2[0].meta.primaryCatId).to.equal('IAB12'); + expect(response3[0].meta.primaryCatId).to.not.exist; + expect(response4[0].meta.primaryCatId).to.not.exist; + expect(response5[0].meta.primaryCatId).to.not.exist; + expect(response6[0].meta.primaryCatId).to.not.exist; + }); + + it('Build banner response', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const response = spec.interpretResponse(rawServerResponse, request); + + expect(response.length).to.equal(1); + expect(response[0].requestId).to.equal(rawServerResponse.body.seatbid[0].bid[0].impid); + expect(response[0].cpm).to.equal(rawServerResponse.body.seatbid[0].bid[0].price); + expect(response[0].width).to.equal(rawServerResponse.body.seatbid[0].bid[0].w); + expect(response[0].height).to.equal(rawServerResponse.body.seatbid[0].bid[0].h); + expect(response[0].creativeId).to.equal(rawServerResponse.body.seatbid[0].bid[0].crid); + expect(response[0].dealId).to.equal(null); + expect(response[0].currency).to.equal(rawServerResponse.body.cur); + expect(response[0].netRevenue).to.equal(true); + expect(response[0].ttl).to.equal(360); + expect(response[0].referrer).to.equal(''); + expect(response[0].ad).to.equal(rawServerResponse.body.seatbid[0].bid[0].adm); + expect(response[0].mediaType).to.equal('banner'); + expect(response[0].burl).to.equal(rawServerResponse.body.seatbid[0].bid[0].burl); + expect(response[0].meta).to.deep.equal({ + advertiserDomains: rawServerResponse.body.seatbid[0].bid[0].adomain, + advertiserName: 'Advertiser', + agencyName: 'mediakeys', + primaryCatId: 'IAB2', + mediaType: 'banner' + }); + }); + + it('Build video response', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const rawServerResponseVideo = utils.deepClone(rawServerResponse); + rawServerResponseVideo.body.seatbid[0].bid[0].ext.prebid.type = 'V'; + const response = spec.interpretResponse(rawServerResponseVideo, request); + + expect(response.length).to.equal(1); + expect(response[0].mediaType).to.equal('video'); + expect(response[0].meta.mediaType).to.equal('video'); + }); + + it('Build native response', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const rawServerResponseVideo = utils.deepClone(rawServerResponse); + rawServerResponseVideo.body.seatbid[0].bid[0].ext.prebid.type = 'N'; + const response = spec.interpretResponse(rawServerResponseVideo, request); + + expect(response.length).to.equal(1); + expect(response[0].mediaType).to.equal('native'); + expect(response[0].meta.mediaType).to.equal('native'); + }); + }); + + describe('onBidWon', function() { + beforeEach(function() { + sinon.stub(utils, 'triggerPixel'); + }); + + afterEach(function() { + utils.triggerPixel.restore(); + }); + + it('Should not trigger pixel if bid does not contain burl', function() { + const result = spec.onBidWon({}); + expect(result).to.be.undefined; + expect(utils.triggerPixel.callCount).to.equal(0); + }) + + it('Should trigger pixel if bid.burl exists', function() { + const result = spec.onBidWon({ + cpm: 4.2, + burl: 'https://example.com/p=${AUCTION_PRICE}&foo=bar' + }); + + expect(utils.triggerPixel.callCount).to.equal(1) + expect(utils.triggerPixel.firstCall.args[0]).to.be.equal( + 'https://example.com/p=4.2&foo=bar' + ); + }) + }) +}); From d0a5fe61b48aaa3ccaa37a3d3c9b2b01cc165204 Mon Sep 17 00:00:00 2001 From: eknis Date: Thu, 12 Aug 2021 05:15:18 +0900 Subject: [PATCH 14/19] Intimate Merger Universal Identifier System: add imuid submodule (#7239) * add imuidIdSystem * add test and refactoring imuid module --- integrationExamples/gpt/userId_example.html | 6 + modules/.submodules.json | 3 +- modules/imuIdSystem.js | 151 ++++++++++++++++++ modules/imuIdSystem.md | 35 ++++ modules/userId/eids.js | 4 + modules/userId/userId.md | 6 + test/spec/modules/imuIdSystem_spec.js | 168 ++++++++++++++++++++ 7 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 modules/imuIdSystem.js create mode 100644 modules/imuIdSystem.md create mode 100644 test/spec/modules/imuIdSystem_spec.js diff --git a/integrationExamples/gpt/userId_example.html b/integrationExamples/gpt/userId_example.html index 5659a208103..dfea06d17d0 100644 --- a/integrationExamples/gpt/userId_example.html +++ b/integrationExamples/gpt/userId_example.html @@ -245,7 +245,13 @@ // To get new token, register https://developer.chrome.com/origintrials/#/trials/active for Federated Learning of Cohorts token: "A3dHTSoNUMjjERBLlrvJSelNnwWUCwVQhZ5tNQ+sll7y+LkPPVZXtB77u2y7CweRIxiYaGwGXNlW1/dFp8VMEgIAAAB+eyJvcmlnaW4iOiJodHRwczovL3NoYXJlZGlkLm9yZzo0NDMiLCJmZWF0dXJlIjoiSW50ZXJlc3RDb2hvcnRBUEkiLCJleHBpcnkiOjE2MjYyMjA3OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9" } + }, + { + "name": "imuid", + "params": { + "cid": 5126 // Set your Intimate Merger Customer ID here for production } + } ], "syncDelay": 5000, "auctionDelay": 1000 diff --git a/modules/.submodules.json b/modules/.submodules.json index 555e8adaefa..1e52b02a358 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -30,7 +30,8 @@ "dmdIdSystem", "akamaiDAPId", "flocIdSystem", - "amxIdSystem" + "amxIdSystem", + "imuIdSystem" ], "adpod": [ "freeWheelAdserverVideo", diff --git a/modules/imuIdSystem.js b/modules/imuIdSystem.js new file mode 100644 index 00000000000..da03c63fc8a --- /dev/null +++ b/modules/imuIdSystem.js @@ -0,0 +1,151 @@ +/** + * The {@link module:modules/userId} module is required + * @module modules/imuIdSystem + * + * @requires module:modules/userId + */ + +import * as utils from '../src/utils.js' +import { ajax } from '../src/ajax.js' +import { submodule } from '../src/hook.js'; +import { getStorageManager } from '../src/storageManager.js'; + +export const storage = getStorageManager(); + +export const storageKey = '__im_uid'; +export const cookieKey = '_im_vid'; +export const apiUrl = 'https://audiencedata.im-apps.net/imuid/get'; +const storageMaxAge = 1800000; // 30 minites (30 * 60 * 1000) +const cookiesMaxAge = 97200000000; // 37 months ((365 * 3 + 30) * 24 * 60 * 60 * 1000) + +export function setImDataInLocalStorage(value) { + storage.setDataInLocalStorage(storageKey, value); + storage.setDataInLocalStorage(`${storageKey}_mt`, new Date(utils.timestamp()).toUTCString()); +} + +export function removeImDataFromLocalStorage() { + storage.removeDataFromLocalStorage(storageKey); + storage.removeDataFromLocalStorage(`${storageKey}_mt`); +} + +function setImDataInCookie(value) { + storage.setCookie( + cookieKey, + value, + new Date(utils.timestamp() + cookiesMaxAge).toUTCString(), + 'none' + ); +} + +export function getLocalData() { + const mt = storage.getDataFromLocalStorage(`${storageKey}_mt`); + let expired = true; + if (Date.parse(mt) && Date.now() - (new Date(mt)).getTime() < storageMaxAge) { + expired = false; + } + return { + id: storage.getDataFromLocalStorage(storageKey), + vid: storage.getCookie(cookieKey), + expired: expired + }; +} + +export function apiSuccessProcess(jsonResponse) { + if (!jsonResponse) { + return; + } + if (jsonResponse.uid) { + setImDataInLocalStorage(jsonResponse.uid); + if (jsonResponse.vid) { + setImDataInCookie(jsonResponse.vid); + } + } else { + removeImDataFromLocalStorage(); + } +} + +export function getApiCallback(callback) { + return { + success: response => { + let responseObj = {}; + if (response) { + try { + responseObj = JSON.parse(response); + apiSuccessProcess(responseObj); + } catch (error) { + utils.logError('User ID - imuid submodule: ' + error); + } + } + if (callback && responseObj.uid) { + callback(responseObj.uid); + } + }, + error: error => { + utils.logError('User ID - imuid submodule was unable to get data from api: ' + error); + if (callback) { + callback(); + } + } + }; +} + +export function callImuidApi(apiUrl) { + return function (callback) { + ajax(apiUrl, getApiCallback(callback), undefined, {method: 'GET', withCredentials: true}); + }; +} + +export function getApiUrl(cid, url) { + if (url) { + return `${url}?cid=${cid}`; + } + return `${apiUrl}?cid=${cid}`; +} + +/** @type {Submodule} */ +export const imuIdSubmodule = { + /** + * used to link submodule with config + * @type {string} + */ + name: 'imuid', + /** + * decode the stored id value for passing to bid requests + * @function + * @returns {{imuid: string} | undefined} + */ + decode(id) { + if (id && typeof id === 'string') { + return {imuid: id}; + } + return undefined; + }, + /** + * @function + * @param {SubmoduleConfig} [config] + * @returns {{id: string} | undefined | {callback:function}}} + */ + getId(config) { + const configParams = (config && config.params) || {}; + if (!configParams || typeof configParams.cid !== 'number') { + utils.logError('User ID - imuid submodule requires a valid cid to be defined'); + return undefined; + } + let apiUrl = getApiUrl(configParams.cid, configParams.url); + const localData = getLocalData(); + if (localData.vid) { + apiUrl += `&vid=${localData.vid}`; + setImDataInCookie(localData.vid); + } + + if (!localData.id) { + return {callback: callImuidApi(apiUrl)} + } + if (localData.expired) { + callImuidApi(apiUrl)(); + } + return {id: localData.id}; + } +}; + +submodule('userId', imuIdSubmodule); diff --git a/modules/imuIdSystem.md b/modules/imuIdSystem.md new file mode 100644 index 00000000000..9b6b1d108df --- /dev/null +++ b/modules/imuIdSystem.md @@ -0,0 +1,35 @@ +## Intimate Merger User ID Submodule + +IM-UID is a universal identifier provided by Intimate Merger. +The integration of [IM-UID](https://intimatemerger.com/r/uid) into Prebid.js consists of this module. + +## Building Prebid with IM-UID Support + +First, make sure to add the Intimate Merger submodule to your Prebid.js package with: + +``` +gulp build --modules=imuIdSystem, userId +``` + +The following configuration parameters are available: + +```javascript +pbjs.setConfig({ + userSync: { + userIds: [{ + name: 'imuid', + params: { + cid 5126 // Set your Intimate Merger Customer ID here for production + } + } + }] + } +}); +``` + +| Param under userSync.userIds[] | Scope | Type | Description | Example | +| --- | --- | --- | --- | --- | +| name | Required | String | The name of this module. | `"imuid"` | +| params | Required | Object | Details of module params. | | +| params.cid | Required | String | This is the Customer ID value obtained via Intimate Merger. | `5126` | +| params.url | Optional | String | Use this to change the default endpoint URL. | `"https://example.com/some/api"` | diff --git a/modules/userId/eids.js b/modules/userId/eids.js index e11eb3edb68..813dd2cf427 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -221,6 +221,10 @@ const USER_IDS_CONFIG = { amxId: { source: 'amxrtb.com', atype: 1, + }, + 'imuid': { + source: 'intimatemerger.com', + atype: 1 } }; diff --git a/modules/userId/userId.md b/modules/userId/userId.md index 1c7f854f725..bbbe995983a 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -264,6 +264,12 @@ pbjs.setConfig({ name: "_dpes_id", expires: 90 } + }, + { + name: 'imuid', + params: { + cid: 5126 // Set your Intimate Merger Customer ID here for production + } }], syncDelay: 5000 } diff --git a/test/spec/modules/imuIdSystem_spec.js b/test/spec/modules/imuIdSystem_spec.js new file mode 100644 index 00000000000..2934a7c213b --- /dev/null +++ b/test/spec/modules/imuIdSystem_spec.js @@ -0,0 +1,168 @@ +import { + imuIdSubmodule, + storage, + getApiUrl, + apiSuccessProcess, + getLocalData, + callImuidApi, + getApiCallback, + storageKey, + cookieKey, + apiUrl +} from 'modules/imuIdSystem.js'; + +import * as utils from 'src/utils.js'; + +describe('imuId module', function () { + // let setLocalStorageStub; + let getLocalStorageStub; + let getCookieStub; + // let ajaxBuilderStub; + + beforeEach(function (done) { + // setLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage'); + getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); + getCookieStub = sinon.stub(storage, 'getCookie'); + // ajaxBuilderStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockResponse('{}')); + done(); + }); + + afterEach(function () { + getLocalStorageStub.restore(); + getCookieStub.restore(); + // ajaxBuilderStub.restore(); + }); + + const storageTestCasesForEmpty = [ + undefined, + null, + '' + ] + + const configParamTestCase = { + params: { + cid: 5126 + } + } + + describe('getId()', function () { + it('should return the uid when it exists in local storages', function () { + getLocalStorageStub.withArgs(storageKey).returns('testUid'); + const id = imuIdSubmodule.getId(configParamTestCase); + expect(id).to.be.deep.equal({id: 'testUid'}); + }); + + storageTestCasesForEmpty.forEach(testCase => it('should return the callback when it not exists in local storages', function () { + getLocalStorageStub.withArgs(storageKey).returns(testCase); + const id = imuIdSubmodule.getId(configParamTestCase); + expect(id).have.all.keys('callback'); + })); + + it('should return "undefined" when empty param', function () { + const id = imuIdSubmodule.getId(); + expect(id).to.be.deep.equal(undefined); + }); + + it('should return the callback when it not exists in local storages (and has vid)', function () { + getCookieStub.withArgs(cookieKey).returns('test'); + const id = imuIdSubmodule.getId(configParamTestCase); + expect(id).have.all.keys('callback'); + }); + }); + + describe('getApiUrl()', function () { + it('should return default url when cid only', function () { + const url = getApiUrl(5126); + expect(url).to.be.equal(`${apiUrl}?cid=5126`); + }); + + it('should return param url when set url', function () { + const url = getApiUrl(5126, 'testurl'); + expect(url).to.be.equal('testurl?cid=5126'); + }); + }); + + describe('decode()', function () { + it('should return the uid when it exists in local storages', function () { + const id = imuIdSubmodule.decode('testDecode'); + expect(id).to.be.deep.equal({imuid: 'testDecode'}); + }); + + it('should return the undefined when decode id is not "string"', function () { + const id = imuIdSubmodule.decode(1); + expect(id).to.equal(undefined); + }); + }); + + describe('getLocalData()', function () { + it('always have the same key', function () { + getLocalStorageStub.withArgs(storageKey).returns('testid'); + getCookieStub.withArgs(cookieKey).returns('testvid'); + getLocalStorageStub.withArgs(`${storageKey}_mt`).returns(new Date(utils.timestamp()).toUTCString()); + const localData = getLocalData(); + expect(localData).to.be.deep.equal({ + id: 'testid', + vid: 'testvid', + expired: false + }); + }); + + it('should return expired is true', function () { + getLocalStorageStub.withArgs(`${storageKey}_mt`).returns(0); + const localData = getLocalData(); + expect(localData).to.be.deep.equal({ + id: undefined, + vid: undefined, + expired: true + }); + }); + }); + + describe('apiSuccessProcess()', function () { + it('should return the undefined when success response', function () { + const res = apiSuccessProcess({ + uid: 'test', + vid: 'test' + }); + expect(res).to.equal(undefined); + }); + + it('should return the undefined when empty response', function () { + const res = apiSuccessProcess(); + expect(res).to.equal(undefined); + }); + + it('should return the undefined when error response', function () { + const res = apiSuccessProcess({ + error: 'error response' + }); + expect(res).to.equal(undefined); + }); + }); + + describe('callImuidApi()', function () { + it('should return function when set url', function () { + const res = callImuidApi(`${apiUrl}?cid=5126`); + expect(res).to.exist.and.to.be.a('function'); + }); + }); + + describe('getApiCallback()', function () { + it('should return success and error functions', function () { + const res = getApiCallback(); + expect(res.success).to.exist.and.to.be.a('function'); + expect(res.error).to.exist.and.to.be.a('function'); + }); + + it('should return "undefined" success', function () { + const res = getApiCallback(function(uid) { return uid }); + expect(res.success('{"uid": "testid"}')).to.equal(undefined); + expect(res.error()).to.equal(undefined); + }); + + it('should return "undefined" catch error response', function () { + const res = getApiCallback(function(uid) { return uid }); + expect(res.success('error response')).to.equal(undefined); + }); + }); +}); From 217c8f66c5a5c08076a9f75e8b6be2d05a067fcf Mon Sep 17 00:00:00 2001 From: CPMStar Date: Wed, 11 Aug 2021 13:36:04 -0700 Subject: [PATCH 15/19] CPMStar Bid Adapter: Add adomain support for Prebid 5.x (#7284) * added cpmstarBidAdapter with meta.advertiserDomains support * fix linting Co-authored-by: Chris Huie --- modules/cpmstarBidAdapter.js | 183 ++++++++++++++++ test/spec/modules/cpmstarBidAdapter_spec.js | 231 ++++++++++++++++++++ 2 files changed, 414 insertions(+) create mode 100755 modules/cpmstarBidAdapter.js create mode 100755 test/spec/modules/cpmstarBidAdapter_spec.js diff --git a/modules/cpmstarBidAdapter.js b/modules/cpmstarBidAdapter.js new file mode 100755 index 00000000000..14c0d43add7 --- /dev/null +++ b/modules/cpmstarBidAdapter.js @@ -0,0 +1,183 @@ + +import * as utils from '../src/utils.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { VIDEO, BANNER } from '../src/mediaTypes.js'; +import { config } from '../src/config.js'; + +const BIDDER_CODE = 'cpmstar'; + +const ENDPOINT_DEV = 'https://dev.server.cpmstar.com/view.aspx'; +const ENDPOINT_STAGING = 'https://staging.server.cpmstar.com/view.aspx'; +const ENDPOINT_PRODUCTION = 'https://server.cpmstar.com/view.aspx'; + +const DEFAULT_TTL = 300; +const DEFAULT_CURRENCY = 'USD'; + +function fixedEncodeURIComponent(str) { + return encodeURIComponent(str).replace(/[!'()*]/g, function(c) { + return '%' + c.charCodeAt(0).toString(16); + }); +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER, VIDEO], + pageID: Math.floor(Math.random() * 10e6), + + getMediaType: function (bidRequest) { + if (bidRequest == null) return BANNER; + return !utils.deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO; + }, + + getPlayerSize: function (bidRequest) { + var playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'); + if (playerSize == null) return [640, 440]; + if (playerSize[0] != null) playerSize = playerSize[0]; + if (playerSize == null || playerSize[0] == null || playerSize[1] == null) return [640, 440]; + return playerSize; + }, + + isBidRequestValid: function (bid) { + return ((typeof bid.params.placementId === 'string') && !!bid.params.placementId.length) || (typeof bid.params.placementId === 'number'); + }, + + buildRequests: function (validBidRequests, bidderRequest) { + var requests = []; + // This reference to window.top can cause issues when loaded in an iframe if not protected with a try/catch. + + for (var i = 0; i < validBidRequests.length; i++) { + var bidRequest = validBidRequests[i]; + var referer = encodeURIComponent(bidderRequest.refererInfo.referer); + var e = utils.getBidIdParameter('endpoint', bidRequest.params); + var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION; + var mediaType = spec.getMediaType(bidRequest); + var playerSize = spec.getPlayerSize(bidRequest); + var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : ''); + var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') + + '&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) + + '&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) + + '&requestid=' + bidRequest.bidId + + '&referer=' + encodeURIComponent(referer); + + if (bidRequest.schain && bidRequest.schain.nodes) { + var schain = bidRequest.schain; + var schainString = ''; + schainString += schain.ver + ',' + schain.complete; + for (var i2 = 0; i2 < schain.nodes.length; i2++) { + var node = schain.nodes[i2]; + schainString += '!' + + fixedEncodeURIComponent(node.asi || '') + ',' + + fixedEncodeURIComponent(node.sid || '') + ',' + + fixedEncodeURIComponent(node.hp || '') + ',' + + fixedEncodeURIComponent(node.rid || '') + ',' + + fixedEncodeURIComponent(node.name || '') + ',' + + fixedEncodeURIComponent(node.domain || ''); + } + url += '&schain=' + schainString + } + + if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent.consentString != null) { + url += '&gdpr_consent=' + bidderRequest.gdprConsent.consentString; + } + if (bidderRequest.gdprConsent.gdprApplies != null) { + url += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + } + } + + if (bidderRequest.uspConsent != null) { + url += '&us_privacy=' + bidderRequest.uspConsent; + } + + if (config.getConfig('coppa')) { + url += '&tfcd=' + (config.getConfig('coppa') ? 1 : 0); + } + + requests.push({ + method: 'GET', + url: url, + bidRequest: bidRequest, + }); + } + + return requests; + }, + + interpretResponse: function (serverResponse, request) { + var bidRequest = request.bidRequest; + var mediaType = spec.getMediaType(bidRequest); + + var bidResponses = []; + + if (!Array.isArray(serverResponse.body)) { + serverResponse.body = [serverResponse.body]; + } + + for (var i = 0; i < serverResponse.body.length; i++) { + var raw = serverResponse.body[i]; + var rawBid = raw.creatives[0]; + if (!rawBid) { + utils.logWarn('cpmstarBidAdapter: server response failed check'); + return; + } + var cpm = (parseFloat(rawBid.cpm) || 0); + + if (!cpm) { + utils.logWarn('cpmstarBidAdapter: server response failed check. Missing cpm') + return; + } + + var bidResponse = { + requestId: rawBid.requestid, + cpm: cpm, + width: rawBid.width || 0, + height: rawBid.height || 0, + currency: rawBid.currency ? rawBid.currency : DEFAULT_CURRENCY, + netRevenue: rawBid.netRevenue ? rawBid.netRevenue : true, + ttl: rawBid.ttl ? rawBid.ttl : DEFAULT_TTL, + creativeId: rawBid.creativeid || 0, + meta: { + advertiserDomains: rawBid.adomain ? rawBid.adomain : [] + } + }; + + if (rawBid.hasOwnProperty('dealId')) { + bidResponse.dealId = rawBid.dealId + } + + if (mediaType == BANNER && rawBid.code) { + bidResponse.ad = rawBid.code + (rawBid.px_cr ? "\n" : ''); + } else if (mediaType == VIDEO && rawBid.creativemacros && rawBid.creativemacros.HTML5VID_VASTSTRING) { + var playerSize = spec.getPlayerSize(bidRequest); + if (playerSize != null) { + bidResponse.width = playerSize[0]; + bidResponse.height = playerSize[1]; + } + bidResponse.mediaType = VIDEO; + bidResponse.vastXml = rawBid.creativemacros.HTML5VID_VASTSTRING; + } else { + return utils.logError('bad response', rawBid); + } + + bidResponses.push(bidResponse); + } + + return bidResponses; + }, + + getUserSyncs: function (syncOptions, serverResponses) { + const syncs = []; + if (serverResponses.length == 0 || !serverResponses[0].body) return syncs; + var usersyncs = serverResponses[0].body[0].syncs; + if (!usersyncs || usersyncs.length < 0) return syncs; + for (var i = 0; i < usersyncs.length; i++) { + var us = usersyncs[i]; + if ((us.type === 'image' && syncOptions.pixelEnabled) || (us.type == 'iframe' && syncOptions.iframeEnabled)) { + syncs.push(us); + } + } + return syncs; + } + +}; +registerBidder(spec); diff --git a/test/spec/modules/cpmstarBidAdapter_spec.js b/test/spec/modules/cpmstarBidAdapter_spec.js new file mode 100755 index 00000000000..285fca9690a --- /dev/null +++ b/test/spec/modules/cpmstarBidAdapter_spec.js @@ -0,0 +1,231 @@ +import { expect } from 'chai'; +import { spec } from 'modules/cpmstarBidAdapter.js'; +import { deepClone } from 'src/utils.js'; +import { config } from 'src/config.js'; + +const valid_bid_requests = [{ + 'bidder': 'cpmstar', + 'params': { + 'placementId': '57' + }, + 'sizes': [[300, 250]], + 'bidId': 'bidId' +}]; + +const bidderRequest = { + refererInfo: { + referer: 'referer', + reachedTop: false, + } +}; + +const serverResponse = { + body: [{ + creatives: [{ + cpm: 1, + width: 0, + height: 0, + currency: 'USD', + netRevenue: true, + ttl: 1, + creativeid: '1234', + requestid: '11123', + code: 'no idea', + media: 'banner', + } + ], + syncs: [{ type: 'image', url: 'https://server.cpmstar.com/pixel.aspx' }] + }] +}; + +describe('Cpmstar Bid Adapter', function () { + describe('isBidRequestValid', function () { + it('should return true since the bid is valid', + function () { + var bid = { params: { placementId: 123456 } }; + expect(spec.isBidRequestValid(bid)).to.equal(true); + }) + + it('should return false since the bid is invalid', function () { + var bid = { params: { placementId: '' } }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }) + + it('should return a valid player size', function () { + var bid = { + mediaTypes: { + video: { + playerSize: [[960, 540]] + } + } + } + expect(spec.getPlayerSize(bid)[0]).to.equal(960); + expect(spec.getPlayerSize(bid)[1]).to.equal(540); + }) + + it('should return a default player size', function () { + var bid = { + mediaTypes: { + video: { + playerSize: null + } + } + } + expect(spec.getPlayerSize(bid)[0]).to.equal(640); + expect(spec.getPlayerSize(bid)[1]).to.equal(440); + }) + }); + + describe('buildRequests', function () { + it('should produce a valid production request', function () { + var requests = spec.buildRequests(valid_bid_requests, bidderRequest); + expect(requests[0]).to.have.property('method'); + expect(requests[0]).to.have.property('url'); + expect(requests[0]).to.have.property('bidRequest'); + expect(requests[0].url).to.include('https://server.cpmstar.com/view.aspx'); + }); + it('should produce a valid staging request', function () { + var stgReq = deepClone(valid_bid_requests); + stgReq[0].params.endpoint = 'staging'; + var requests = spec.buildRequests(stgReq, bidderRequest); + expect(requests[0]).to.have.property('method'); + expect(requests[0]).to.have.property('url'); + expect(requests[0]).to.have.property('bidRequest'); + expect(requests[0].url).to.include('https://staging.server.cpmstar.com/view.aspx'); + }); + it('should produce a valid dev request', function () { + var devReq = deepClone(valid_bid_requests); + devReq[0].params.endpoint = 'dev'; + var requests = spec.buildRequests(devReq, bidderRequest); + expect(requests[0]).to.have.property('method'); + expect(requests[0]).to.have.property('url'); + expect(requests[0]).to.have.property('bidRequest'); + expect(requests[0].url).to.include('https://dev.server.cpmstar.com/view.aspx'); + }); + it('should produce a request with support for GDPR', function () { + var gdpr_bidderRequest = deepClone(bidderRequest); + gdpr_bidderRequest.gdprConsent = { + consentString: 'consentString', + gdprApplies: true + }; + var requests = spec.buildRequests(valid_bid_requests, gdpr_bidderRequest); + expect(requests[0]).to.have.property('url'); + expect(requests[0].url).to.include('gdpr_consent=consentString'); + expect(requests[0].url).to.include('gdpr=1'); + }); + it('should produce a request with support for USP', function () { + var usp_bidderRequest = deepClone(bidderRequest); + usp_bidderRequest.uspConsent = '1YYY'; + var requests = spec.buildRequests(valid_bid_requests, usp_bidderRequest); + expect(requests[0]).to.have.property('url'); + expect(requests[0].url).to.include('us_privacy=1YYY'); + }); + it('should produce a request with support for COPPA', function () { + sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); + var requests = spec.buildRequests(valid_bid_requests, bidderRequest); + config.getConfig.restore(); + expect(requests[0]).to.have.property('url'); + expect(requests[0].url).to.include('tfcd=1'); + }); + }); + + it('should produce a request with support for OpenRTB SupplyChain', function () { + var reqs = deepClone(valid_bid_requests); + reqs[0].schain = { + 'ver': '1.0', + 'complete': 1, + 'nodes': [ + { + 'asi': 'exchange1.com', + 'sid': '1234', + 'hp': 1 + }, + { + 'asi': 'exchange2.com', + 'sid': 'abcd', + 'hp': 1 + } + ] + }; + var requests = spec.buildRequests(reqs, bidderRequest); + expect(requests[0]).to.have.property('url'); + expect(requests[0].url).to.include('&schain=1.0,1!exchange1.com,1234,1,,,!exchange2.com,abcd,1,,,'); + }); + + describe('interpretResponse', function () { + const request = { + bidRequest: { + mediaType: 'BANNER' + } + }; + + it('should return a valid bidresponse array', function () { + var r = spec.interpretResponse(serverResponse, request) + var c = serverResponse.body[0].creatives[0]; + expect(r[0].length).to.not.equal(0); + expect(r[0].requestId).equal(c.requestid); + expect(r[0].creativeId).equal(c.creativeid); + expect(r[0].cpm).equal(c.cpm); + expect(r[0].width).equal(c.width); + expect(r[0].height).equal(c.height); + expect(r[0].currency).equal(c.currency); + expect(r[0].netRevenue).equal(c.netRevenue); + expect(r[0].ttl).equal(c.ttl); + expect(r[0].ad).equal(c.code); + }); + + it('should return a valid bidresponse array from a non-array-body', function () { + var r = spec.interpretResponse({ body: serverResponse.body[0] }, request) + var c = serverResponse.body[0].creatives[0]; + expect(r[0].length).to.not.equal(0); + expect(r[0].requestId).equal(c.requestid); + expect(r[0].creativeId).equal(c.creativeid); + expect(r[0].cpm).equal(c.cpm); + expect(r[0].width).equal(c.width); + expect(r[0].height).equal(c.height); + expect(r[0].currency).equal(c.currency); + expect(r[0].netRevenue).equal(c.netRevenue); + expect(r[0].ttl).equal(c.ttl); + expect(r[0].ad).equal(c.code); + }); + + it('should return undefined due to an invalid cpm value', function () { + var badServer = deepClone(serverResponse); + badServer.body[0].creatives[0].cpm = 0; + var c = spec.interpretResponse(badServer, request); + expect(c).to.be.undefined; + }); + + it('should return undefined due to a bad response', function () { + var badServer = deepClone(serverResponse); + badServer.body[0].creatives[0].code = null; + var c = spec.interpretResponse(badServer, request); + expect(c).to.be.undefined; + }); + + it('should return a valid response with a dealId', function () { + var dealServer = deepClone(serverResponse); + dealServer.body[0].creatives[0].dealId = 'deal'; + expect(spec.interpretResponse(dealServer, request)[0].dealId).to.equal('deal'); + }); + }); + + describe('getUserSyncs', function () { + var sres = [deepClone(serverResponse)]; + + it('should return a valid pixel sync', function () { + var syncs = spec.getUserSyncs({ pixelEnabled: true }, sres); + expect(syncs.length).equal(1); + expect(syncs[0].type).equal('image'); + expect(syncs[0].url).equal('https://server.cpmstar.com/pixel.aspx'); + }); + + it('should return a valid iframe sync', function () { + sres[0].body[0].syncs[0].type = 'iframe'; + var syncs = spec.getUserSyncs({ iframeEnabled: true }, sres); + expect(syncs.length).equal(1); + expect(syncs[0].type).equal('iframe'); + expect(syncs[0].url).equal('https://server.cpmstar.com/pixel.aspx'); + }); + }); +}); From 3d8ed534dac05153e54d3c07b13700cf6628985b Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Thu, 12 Aug 2021 16:49:35 +0300 Subject: [PATCH 16/19] Adf adapter: schain support added (#7292) --- modules/adfBidAdapter.js | 5 +++++ test/spec/modules/adfBidAdapter_spec.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/modules/adfBidAdapter.js b/modules/adfBidAdapter.js index 7666e98b374..43dcdcd1604 100644 --- a/modules/adfBidAdapter.js +++ b/modules/adfBidAdapter.js @@ -94,6 +94,7 @@ export const spec = { const currency = getConfig('currency.adServerCurrency'); const cur = currency && [ currency ]; const eids = setOnAny(validBidRequests, 'userIdAsEids'); + const schain = setOnAny(validBidRequests, 'schain'); const imp = validBidRequests.map((bid, id) => { bid.netRevenue = pt; @@ -206,6 +207,10 @@ export const spec = { utils.deepSetValue(request, 'user.ext.eids', eids); } + if (schain) { + utils.deepSetValue(request, 'source.ext.schain', schain); + } + return { method: 'POST', url: 'https://' + adxDomain + '/adx/openrtb', diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js index 25ad6987153..ef11490529a 100644 --- a/test/spec/modules/adfBidAdapter_spec.js +++ b/test/spec/modules/adfBidAdapter_spec.js @@ -245,6 +245,27 @@ describe('Adf adapter', function () { assert.deepEqual(request.cur, [ 'EUR' ]); }); + it('should pass supply chain object', function () { + let validBidRequests = [{ + bidId: 'bidId', + params: {}, + schain: { + validation: 'strict', + config: { + ver: '1.0' + } + } + }]; + + let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); + assert.deepEqual(request.source.ext.schain, { + validation: 'strict', + config: { + ver: '1.0' + } + }); + }); + describe('priceType', function () { it('should send default priceType', function () { let validBidRequests = [{ From 3b59a2b310d47092557a5605d7074bcb07a3885a Mon Sep 17 00:00:00 2001 From: Alexander Clouter Date: Thu, 12 Aug 2021 15:38:34 +0100 Subject: [PATCH 17/19] targeting: allow non-string (eg. numeric) targeting segments (#7160) Documentation[1] shows a numeric example which causes an exception as we try to call .split(','). [1] https://docs.prebid.org/dev-docs/add-rtd-submodule.html#gettargetingdata --- src/targeting.js | 4 ++- test/spec/unit/core/targeting_spec.js | 47 ++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/targeting.js b/src/targeting.js index edf9521c251..4bbed7bb758 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -634,7 +634,9 @@ export function newTargeting(auctionManager) { return Object.keys(aut) .map(function(key) { - return {[key]: utils.isArray(aut[key]) ? aut[key] : aut[key].split(',')}; + if (utils.isStr(aut[key])) aut[key] = aut[key].split(','); + if (!utils.isArray(aut[key])) aut[key] = [ aut[key] ]; + return { [key]: aut[key] }; }); } diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index c82aac1acf9..f83bd2f6635 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { targeting as targetingInstance, filters, getHighestCpmBidsFromBidPool, sortByDealAndPriceBucketOrCpm } from 'src/targeting.js'; import { config } from 'src/config.js'; -import { getAdUnits, createBidReceived } from 'test/fixtures/fixtures.js'; +import { createBidReceived } from 'test/fixtures/fixtures.js'; import CONSTANTS from 'src/constants.json'; import { auctionManager } from 'src/auctionManager.js'; import * as utils from 'src/utils.js'; @@ -280,6 +280,51 @@ describe('targeting tests', function () { bidExpiryStub.restore(); }); + describe('when handling different adunit targeting value types', function () { + const adUnitCode = '/123456/header-bid-tag-0'; + const adServerTargeting = {}; + + let getAdUnitsStub; + + before(function() { + getAdUnitsStub = sandbox.stub(auctionManager, 'getAdUnits').callsFake(function() { + return [ + { + 'code': adUnitCode, + [CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]: adServerTargeting + } + ]; + }); + }); + + after(function() { + getAdUnitsStub.restore(); + }); + + afterEach(function() { + delete adServerTargeting.test_type; + }); + + const pairs = [ + ['string', '2.3', '2.3'], + ['number', 2.3, '2.3'], + ['boolean', true, 'true'], + ['string-separated', '2.3,4.5', '2.3, 4.5'], + ['array-of-string', ['2.3', '4.5'], '2.3, 4.5'], + ['array-of-number', [2.3, 4.5], '2.3, 4.5'], + ['array-of-boolean', [true, false], 'true, false'] + ]; + pairs.forEach(([type, value, result]) => { + it(`accepts ${type}`, function() { + adServerTargeting.test_type = value; + + const targeting = targetingInstance.getAllTargeting([adUnitCode]); + + expect(targeting[adUnitCode].test_type).is.equal(result); + }); + }); + }); + describe('when hb_deal is present in bid.adserverTargeting', function () { let bid4; From 7f5a3be54e1525d493647652e5fa15b2fe8f40e1 Mon Sep 17 00:00:00 2001 From: Mike Chowla Date: Thu, 12 Aug 2021 11:23:17 -0700 Subject: [PATCH 18/19] Prebid 5.9.0 Release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f96581fbdfb..a4f6abd1a4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "5.9.0-pre", + "version": "5.9.0", "description": "Header Bidding Management Library", "main": "src/prebid.js", "scripts": { From 707d73f126cbad0bb37a70f877838600845e35fa Mon Sep 17 00:00:00 2001 From: Mike Chowla Date: Thu, 12 Aug 2021 11:53:42 -0700 Subject: [PATCH 19/19] Increment pre version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a4f6abd1a4f..f8cd2fc3ef3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "5.9.0", + "version": "5.10.0-pre", "description": "Header Bidding Management Library", "main": "src/prebid.js", "scripts": {