diff --git a/modules/dailymotionBidAdapter.js b/modules/dailymotionBidAdapter.js index ff8e52d6d11..2be5edad78e 100644 --- a/modules/dailymotionBidAdapter.js +++ b/modules/dailymotionBidAdapter.js @@ -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, diff --git a/test/spec/modules/dailymotionBidAdapter_spec.js b/test/spec/modules/dailymotionBidAdapter_spec.js index e5a20fa6b6e..a102c26dca2 100644 --- a/test/spec/modules/dailymotionBidAdapter_spec.js +++ b/test/spec/modules/dailymotionBidAdapter_spec.js @@ -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' }], + }, + ], }, }, }, @@ -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' }], + }, + ], }, }, }, @@ -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,