diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index f8a53a293de..4ee5aaec5be 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; +import { deepAccess, isArray, isStr, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; import { getRefererInfo } from '../src/refererDetection.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; @@ -40,6 +40,19 @@ export const spec = { const pageUrl = getPageUrl(bidderRequest.refererInfo, window); const gdpr = bidderRequest.gdprConsent; const firstSlot = slots[0]; + const kwdsFromRequest = firstSlot.kwds; + let keywords = []; + if (kwdsFromRequest) { + if (isArray(kwdsFromRequest)) { + keywords = kwdsFromRequest; + } else if (isStr(kwdsFromRequest)) { + if (kwdsFromRequest.indexOf(',') != -1) { + keywords = kwdsFromRequest.split(',').map((e) => { return e.trim() }); + } else { + keywords.push(kwdsFromRequest); + } + } + } const payloadObject = { at: new Date().toString(), nid: firstSlot.nid, @@ -47,12 +60,13 @@ export const spec = { pid: firstSlot.pid, url: pageUrl, lang: (window.navigator.language || window.navigator.languages[0]), - kwds: bidderRequest.ortb2?.site?.keywords || [], + kwds: keywords, dbg: false, slts: slots, is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'), tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null, }; + const payloadString = JSON.stringify(payloadObject); return { method: 'POST', @@ -129,6 +143,7 @@ function beOpRequestSlotsMaker(bid) { sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes, flr: floor, pid: getValue(bid.params, 'accountId'), + kwds: getValue(bid.params, 'keywords'), nid: getValue(bid.params, 'networkId'), nptnid: getValue(bid.params, 'networkPartnerId'), bid: getBidIdParameter('bidId', bid), diff --git a/test/spec/modules/beopBidAdapter_spec.js b/test/spec/modules/beopBidAdapter_spec.js index c6001c3ba2e..ad096fd6526 100644 --- a/test/spec/modules/beopBidAdapter_spec.js +++ b/test/spec/modules/beopBidAdapter_spec.js @@ -216,4 +216,56 @@ describe('BeOp Bid Adapter tests', () => { expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad'); }); }); + + describe('Ensure keywords is always array of string', function () { + let bidRequests = []; + afterEach(function () { + bidRequests = []; + }); + + it('should work with keywords as an array', function () { + let bid = Object.assign({}, validBid); + bid.params.keywords = ['a', 'b']; + bidRequests.push(bid); + config.setConfig({ + currency: { adServerCurrency: 'USD' } + }); + const request = spec.buildRequests(bidRequests, {}); + const payload = JSON.parse(request.data); + const url = request.url; + expect(payload.kwds).to.exist; + expect(payload.kwds).to.include('a'); + expect(payload.kwds).to.include('b'); + }); + + it('should work with keywords as a string', function () { + let bid = Object.assign({}, validBid); + bid.params.keywords = 'list of keywords'; + bidRequests.push(bid); + config.setConfig({ + currency: { adServerCurrency: 'USD' } + }); + const request = spec.buildRequests(bidRequests, {}); + const payload = JSON.parse(request.data); + const url = request.url; + expect(payload.kwds).to.exist; + expect(payload.kwds).to.include('list of keywords'); + }); + + it('should work with keywords as a string containing a comma', function () { + let bid = Object.assign({}, validBid); + bid.params.keywords = 'list, of, keywords'; + bidRequests.push(bid); + config.setConfig({ + currency: { adServerCurrency: 'USD' } + }); + const request = spec.buildRequests(bidRequests, {}); + const payload = JSON.parse(request.data); + const url = request.url; + expect(payload.kwds).to.exist; + expect(payload.kwds).to.include('list'); + expect(payload.kwds).to.include('of'); + expect(payload.kwds).to.include('keywords'); + }) + }) });