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 Sep 27, 2022
1 parent bcc6cd5 commit 795edd8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
18 changes: 16 additions & 2 deletions modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const spec = {
};

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

let slot = {
name: bidRequest.adUnitCode,
bidId: bidRequest.bidId,
Expand All @@ -59,8 +62,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 @@ -216,3 +220,13 @@ function consentAllowsPpid(bidderRequest) {

return (uspConsent || gdprConsent);
}

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 @@ -119,6 +144,16 @@ describe('ConcertAdapter', function () {

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

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 795edd8

Please sign in to comment.