diff --git a/modules/gridBidAdapter.js b/modules/gridBidAdapter.js index 16f8ff11574..854b82aa84d 100644 --- a/modules/gridBidAdapter.js +++ b/modules/gridBidAdapter.js @@ -213,9 +213,12 @@ export const spec = { } if (pageKeywords) { - request.ext = { - keywords: pageKeywords - }; + pageKeywords = reformatKeywords(pageKeywords); + if (pageKeywords) { + request.ext = { + keywords: pageKeywords + }; + } } if (gdprConsent && gdprConsent.gdprApplies) { @@ -419,6 +422,51 @@ function createBannerRequest(bid, mediaType) { return result; } +function reformatKeywords(pageKeywords) { + const formatedPageKeywords = {}; + Object.keys(pageKeywords).forEach((name) => { + const keywords = pageKeywords[name]; + if (keywords) { + if (name === 'site' || name === 'user') { + const formatedKeywords = {}; + Object.keys(keywords).forEach((pubName) => { + if (Array.isArray(keywords[pubName])) { + const formatedPublisher = []; + keywords[pubName].forEach((pubItem) => { + if (typeof pubItem === 'object' && pubItem.name) { + const formatedPubItem = { name: pubItem.name, segments: [] }; + Object.keys(pubItem).forEach((key) => { + if (Array.isArray(pubItem[key])) { + pubItem[key].forEach((keyword) => { + if (keyword) { + if (typeof keyword === 'string') { + formatedPubItem.segments.push({ name: key, value: keyword }); + } else if (key === 'segments' && typeof keyword.name === 'string' && typeof keyword.value === 'string') { + formatedPubItem.segments.push(keyword); + } + } + }); + } + }); + if (formatedPubItem.segments.length) { + formatedPublisher.push(formatedPubItem); + } + } + }); + if (formatedPublisher.length) { + formatedKeywords[pubName] = formatedPublisher; + } + } + }); + formatedPageKeywords[name] = formatedKeywords; + } else { + formatedPageKeywords[name] = keywords; + } + } + }); + return Object.keys(formatedPageKeywords).length && formatedPageKeywords; +} + function outstreamRender (bid) { bid.renderer.push(() => { window.ANOutstreamVideo.renderAd({ diff --git a/test/spec/modules/gridBidAdapter_spec.js b/test/spec/modules/gridBidAdapter_spec.js index 2e5d2e63677..1ec0200885c 100644 --- a/test/spec/modules/gridBidAdapter_spec.js +++ b/test/spec/modules/gridBidAdapter_spec.js @@ -412,6 +412,17 @@ describe('TheMediaGrid Adapter', function () { 'topic': ['stress', 'fear'] } ] + }, + 'user': { + 'formatedPublisher': [ + { + 'name': 'fomatedName', + 'segments': [ + { 'name': 'segName1', 'value': 'segVal1' }, + { 'name': 'segName2', 'value': 'segVal2' } + ] + } + ] } }; const bidRequestWithKW = { ...bidRequests[0], params: { ...bidRequests[0].params, keywords } } @@ -423,22 +434,39 @@ describe('TheMediaGrid Adapter', function () { 'somePublisher': [ { 'name': 'someName', - 'brandsafety': ['disaster'], - 'topic': ['stress', 'fear'] + 'segments': [ + { 'name': 'brandsafety', 'value': 'disaster' }, + { 'name': 'topic', 'value': 'stress' }, + { 'name': 'topic', 'value': 'fear' } + ] } ], 'ortb2': [ { 'name': 'keywords', - 'keywords': ['bar'] + 'segments': [ + { 'name': 'keywords', 'value': 'bar' } + ] } ] }, 'user': { + 'formatedPublisher': [ + { + 'name': 'fomatedName', + 'segments': [ + { 'name': 'segName1', 'value': 'segVal1' }, + { 'name': 'segName2', 'value': 'segVal2' } + ] + } + ], 'ortb2': [ { 'name': 'keywords', - 'keywords': ['foo', 'any'] + 'segments': [ + { 'name': 'keywords', 'value': 'foo' }, + { 'name': 'keywords', 'value': 'any' } + ] } ] }