Skip to content

Commit

Permalink
Concert Bid Adapter: Add prebid unified ID 2.0 and slot coordinates (p…
Browse files Browse the repository at this point in the history
…rebid#9122)

* collect EIDs for bid request

* add ad slot positioning to payload

Co-authored-by: Brett Bloxom <38990705+BrettBlox@users.noreply.github.com>
  • Loading branch information
2 people authored and JacobKlein26 committed Feb 8, 2023
1 parent c4ff2c0 commit 39802e0
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
46 changes: 44 additions & 2 deletions modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const spec = {
buildRequests: function(validBidRequests, bidderRequest) {
logMessage(validBidRequests);
logMessage(bidderRequest);

const eids = [];

let payload = {
meta: {
prebidVersion: '$prebid.version$',
Expand All @@ -49,6 +52,10 @@ export const spec = {
};

payload.slots = validBidRequests.map(bidRequest => {
collectEid(eids, bidRequest);
const adUnitElement = document.getElementById(bidRequest.adUnitCode)
const coordinates = getOffset(adUnitElement)

let slot = {
name: bidRequest.adUnitCode,
bidId: bidRequest.bidId,
Expand All @@ -59,12 +66,15 @@ export const spec = {
adSlot: bidRequest.params.slot || bidRequest.adUnitCode,
placementId: bidRequest.params.placementId || '',
site: bidRequest.params.site || bidderRequest.refererInfo.page,
ref: bidderRequest.refererInfo.ref
};
ref: bidderRequest.refererInfo.ref,
offsetCoordinates: { x: coordinates?.left, y: coordinates?.top }
}

return slot;
});

payload.meta.eids = eids.filter(Boolean);

logMessage(payload);

return {
Expand Down Expand Up @@ -216,3 +226,35 @@ function consentAllowsPpid(bidderRequest) {

return (uspConsent || gdprConsent);
}

function collectEid(eids, bid) {
if (bid.userId) {
const eid = getUserId(bid.userId.uid2 && bid.userId.uid2.id, 'uidapi.com', undefined, 3)
eids.push(eid)
}
}

function getUserId(id, source, uidExt, atype) {
if (id) {
const uid = { id, atype };

if (uidExt) {
uid.ext = uidExt;
}

return {
source,
uids: [ uid ]
};
}
}

function getOffset(el) {
if (el) {
const rect = el.getBoundingClientRect();
return {
left: rect.left + window.scrollX,
top: rect.top + window.scrollY
};
}
}
56 changes: 56 additions & 0 deletions test/spec/modules/concertBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@ describe('ConcertAdapter', function () {
let bidRequests;
let bidRequest;
let bidResponse;
let element;
let sandbox;

afterEach(function () {
$$PREBID_GLOBAL$$.bidderSettings = {};
sandbox.restore();
});

beforeEach(function () {
element = {
x: 0,
y: 0,
width: 0,
height: 0,
getBoundingClientRect: () => {
return {
width: element.width,
height: element.height,

left: element.x,
top: element.y,
right: element.x + element.width,
bottom: element.y + element.height
};
}
};

$$PREBID_GLOBAL$$.bidderSettings = {
concert: {
storageAllowed: true
Expand Down Expand Up @@ -56,6 +78,9 @@ describe('ConcertAdapter', function () {
]
}
}

sandbox = sinon.sandbox.create();
sandbox.stub(document, 'getElementById').withArgs('desktop_leaderboard_variable').returns(element)
});

describe('spec.isBidRequestValid', function() {
Expand Down Expand Up @@ -119,6 +144,37 @@ describe('ConcertAdapter', function () {

expect(payload.meta.uid).to.equal('foo');
});

it('should add uid2 to eids list if available', function() {
bidRequests[0].userId = { uid2: { id: 'uid123' } }

const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
const meta = payload.meta

expect(meta.eids.length).to.equal(1);
expect(meta.eids[0].uids[0].id).to.equal('uid123')
expect(meta.eids[0].uids[0].atype).to.equal(3)
})

it('should return empty eids list if none are available', function() {
bidRequests[0].userId = { testId: { id: 'uid123' } }
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
const meta = payload.meta

expect(meta.eids.length).to.equal(0);
});

it('should return x/y offset coordiantes when element is present', function() {
Object.assign(element, { x: 100, y: 0, width: 400, height: 400 })
const request = spec.buildRequests(bidRequests, bidRequest);
const payload = JSON.parse(request.data);
const slot = payload.slots[0];

expect(slot.offsetCoordinates.x).to.equal(100)
expect(slot.offsetCoordinates.y).to.equal(0)
})
});

describe('spec.interpretResponse', function() {
Expand Down

0 comments on commit 39802e0

Please sign in to comment.