Skip to content

Commit

Permalink
TheMediaGrid Bid Adapter: fix keywords workflow (prebid#7130)
Browse files Browse the repository at this point in the history
* 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 <phoenixtechnerd@gmail.com>
  • Loading branch information
2 people authored and agrandes-tappx committed Sep 29, 2021
1 parent fd1547b commit 457e525
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
52 changes: 28 additions & 24 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ export const spec = {
}
const {params: {uid, keywords}, mediaTypes, bidId, adUnitCode, rtd, ortb2Imp} = bid;
bidsMap[bidId] = bid;
if (!pageKeywords && !utils.isEmpty(keywords)) {
pageKeywords = utils.transformBidderParamKeywords(keywords);
}
const bidFloor = _getFloor(mediaTypes || {}, bid);
const jwTargeting = rtd && rtd.jwplayer && rtd.jwplayer.targeting;
if (jwTargeting) {
Expand All @@ -104,6 +101,12 @@ export const spec = {
impObj.ext.gpid = impObj.ext.data.adserver.adslot;
}
}
if (!utils.isEmpty(keywords)) {
if (!pageKeywords) {
pageKeywords = keywords;
}
impObj.ext.bidder = { keywords };
}

if (bidFloor) {
impObj.bidfloor = bidFloor;
Expand Down Expand Up @@ -185,17 +188,28 @@ export const spec = {
request.user = user;
}

const configKeywords = utils.transformBidderParamKeywords({
'user': utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null,
'context': utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null
});
const userKeywords = utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null;
const siteKeywords = utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null;

if (configKeywords.length) {
pageKeywords = (pageKeywords || []).concat(configKeywords);
if (userKeywords) {
pageKeywords = pageKeywords || {};
pageKeywords.user = pageKeywords.user || {};
pageKeywords.user.ortb2 = [
{
name: 'keywords',
keywords: userKeywords.split(','),
}
];
}

if (pageKeywords && pageKeywords.length > 0) {
pageKeywords.forEach(deleteValues);
if (siteKeywords) {
pageKeywords = pageKeywords || {};
pageKeywords.site = pageKeywords.site || {};
pageKeywords.site.ortb2 = [
{
name: 'keywords',
keywords: siteKeywords.split(','),
}
];
}

if (pageKeywords) {
Expand Down Expand Up @@ -311,16 +325,6 @@ function _getFloor (mediaTypes, bid) {
return floor;
}

function isPopulatedArray(arr) {
return !!(utils.isArray(arr) && arr.length > 0);
}

function deleteValues(keyPairObj) {
if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') {
delete keyPairObj.value;
}
}

function _getBidFromResponse(respItem) {
if (!respItem) {
utils.logError(LOG_ERROR_MESS.emptySeatbid);
Expand All @@ -341,11 +345,11 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) {
const bid = bidRequest.bidsMap[serverBid.impid];
if (bid) {
const bidResponse = {
requestId: bid.bidId, // bid.bidderRequestId,
requestId: bid.bidId, // bid.bidderRequestId
cpm: serverBid.price,
width: serverBid.w,
height: serverBid.h,
creativeId: serverBid.auid, // bid.bidId,
creativeId: serverBid.auid, // bid.bidId
currency: 'USD',
netRevenue: true,
ttl: TIME_TO_LIVE,
Expand Down
42 changes: 39 additions & 3 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,47 @@ describe('TheMediaGrid Adapter', function () {

it('should contain the keyword values if it present in ortb2.(site/user)', function () {
const getConfigStub = sinon.stub(config, 'getConfig').callsFake(
arg => arg === 'ortb2.user' ? {'keywords': 'foo'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null));
const request = spec.buildRequests([bidRequests[0]], bidderRequest);
arg => arg === 'ortb2.user' ? {'keywords': 'foo,any'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null));
const keywords = {
'site': {
'somePublisher': [
{
'name': 'someName',
'brandsafety': ['disaster'],
'topic': ['stress', 'fear']
}
]
}
};
const bidRequestWithKW = { ...bidRequests[0], params: { ...bidRequests[0].params, keywords } }
const request = spec.buildRequests([bidRequestWithKW], bidderRequest);
expect(request.data).to.be.an('string');
const payload = parseRequest(request.data);
expect(payload.ext.keywords).to.deep.equal([{'key': 'user', 'value': ['foo']}, {'key': 'context', 'value': ['bar']}]);
expect(payload.ext.keywords).to.deep.equal({
'site': {
'somePublisher': [
{
'name': 'someName',
'brandsafety': ['disaster'],
'topic': ['stress', 'fear']
}
],
'ortb2': [
{
'name': 'keywords',
'keywords': ['bar']
}
]
},
'user': {
'ortb2': [
{
'name': 'keywords',
'keywords': ['foo', 'any']
}
]
}
});
getConfigStub.restore();
});

Expand Down

0 comments on commit 457e525

Please sign in to comment.