Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPO-2971] - Add ad slot positioning to payload #6

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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