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);