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

Relevant Bid Adapter : support s2s #10610

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion modules/relevantdigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ export const spec = {
isBidRequestValid: (bid) => bid.params?.placementId && getBidderConfig([bid]).complete,

/** Trigger impression-pixel */
onBidWon: ({pbsWurl}) => pbsWurl && triggerPixel(pbsWurl),
onBidWon(bid) {
if (bid.pbsWurl) {
triggerPixel(bid.pbsWurl)
}
if (bid.burl) {
triggerPixel(bid.burl)
}
},

/** Build BidRequest for PBS */
buildRequests(bidRequests, bidderRequest) {
Expand Down Expand Up @@ -193,6 +200,24 @@ export const spec = {
});
return syncs;
},

/** If server side, transform bid params if needed */
transformBidParams(params, isOrtb, adUnit, bidRequests) {
if (!params.placementId) {
return;
}
const bid = bidRequests.flatMap(req => req.adUnitsS2SCopy || []).flatMap((adUnit) => adUnit.bids).find((bid) => bid.params?.placementId === params.placementId);
if (!bid) {
return;
}
const cfg = getBidderConfig([bid]);
FIELDS.forEach(({ name }) => {
if (cfg[name] && !params[name]) {
params[name] = cfg[name];
}
});
return params;
},
};

registerBidder(spec);
92 changes: 86 additions & 6 deletions test/spec/modules/relevantdigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {spec, resetBidderConfigs} from 'modules/relevantdigitalBidAdapter.js';
import { parseUrl, deepClone } from 'src/utils.js';
import { config } from 'src/config.js';
import CONSTANTS from 'src/constants.json';

import adapterManager, {
} from 'src/adapterManager.js';

const expect = require('chai').expect;

Expand All @@ -9,14 +14,29 @@ const ACCOUNT_ID = 'example_account_id';
const TEST_DOMAIN = 'example.com';
const TEST_PAGE = `https://${TEST_DOMAIN}/page.html`;

const BID_REQUEST =
{
'bidder': 'relevantdigital',
const CONFIG = {
enabled: true,
endpoint: CONSTANTS.S2S.DEFAULT_ENDPOINT,
timeout: 1000,
maxBids: 1,
adapter: 'prebidServer',
bidders: ['relevantdigital'],
accountId: 'abc'
};

const ADUNIT_CODE = '/19968336/header-bid-tag-0';

const BID_PARAMS = {
'params': {
'placementId': PLACEMENT_ID,
'accountId': ACCOUNT_ID,
'pbsHost': PBS_HOST,
},
'pbsHost': PBS_HOST
}
};

const BID_REQUEST = {
'bidder': 'relevantdigital',
...BID_PARAMS,
'ortb2Imp': {
'ext': {
'tid': 'e13391ea-00f3-495d-99a6-d937990d73a9'
Expand All @@ -32,7 +52,7 @@ const BID_REQUEST =
]
}
},
'adUnitCode': '/19968336/header-bid-tag-0',
'adUnitCode': ADUNIT_CODE,
'transactionId': 'e13391ea-00f3-495d-99a6-d937990d73a9',
'sizes': [
[
Expand Down Expand Up @@ -292,4 +312,64 @@ describe('Relevant Digital Bid Adaper', function () {
expect(allSyncs).to.deep.equal(expectedResult)
});
});
describe('transformBidParams', function () {
beforeEach(() => {
config.setConfig({
s2sConfig: CONFIG,
});
});
afterEach(() => {
config.resetConfig();
});

const adUnit = (params) => ({
code: ADUNIT_CODE,
bids: [
{
bidder: 'relevantdigital',
adUnitCode: ADUNIT_CODE,
params,
}
]
});

const request = (params) => adapterManager.makeBidRequests([adUnit(params)], 123, 'auction-id', 123, [], {})[0];

it('transforms adunit bid params and config params correctly', function () {
config.setConfig({
relevantdigital: {
pbsHost: PBS_HOST,
accountId: ACCOUNT_ID,
},
});
const adUnitParams = { placementId: PLACEMENT_ID };
const expextedTransformedBidParams = {
...BID_PARAMS.params, pbsHost: `https://${BID_PARAMS.params.pbsHost}`, 'pbsBufferMs': 250
};
expect(spec.transformBidParams(adUnitParams, null, null, [request(adUnitParams)])).to.deep.equal(expextedTransformedBidParams);
});
it('transforms adunit bid params correctly', function () {
const adUnitParams = { ...BID_PARAMS.params, pbsHost: 'host.relevant-digital.com', pbsBufferMs: 500 };
const expextedTransformedBidParams = {
...BID_PARAMS.params, pbsHost: 'host.relevant-digital.com', pbsBufferMs: 500
};
expect(spec.transformBidParams(adUnitParams, null, null, [request(adUnitParams)])).to.deep.equal(expextedTransformedBidParams);
});
it('transforms adunit bid params correctly', function () {
const adUnitParams = { ...BID_PARAMS.params, pbsHost: 'host.relevant-digital.com', pbsBufferMs: 500 };
const expextedTransformedBidParams = {
...BID_PARAMS.params, pbsHost: 'host.relevant-digital.com', pbsBufferMs: 500
};
expect(spec.transformBidParams(adUnitParams, null, null, [request(adUnitParams)])).to.deep.equal(expextedTransformedBidParams);
});
it('does not transform bid params if placementId is missing', function () {
const adUnitParams = { ...BID_PARAMS.params, placementId: null };
expect(spec.transformBidParams(adUnitParams, null, null, [request(adUnitParams)])).to.equal(undefined);
});
it('does not transform bid params s2s config is missing', function () {
config.resetConfig();
const adUnitParams = BID_PARAMS.params;
expect(spec.transformBidParams(adUnitParams, null, null, [request(adUnitParams)])).to.equal(undefined);
});
})
});