Skip to content

Commit adf3b9a

Browse files
prBigBrotherjorgeluisrocha
authored andcommitted
Brightcom Bid adapter: add support for uspConsent, coppa, schain, userIdAsEids, userId (prebid#9063)
* Brightcom: add support for uspConsent, coppa, schain, userIdAsEids, userId * Brightcom: tests for updates
1 parent e104f88 commit adf3b9a

File tree

2 files changed

+124
-11
lines changed

2 files changed

+124
-11
lines changed

modules/brightcomBidAdapter.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ function buildRequests(bidReqs, bidderRequest) {
7575
deepSetValue(brightcomBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
7676
}
7777

78+
if (bidderRequest && bidderRequest.uspConsent) {
79+
deepSetValue(brightcomBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent);
80+
}
81+
82+
if (config.getConfig('coppa') === true) {
83+
deepSetValue(brightcomBidReq, 'regs.coppa', 1);
84+
}
85+
86+
if (bidReqs[0] && bidReqs[0].schain) {
87+
deepSetValue(brightcomBidReq, 'source.ext.schain', bidReqs[0].schain)
88+
}
89+
90+
if (bidReqs[0] && bidReqs[0].userIdAsEids) {
91+
deepSetValue(brightcomBidReq, 'user.ext.eids', bidReqs[0].userIdAsEids || [])
92+
}
93+
94+
if (bidReqs[0] && bidReqs[0].userId) {
95+
deepSetValue(brightcomBidReq, 'user.ext.ids', bidReqs[0].userId || [])
96+
}
97+
7898
return {
7999
method: 'POST',
80100
url: URL,
@@ -103,7 +123,7 @@ function interpretResponse(serverResponse) {
103123
logWarn('Brightcom server returned empty/non-json response: ' + JSON.stringify(serverResponse.body));
104124
return [];
105125
}
106-
const { body: {id, seatbid} } = serverResponse;
126+
const {body: {id, seatbid}} = serverResponse;
107127
try {
108128
const brightcomBidResponses = [];
109129
if (id &&
@@ -164,9 +184,9 @@ function _isViewabilityMeasurable(element) {
164184
return !_isIframe() && element !== null;
165185
}
166186

167-
function _getViewability(element, topWin, { w, h } = {}) {
187+
function _getViewability(element, topWin, {w, h} = {}) {
168188
return getWindowTop().document.visibilityState === 'visible'
169-
? _getPercentInView(element, topWin, { w, h })
189+
? _getPercentInView(element, topWin, {w, h})
170190
: 0;
171191
}
172192

@@ -182,8 +202,8 @@ function _getMinSize(sizes) {
182202
return sizes.reduce((min, size) => size.h * size.w < min.h * min.w ? size : min);
183203
}
184204

185-
function _getBoundingBox(element, { w, h } = {}) {
186-
let { width, height, left, top, right, bottom } = element.getBoundingClientRect();
205+
function _getBoundingBox(element, {w, h} = {}) {
206+
let {width, height, left, top, right, bottom} = element.getBoundingClientRect();
187207

188208
if ((width === 0 || height === 0) && w && h) {
189209
width = w;
@@ -192,7 +212,7 @@ function _getBoundingBox(element, { w, h } = {}) {
192212
bottom = top + h;
193213
}
194214

195-
return { width, height, left, top, right, bottom };
215+
return {width, height, left, top, right, bottom};
196216
}
197217

198218
function _getIntersectionOfRects(rects) {
@@ -225,16 +245,16 @@ function _getIntersectionOfRects(rects) {
225245
return bbox;
226246
}
227247

228-
function _getPercentInView(element, topWin, { w, h } = {}) {
229-
const elementBoundingBox = _getBoundingBox(element, { w, h });
248+
function _getPercentInView(element, topWin, {w, h} = {}) {
249+
const elementBoundingBox = _getBoundingBox(element, {w, h});
230250

231251
// Obtain the intersection of the element and the viewport
232-
const elementInViewBoundingBox = _getIntersectionOfRects([ {
252+
const elementInViewBoundingBox = _getIntersectionOfRects([{
233253
left: 0,
234254
top: 0,
235255
right: topWin.innerWidth,
236256
bottom: topWin.innerHeight
237-
}, elementBoundingBox ]);
257+
}, elementBoundingBox]);
238258

239259
let elementInViewArea, elementTotalArea;
240260

test/spec/modules/brightcomBidAdapter_spec.js

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai';
22
import * as utils from 'src/utils.js';
33
import { spec } from 'modules/brightcomBidAdapter.js';
44
import { newBidder } from 'src/adapters/bidderFactory.js';
5+
import {config} from '../../../src/config';
56

67
const URL = 'https://brightcombid.marphezis.com/hb';
78

@@ -52,7 +53,21 @@ describe('brightcomBidAdapter', function() {
5253
},
5354
'bidId': '5fb26ac22bde4',
5455
'bidderRequestId': '4bf93aeb730cb9',
55-
'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e'
56+
'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e',
57+
'schain': {
58+
'ver': '1.0',
59+
'complete': 1,
60+
'nodes': [
61+
{
62+
'asi': 'exchange1.com',
63+
'sid': '1234',
64+
'hp': 1,
65+
'rid': 'bid-request-1',
66+
'name': 'publisher',
67+
'domain': 'publisher.com'
68+
}
69+
]
70+
},
5671
}];
5772

5873
sandbox = sinon.sandbox.create();
@@ -167,6 +182,84 @@ describe('brightcomBidAdapter', function() {
167182
expect(data.user.ext.consent).to.equal(consentString);
168183
});
169184

185+
it('sends us_privacy', function () {
186+
const bidderRequest = {
187+
uspConsent: '1YYY'
188+
};
189+
const data = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data)
190+
191+
expect(data.regs).to.not.equal(null);
192+
expect(data.regs.ext).to.not.equal(null);
193+
expect(data.regs.ext.us_privacy).to.equal('1YYY');
194+
});
195+
196+
it('sends coppa', function () {
197+
sandbox.stub(config, 'getConfig').withArgs('coppa').returns(true);
198+
199+
const data = JSON.parse(spec.buildRequests(bidRequests).data)
200+
expect(data.regs).to.not.be.undefined;
201+
expect(data.regs.coppa).to.equal(1);
202+
});
203+
204+
it('sends schain', function () {
205+
const data = JSON.parse(spec.buildRequests(bidRequests).data);
206+
expect(data).to.not.be.undefined;
207+
expect(data.source).to.not.be.undefined;
208+
expect(data.source.ext).to.not.be.undefined;
209+
expect(data.source.ext.schain).to.not.be.undefined;
210+
expect(data.source.ext.schain.complete).to.equal(1);
211+
expect(data.source.ext.schain.ver).to.equal('1.0');
212+
expect(data.source.ext.schain.nodes).to.not.be.undefined;
213+
expect(data.source.ext.schain.nodes).to.lengthOf(1);
214+
expect(data.source.ext.schain.nodes[0].asi).to.equal('exchange1.com');
215+
expect(data.source.ext.schain.nodes[0].sid).to.equal('1234');
216+
expect(data.source.ext.schain.nodes[0].hp).to.equal(1);
217+
expect(data.source.ext.schain.nodes[0].rid).to.equal('bid-request-1');
218+
expect(data.source.ext.schain.nodes[0].name).to.equal('publisher');
219+
expect(data.source.ext.schain.nodes[0].domain).to.equal('publisher.com');
220+
});
221+
222+
it('sends user eid parameters', function () {
223+
bidRequests[0].userIdAsEids = [{
224+
source: 'pubcid.org',
225+
uids: [{
226+
id: 'userid_pubcid'
227+
}]
228+
}, {
229+
source: 'adserver.org',
230+
uids: [{
231+
id: 'userid_ttd',
232+
ext: {
233+
rtiPartner: 'TDID'
234+
}
235+
}]
236+
}
237+
];
238+
239+
const data = JSON.parse(spec.buildRequests(bidRequests).data);
240+
241+
expect(data.user).to.not.be.undefined;
242+
expect(data.user.ext).to.not.be.undefined;
243+
expect(data.user.ext.eids).to.not.be.undefined;
244+
expect(data.user.ext.eids).to.deep.equal(bidRequests[0].userIdAsEids);
245+
});
246+
247+
it('sends user id parameters', function () {
248+
const userId = {
249+
sharedid: {
250+
id: '01*******',
251+
third: '01E*******'
252+
}
253+
};
254+
255+
bidRequests[0].userId = userId;
256+
257+
const data = JSON.parse(spec.buildRequests(bidRequests).data);
258+
expect(data.user).to.not.be.undefined;
259+
expect(data.user.ext).to.not.be.undefined;
260+
expect(data.user.ext.ids).is.deep.equal(userId);
261+
});
262+
170263
context('when element is fully in view', function() {
171264
it('returns 100', function() {
172265
Object.assign(element, { width: 600, height: 400 });

0 commit comments

Comments
 (0)