Skip to content

Commit

Permalink
Dailymotion Bid Adaptor: get iabcats from ortb2.site.content.data
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Siow committed Apr 18, 2024
1 parent cff7c34 commit 4627162
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
26 changes: 20 additions & 6 deletions modules/dailymotionBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,31 @@ function getVideoMetadata(bidRequest, bidderRequest) {
...videoBidderParams, // Bidder Specific overrides
};

// Store as object keys to ensure uniqueness
const iabcat1 = {};
const iabcat2 = {};

deepAccess(bidderRequest, 'ortb2.site.content.data', []).forEach((data) => {
if ([4, 5, 6, 7].includes(data?.ext?.segtax)) {
(Array.isArray(data.segment) ? data.segment : []).forEach((segment) => {
if (typeof segment.id === 'string') {
// See https://docs.prebid.org/features/firstPartyData.html#segments-and-taxonomy
// Only take IAB cats of taxonomy V1
if (data.ext.segtax === 4) iabcat1[segment.id] = 1;
// Only take IAB cats of taxonomy V2 or higher
if ([5, 6, 7].includes(data.ext.segtax)) iabcat2[segment.id] = 1;
}
});
}
});

const videoMetadata = {
description: videoParams.description || '',
duration: videoParams.duration || 0,
iabcat1: deepAccess(bidderRequest, 'ortb2.site.content.cat', [])
// Only take IAB cats of taxonomy V1
.filter(cat => cat.toLowerCase().indexOf('iab-') === 0),
iabcat1: Object.keys(iabcat1),
iabcat2: Array.isArray(videoParams.iabcat2)
? videoParams.iabcat2
// Only take IAB cats of taxonomy V2 or higher by excluding "IAB-" type categories
: deepAccess(bidderRequest, 'ortb2.site.content.cat', [])
.filter(cat => cat.toLowerCase().indexOf('iab-') !== 0),
: Object.keys(iabcat2),
id: videoParams.id || '',
lang: videoParams.lang || '',
private: videoParams.private || false,
Expand Down
56 changes: 53 additions & 3 deletions test/spec/modules/dailymotionBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,18 @@ describe('dailymotionBidAdapterTests', () => {
},
site: {
content: {
cat: ['IAB-1', '200'],
data: [
{
name: 'dataprovider.com',
ext: { segtax: 4 },
segment: [{ id: 'IAB-1' }],
},
{
name: 'dataprovider.com',
ext: { segtax: 5 },
segment: [{ id: '200' }],
},
],
},
},
},
Expand Down Expand Up @@ -171,7 +182,46 @@ describe('dailymotionBidAdapterTests', () => {
},
site: {
content: {
cat: ['6', '17'],
data: [
undefined, // Undefined to check proper handling of edge cases
{}, // Empty object to check proper handling of edge cases
{ ext: {} }, // Empty ext to check proper handling of edge cases
{
name: 'dataprovider.com',
ext: { segtax: 22 }, // Invalid segtax to check proper handling of edge cases
segment: [{ id: '400' }],
},
{
name: 'dataprovider.com',
ext: { segtax: 5 },
segment: undefined, // Invalid segment to check proper handling of edge cases
},
{
name: 'dataprovider.com',
ext: { segtax: 4 },
segment: undefined, // Invalid segment to check proper handling of edge cases
},
{
name: 'dataprovider.com',
ext: { segtax: 4 },
segment: [{ id: 2222 }], // Invalid segment id to check proper handling of edge cases
},
{
name: 'dataprovider.com',
ext: { segtax: 5 },
segment: [{ id: '6' }],
},
{
name: 'dataprovider.com',
ext: { segtax: 5 },
segment: [{ id: '6' }], // Check that same cat won't be duplicated
},
{
name: 'dataprovider.com',
ext: { segtax: 5 },
segment: [{ id: '17' }, { id: '20' }],
},
],
},
},
},
Expand Down Expand Up @@ -206,7 +256,7 @@ describe('dailymotionBidAdapterTests', () => {
description: bidRequestData[0].mediaTypes.video.description,
// No iabcat1 here because nothing matches taxonomy
iabcat1: [],
iabcat2: bidderRequestData.ortb2.site.content.cat,
iabcat2: ['6', '17', '20'],
id: bidRequestData[0].params.video.id,
lang: bidRequestData[0].params.video.lang,
private: bidRequestData[0].params.video.private,
Expand Down

0 comments on commit 4627162

Please sign in to comment.