Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeOp Bid Adapter : update keywords management #9166

Merged
merged 11 commits into from
Nov 17, 2022
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');
})
})
});