Skip to content

Commit

Permalink
BeOp Bid Adapter : update keywords management (prebid#9166)
Browse files Browse the repository at this point in the history
* 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 (#9)

* Keywords have to be an array of string

* Last check if isStr

* Fix linting errors

* Fix tests
  • Loading branch information
sebrobert committed Nov 17, 2022
1 parent c3f789b commit c7da527
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
19 changes: 17 additions & 2 deletions modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -40,19 +40,33 @@ 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,
nptnid: firstSlot.nptnid,
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',
Expand Down Expand Up @@ -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),
Expand Down
52 changes: 52 additions & 0 deletions test/spec/modules/beopBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})
})
});

0 comments on commit c7da527

Please sign in to comment.