From f150d713e8a5d4b17be5aed0c4f5dd71eba64596 Mon Sep 17 00:00:00 2001 From: TheMediaGrid <44166371+TheMediaGrid@users.noreply.github.com> Date: Mon, 12 Jul 2021 09:03:19 +0300 Subject: [PATCH] TheMediaGrid: added keywords formatting in the ad request (#7164) * Added TheMediaGridNM Bid Adapter * Updated required params for TheMediaGridNM Bid Adapter * Update TheMediGridNM Bid Adapter * Fix tests for TheMediaGridNM Bid Adapter * Fixes after review for TheMediaGridNM Bid Adapter * Add support of multi-format in TheMediaGrid Bid Adapter * Update sync url for grid and gridNM Bid Adapters * TheMediaGrid Bid Adapter: added keywords adUnit parameter * Update TheMediaGrid Bid Adapter to support keywords from config * Implement new request format for TheMediaGrid Bid Adapter * Fix jwpseg params for TheMediaGrid Bid Adapter * Update unit tests for The Media Grid Bid Adapter * Fix typo in TheMediaGrid Bid Adapter * Added test for jwTargeting in TheMediaGrid Bid Adapter * The new request format was made by default in TheMediaGrid Bid Adapter * Update userId format in ad request for TheMediaGrid Bid Adapter * Added bidFloor parameter for TheMediaGrid Bid Adapter * Fix for review TheMediaGrid Bid Adapter * Support floorModule in TheMediaGrid Bid Adapter * Fix empty bidfloor for TheMediaGrid Bid Adapter * Some change to restart autotests * Fix userIds format for TheMediaGrid Bid Adapter * Remove digitrust userId from TheMediaGrid Bid Adapter * Protocols was added in video section in ad request for TheMediaGrid Bid Adapter * TheMediaGrid: fix trouble with alias using * TheMediaGridNM: fix trouble with alias * TheMediaGrid Bid Adapter: added support of PBAdSlot module * TheMediaGrid Bid Adapter: fix typo * GridNM Bid Adapter: use absent in params data from mediaTypes * GridNM Bid Adapter: fix md file + add advertiserDomains support * TheMediaGrid and gridNM Bid Adapter: minor netRevenue fixes * gridNM Bid Adapter updates after review * TheMediaGrid Bid Adapter: fix keywords workflow * fix testing and kick off lgtm again Co-authored-by: Chris Huie --- modules/gridBidAdapter.js | 54 ++++++++++++++++++++++-- test/spec/modules/gridBidAdapter_spec.js | 36 ++++++++++++++-- 2 files changed, 83 insertions(+), 7 deletions(-) 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' } + ] } ] }