Skip to content

Commit

Permalink
add ad slot positioning to payload
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinfive committed Oct 17, 2022
1 parent d4392ca commit 0be448c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
17 changes: 15 additions & 2 deletions modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ 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,
Expand All @@ -64,8 +66,9 @@ 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;
});
Expand Down Expand Up @@ -245,3 +248,13 @@ function getUserId(id, source, uidExt, atype) {
};
}
}

function getOffset(el) {
if (el) {
const rect = el.getBoundingClientRect();
return {
left: rect.left + window.scrollX,
top: rect.top + window.scrollY
};
}
}
35 changes: 35 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 @@ -139,6 +164,16 @@ describe('ConcertAdapter', function () {
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)
})
});

Expand Down

0 comments on commit 0be448c

Please sign in to comment.