From 0be448c2e5b3b20a19528aa3b5ae6181dbc43ac8 Mon Sep 17 00:00:00 2001 From: antoin Date: Tue, 27 Sep 2022 15:02:28 -0400 Subject: [PATCH] add ad slot positioning to payload --- modules/concertBidAdapter.js | 17 ++++++++-- test/spec/modules/concertBidAdapter_spec.js | 35 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/modules/concertBidAdapter.js b/modules/concertBidAdapter.js index 0e448f66b55..620e77a5a08 100644 --- a/modules/concertBidAdapter.js +++ b/modules/concertBidAdapter.js @@ -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, @@ -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; }); @@ -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 + }; + } +} diff --git a/test/spec/modules/concertBidAdapter_spec.js b/test/spec/modules/concertBidAdapter_spec.js index abb032ab154..10ea997b304 100644 --- a/test/spec/modules/concertBidAdapter_spec.js +++ b/test/spec/modules/concertBidAdapter_spec.js @@ -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 @@ -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() { @@ -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) }) });