diff --git a/libraries/viewport/viewport.js b/libraries/viewport/viewport.js new file mode 100644 index 00000000000..b385e9a27ec --- /dev/null +++ b/libraries/viewport/viewport.js @@ -0,0 +1,13 @@ +import {getWindowTop} from '../../src/utils.js'; + +export function getViewportCoordinates() { + try { + const win = getWindowTop(); + let { scrollY: top, scrollX: left, innerHeight, innerWidth } = win; + innerHeight = innerHeight || win.document.documentElement.clientWidth || win.document.body.clientWidth; + innerWidth = innerWidth || win.document.documentElement.clientHeight || win.document.body.clientHeight + return { top, right: left + innerWidth, bottom: top + innerHeight, left }; + } catch (e) { + return {}; + } +} diff --git a/modules/medianetBidAdapter.js b/modules/medianetBidAdapter.js index c90292a74ac..0c43b04f53c 100644 --- a/modules/medianetBidAdapter.js +++ b/modules/medianetBidAdapter.js @@ -21,6 +21,7 @@ import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; import {getGlobal} from '../src/prebidGlobal.js'; import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; import {ajax} from '../src/ajax.js'; +import {getViewportCoordinates} from '../libraries/viewport/viewport.js'; /** * @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest @@ -180,6 +181,7 @@ function extParams(bidRequest, bidderRequests) { const gdprApplies = !!(gdpr && gdpr.gdprApplies); const uspApplies = !!(uspConsent); const coppaApplies = !!(config.getConfig('coppa')); + const {top = -1, right = -1, bottom = -1, left = -1} = getViewportCoordinates(); return Object.assign({}, { customer_id: params.cid }, { prebid_version: 'v' + '$prebid.version$' }, @@ -191,7 +193,13 @@ function extParams(bidRequest, bidderRequests) { windowSize.w !== -1 && windowSize.h !== -1 && { screen: windowSize }, userId && { user_id: userId }, getGlobal().medianetGlobals.analyticsEnabled && { analytics: true }, - !isEmpty(sChain) && {schain: sChain} + !isEmpty(sChain) && {schain: sChain}, + { + vcoords: { + top_left: { x: left, y: top }, + bottom_right: { x: right, y: bottom } + } + } ); } @@ -317,14 +325,15 @@ function getOverlapArea(topLeft1, bottomRight1, topLeft2, bottomRight2) { } function normalizeCoordinates(coordinates) { + const {scrollX, scrollY} = window; return { top_left: { - x: coordinates.top_left.x + window.pageXOffset, - y: coordinates.top_left.y + window.pageYOffset, + x: coordinates.top_left.x + scrollX, + y: coordinates.top_left.y + scrollY, }, bottom_right: { - x: coordinates.bottom_right.x + window.pageXOffset, - y: coordinates.bottom_right.y + window.pageYOffset, + x: coordinates.bottom_right.x + scrollX, + y: coordinates.bottom_right.y + scrollY, } } } diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js index d3eab769f4a..5f2efc7864f 100644 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ b/test/spec/modules/medianetBidAdapter_spec.js @@ -531,6 +531,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -622,6 +632,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -714,6 +734,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -807,6 +837,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -901,6 +941,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -1008,6 +1058,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -1104,6 +1164,16 @@ let VALID_BID_REQUEST = [{ 'w': 1000, 'h': 1000 }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } + } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', 'imp': [ @@ -1640,6 +1710,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -1747,6 +1827,16 @@ let VALID_BID_REQUEST = [{ 'screen': { 'w': 1000, 'h': 1000 + }, + 'vcoords': { + 'top_left': { + 'x': 50, + 'y': 100 + }, + 'bottom_right': { + 'x': 490, + 'y': 880 + } } }, 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', @@ -1829,6 +1919,10 @@ describe('Media.net bid adapter', function () { let sandbox; beforeEach(function () { sandbox = sinon.sandbox.create(); + sandbox.stub(window.top, 'innerHeight').value(780) + sandbox.stub(window.top, 'innerWidth').value(440) + sandbox.stub(window.top, 'scrollY').value(100) + sandbox.stub(window.top, 'scrollX').value(50) }); afterEach(function () {