diff --git a/modules/gridBidAdapter.js b/modules/gridBidAdapter.js index d4aceaea162..16f8ff11574 100644 --- a/modules/gridBidAdapter.js +++ b/modules/gridBidAdapter.js @@ -78,9 +78,6 @@ export const spec = { } const {params: {uid, keywords}, mediaTypes, bidId, adUnitCode, rtd, ortb2Imp} = bid; bidsMap[bidId] = bid; - if (!pageKeywords && !utils.isEmpty(keywords)) { - pageKeywords = utils.transformBidderParamKeywords(keywords); - } const bidFloor = _getFloor(mediaTypes || {}, bid); const jwTargeting = rtd && rtd.jwplayer && rtd.jwplayer.targeting; if (jwTargeting) { @@ -104,6 +101,12 @@ export const spec = { impObj.ext.gpid = impObj.ext.data.adserver.adslot; } } + if (!utils.isEmpty(keywords)) { + if (!pageKeywords) { + pageKeywords = keywords; + } + impObj.ext.bidder = { keywords }; + } if (bidFloor) { impObj.bidfloor = bidFloor; @@ -185,17 +188,28 @@ export const spec = { request.user = user; } - const configKeywords = utils.transformBidderParamKeywords({ - 'user': utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null, - 'context': utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null - }); + const userKeywords = utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; + const siteKeywords = utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; - if (configKeywords.length) { - pageKeywords = (pageKeywords || []).concat(configKeywords); + if (userKeywords) { + pageKeywords = pageKeywords || {}; + pageKeywords.user = pageKeywords.user || {}; + pageKeywords.user.ortb2 = [ + { + name: 'keywords', + keywords: userKeywords.split(','), + } + ]; } - - if (pageKeywords && pageKeywords.length > 0) { - pageKeywords.forEach(deleteValues); + if (siteKeywords) { + pageKeywords = pageKeywords || {}; + pageKeywords.site = pageKeywords.site || {}; + pageKeywords.site.ortb2 = [ + { + name: 'keywords', + keywords: siteKeywords.split(','), + } + ]; } if (pageKeywords) { @@ -311,16 +325,6 @@ function _getFloor (mediaTypes, bid) { return floor; } -function isPopulatedArray(arr) { - return !!(utils.isArray(arr) && arr.length > 0); -} - -function deleteValues(keyPairObj) { - if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') { - delete keyPairObj.value; - } -} - function _getBidFromResponse(respItem) { if (!respItem) { utils.logError(LOG_ERROR_MESS.emptySeatbid); @@ -341,11 +345,11 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) { const bid = bidRequest.bidsMap[serverBid.impid]; if (bid) { const bidResponse = { - requestId: bid.bidId, // bid.bidderRequestId, + requestId: bid.bidId, // bid.bidderRequestId cpm: serverBid.price, width: serverBid.w, height: serverBid.h, - creativeId: serverBid.auid, // bid.bidId, + creativeId: serverBid.auid, // bid.bidId currency: 'USD', netRevenue: true, ttl: TIME_TO_LIVE, diff --git a/test/spec/modules/gridBidAdapter_spec.js b/test/spec/modules/gridBidAdapter_spec.js index 4f5f62f2cb8..2e5d2e63677 100644 --- a/test/spec/modules/gridBidAdapter_spec.js +++ b/test/spec/modules/gridBidAdapter_spec.js @@ -402,11 +402,47 @@ describe('TheMediaGrid Adapter', function () { it('should contain the keyword values if it present in ortb2.(site/user)', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( - arg => arg === 'ortb2.user' ? {'keywords': 'foo'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null)); - const request = spec.buildRequests([bidRequests[0]], bidderRequest); + arg => arg === 'ortb2.user' ? {'keywords': 'foo,any'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null)); + const keywords = { + 'site': { + 'somePublisher': [ + { + 'name': 'someName', + 'brandsafety': ['disaster'], + 'topic': ['stress', 'fear'] + } + ] + } + }; + const bidRequestWithKW = { ...bidRequests[0], params: { ...bidRequests[0].params, keywords } } + const request = spec.buildRequests([bidRequestWithKW], bidderRequest); expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); - expect(payload.ext.keywords).to.deep.equal([{'key': 'user', 'value': ['foo']}, {'key': 'context', 'value': ['bar']}]); + expect(payload.ext.keywords).to.deep.equal({ + 'site': { + 'somePublisher': [ + { + 'name': 'someName', + 'brandsafety': ['disaster'], + 'topic': ['stress', 'fear'] + } + ], + 'ortb2': [ + { + 'name': 'keywords', + 'keywords': ['bar'] + } + ] + }, + 'user': { + 'ortb2': [ + { + 'name': 'keywords', + 'keywords': ['foo', 'any'] + } + ] + } + }); getConfigStub.restore(); });