Skip to content

Commit

Permalink
TheMediaGrid: added ortb2.user.data to gridNMBidAdapter (#8652)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMediaGrid authored and ahmadlob committed Jul 27, 2022
1 parent bffb305 commit 8aecf19
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
49 changes: 45 additions & 4 deletions modules/gridNMBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { isStr, deepAccess, isArray, isNumber, logError, logWarn, parseGPTSingleSizeArrayToRtbSize } from '../src/utils.js';
import {
isStr,
deepAccess,
isArray,
isNumber,
logError,
logWarn,
parseGPTSingleSizeArrayToRtbSize,
mergeDeep
} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
import { VIDEO } from '../src/mediaTypes.js';
Expand Down Expand Up @@ -153,9 +162,7 @@ export const spec = {
user = {
data: [{
name: 'iow_labs_pub_data',
segment: jwpseg.map((seg) => {
return {name: 'jwpseg', value: seg};
})
segment: segmentProcessing(jwpseg, 'jwpseg'),
}]
};
}
Expand All @@ -174,9 +181,27 @@ export const spec = {
user.ext = userExt;
}

const ortb2UserData = deepAccess(bidderRequest, 'ortb2.user.data');
if (ortb2UserData && ortb2UserData.length) {
if (!user) {
user = { data: [] };
}
user = mergeDeep(user, {
data: [...ortb2UserData]
});
}

if (user) {
request.user = user;
}
const site = deepAccess(bidderRequest, 'ortb2.site');
if (site) {
const data = deepAccess(site, 'content.data');
if (data && data.length) {
const siteContent = request.site.content || {};
request.site.content = mergeDeep(siteContent, { data });
}
}

if (gdprConsent && gdprConsent.gdprApplies) {
request.regs = {
Expand Down Expand Up @@ -408,4 +433,20 @@ export function getSyncUrl() {
return SYNC_URL;
}

function segmentProcessing(segment, forceSegName) {
return segment
.map((seg) => {
const value = seg && (seg.value || seg.id || seg);
if (typeof value === 'string' || typeof value === 'number') {
return {
value: value.toString(),
...(forceSegName && { name: forceSegName }),
...(seg.name && { name: seg.name }),
};
}
return null;
})
.filter((seg) => !!seg);
}

registerBidder(spec);
32 changes: 32 additions & 0 deletions test/spec/modules/gridNMBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ describe('TheMediaGridNM Adapter', function () {
}
];

it('if content and segment is present in jwTargeting, payload must have right params', function () {
const jsContent = {id: 'test_jw_content_id'};
const jsSegments = ['test_seg_1', 'test_seg_2'];
const bidRequestsWithJwTargeting = bidRequests.map((bid) => {
return Object.assign({
rtd: {
jwplayer: {
targeting: {
segments: jsSegments,
content: jsContent
}
}
}
}, bid);
});
const requests = spec.buildRequests(bidRequestsWithJwTargeting, bidderRequest);
requests.forEach((req, i) => {
const payload = req.data;
expect(req).to.have.property('data');
expect(payload).to.have.property('user');
expect(payload.user.data).to.deep.equal([{
name: 'iow_labs_pub_data',
segment: [
{name: 'jwpseg', value: jsSegments[0]},
{name: 'jwpseg', value: jsSegments[1]}
]
}]);
expect(payload).to.have.property('site');
expect(payload.site.content).to.deep.equal(jsContent);
});
});

it('should attach valid params to the tag', function () {
const requests = spec.buildRequests(bidRequests, bidderRequest);
const requestsSizes = ['300x250,300x600', '728x90'];
Expand Down

0 comments on commit 8aecf19

Please sign in to comment.