Skip to content

Commit

Permalink
Yieldmo Bid Adapter : send topics in the Bid Request (prebid#10892)
Browse files Browse the repository at this point in the history
* Adding topics to bid request

Getting topics and adding them to bid request.

* converting topics to numbers

* Adding unit tests
  • Loading branch information
desidiver authored Jan 30, 2024
1 parent 0815414 commit 951d7d0
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
28 changes: 26 additions & 2 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const spec = {
const videoBidRequests = bidRequests.filter(request => hasVideoMediaType(request));
let serverRequests = [];
const eids = getEids(bidRequests[0]) || [];

const topicsData = getTopics(bidderRequest);
if (bannerBidRequests.length > 0) {
let serverRequest = {
pbav: '$prebid.version$',
Expand All @@ -97,6 +97,9 @@ export const spec = {
}),
us_privacy: deepAccess(bidderRequest, 'uspConsent') || '',
};
if (topicsData) {
serverRequest.topics = topicsData;
}

if (canAccessTopWindow()) {
serverRequest.pr = (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '';
Expand Down Expand Up @@ -161,6 +164,9 @@ export const spec = {

if (videoBidRequests.length > 0) {
const serverRequest = openRtbRequest(videoBidRequests, bidderRequest);
if (topicsData) {
serverRequest.topics = topicsData;
}
if (eids.length) {
serverRequest.user = { eids };
};
Expand Down Expand Up @@ -416,10 +422,28 @@ function openRtbRequest(bidRequests, bidderRequest) {
openRtbRequest.auctionId = bidRequests[0].auctionId;
}
populateOpenRtbGdpr(openRtbRequest, bidderRequest);

return openRtbRequest;
}

function getTopics(bidderRequest) {
const userData = deepAccess(bidderRequest, 'ortb2.user.data') || [];
const topicsData = userData.filter((dataObj) => {
const segtax = dataObj.ext?.segtax;
return segtax >= 600 && segtax <= 609;
})[0];

if (topicsData) {
let topicsObject = {
taxonomy: topicsData.ext.segtax,
classifier: topicsData.ext.segclass,
// topics needs to be array of numbers
topics: Object.values(topicsData.segment).map(i => Number(i)),
};
return topicsObject;
}
return null;
}

/**
* @param {BidRequest} bidRequest bidder request object.
* @return Object OpenRTB's 'imp' (impression) object
Expand Down
47 changes: 47 additions & 0 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,25 @@ describe('YieldmoAdapter', function () {
expect(placementInfo).to.include('"gpid":"/6355419/Travel/Europe/France/Paris"');
});

it('should add topics to the banner bid request', function () {
const biddata = build([mockBannerBid()], mockBidderRequest({ortb2: { user: {
data: [
{
ext: {
segtax: 600,
segclass: '2206021246',
},
segment: ['7', '8', '9'],
},
],
}}}));
expect(biddata[0].data.topics).to.deep.equal({
taxonomy: 600,
classifier: '2206021246',
topics: [7, 8, 9],
});
});

it('should add eids to the banner bid request', function () {
const params = {
userIdAsEids: [{
Expand Down Expand Up @@ -620,6 +639,34 @@ describe('YieldmoAdapter', function () {
};
expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids);
});

it('should add topics to the bid request', function () {
let videoBidder = mockBidderRequest(
{
ortb2: {
user: {
data: [
{
ext: {
segtax: 600,
segclass: '2206021246',
},
segment: ['7', '8', '9'],
},
],
},
},
},
[mockVideoBid()]
);
let payload = buildAndGetData([mockVideoBid()], 0, videoBidder);
expect(payload.topics).to.deep.equal({
taxonomy: 600,
classifier: '2206021246',
topics: [7, 8, 9],
});
});

it('should add device info to payload if available', function () {
let videoBidder = mockBidderRequest({ ortb2: {
device: {
Expand Down

0 comments on commit 951d7d0

Please sign in to comment.