Skip to content

Commit 4ef0675

Browse files
sebrobertJacobKlein26
authored andcommitted
BeOp Bid Adapter : update keywords management (prebid#9166)
* Don't know why params are in an array in that bid object. Make it work for both if it is fixed later * Update params reading method to adapt to arrays for all params * Keywords have to be an array of string (prebid#9) * Keywords have to be an array of string * Last check if isStr * Fix linting errors * Fix tests
1 parent f4988e3 commit 4ef0675

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

modules/beopBidAdapter.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js';
1+
import { deepAccess, isArray, isStr, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js';
22
import { getRefererInfo } from '../src/refererDetection.js';
33
import { registerBidder } from '../src/adapters/bidderFactory.js';
44
import { config } from '../src/config.js';
@@ -40,19 +40,33 @@ export const spec = {
4040
const pageUrl = getPageUrl(bidderRequest.refererInfo, window);
4141
const gdpr = bidderRequest.gdprConsent;
4242
const firstSlot = slots[0];
43+
const kwdsFromRequest = firstSlot.kwds;
44+
let keywords = [];
45+
if (kwdsFromRequest) {
46+
if (isArray(kwdsFromRequest)) {
47+
keywords = kwdsFromRequest;
48+
} else if (isStr(kwdsFromRequest)) {
49+
if (kwdsFromRequest.indexOf(',') != -1) {
50+
keywords = kwdsFromRequest.split(',').map((e) => { return e.trim() });
51+
} else {
52+
keywords.push(kwdsFromRequest);
53+
}
54+
}
55+
}
4356
const payloadObject = {
4457
at: new Date().toString(),
4558
nid: firstSlot.nid,
4659
nptnid: firstSlot.nptnid,
4760
pid: firstSlot.pid,
4861
url: pageUrl,
4962
lang: (window.navigator.language || window.navigator.languages[0]),
50-
kwds: bidderRequest.ortb2?.site?.keywords || [],
63+
kwds: keywords,
5164
dbg: false,
5265
slts: slots,
5366
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
5467
tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null,
5568
};
69+
5670
const payloadString = JSON.stringify(payloadObject);
5771
return {
5872
method: 'POST',
@@ -129,6 +143,7 @@ function beOpRequestSlotsMaker(bid) {
129143
sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes,
130144
flr: floor,
131145
pid: getValue(bid.params, 'accountId'),
146+
kwds: getValue(bid.params, 'keywords'),
132147
nid: getValue(bid.params, 'networkId'),
133148
nptnid: getValue(bid.params, 'networkPartnerId'),
134149
bid: getBidIdParameter('bidId', bid),

test/spec/modules/beopBidAdapter_spec.js

+52
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,56 @@ describe('BeOp Bid Adapter tests', () => {
216216
expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad');
217217
});
218218
});
219+
220+
describe('Ensure keywords is always array of string', function () {
221+
let bidRequests = [];
222+
afterEach(function () {
223+
bidRequests = [];
224+
});
225+
226+
it('should work with keywords as an array', function () {
227+
let bid = Object.assign({}, validBid);
228+
bid.params.keywords = ['a', 'b'];
229+
bidRequests.push(bid);
230+
config.setConfig({
231+
currency: { adServerCurrency: 'USD' }
232+
});
233+
const request = spec.buildRequests(bidRequests, {});
234+
const payload = JSON.parse(request.data);
235+
const url = request.url;
236+
expect(payload.kwds).to.exist;
237+
expect(payload.kwds).to.include('a');
238+
expect(payload.kwds).to.include('b');
239+
});
240+
241+
it('should work with keywords as a string', function () {
242+
let bid = Object.assign({}, validBid);
243+
bid.params.keywords = 'list of keywords';
244+
bidRequests.push(bid);
245+
config.setConfig({
246+
currency: { adServerCurrency: 'USD' }
247+
});
248+
const request = spec.buildRequests(bidRequests, {});
249+
const payload = JSON.parse(request.data);
250+
const url = request.url;
251+
expect(payload.kwds).to.exist;
252+
expect(payload.kwds).to.include('list of keywords');
253+
});
254+
255+
it('should work with keywords as a string containing a comma', function () {
256+
let bid = Object.assign({}, validBid);
257+
bid.params.keywords = 'list, of, keywords';
258+
bidRequests.push(bid);
259+
config.setConfig({
260+
currency: { adServerCurrency: 'USD' }
261+
});
262+
const request = spec.buildRequests(bidRequests, {});
263+
const payload = JSON.parse(request.data);
264+
const url = request.url;
265+
expect(payload.kwds).to.exist;
266+
expect(payload.kwds).to.include('list');
267+
expect(payload.kwds).to.include('of');
268+
expect(payload.kwds).to.include('keywords');
269+
})
270+
})
219271
});

0 commit comments

Comments
 (0)