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

Draft: Add support for forwarding viewport coordinates and fix deprecated scroll value (pageXOffset and pageYOffset) #12354

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
30 changes: 25 additions & 5 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function extParams(bidRequest, bidderRequests) {
const gdprApplies = !!(gdpr && gdpr.gdprApplies);
const uspApplies = !!(uspConsent);
const coppaApplies = !!(config.getConfig('coppa'));
const vcoords = getViewportCoordinates();
return Object.assign({},
{ customer_id: params.cid },
{ prebid_version: 'v' + '$prebid.version$' },
Expand All @@ -191,10 +192,29 @@ 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: vcoords}
);
}

function getViewportCoordinates() {
let top = -1;
let bottom = -1;
let left = -1;
let right = -1;
try {
const windowTop = getWindowTop();
top = windowTop.scrollY;
bottom = top + windowTop.innerHeight
left = windowTop.scrollX;
right = left + windowTop.innerWidth
} catch (e) {}
return {
top_left: { x: left, y: top },
bottom_right: { x: right, y: bottom }
}
}

function slotParams(bidRequest, bidderRequests) {
// check with Media.net Account manager for bid floor and crid parameters
let params = {
Expand Down Expand Up @@ -319,12 +339,12 @@ function getOverlapArea(topLeft1, bottomRight1, topLeft2, bottomRight2) {
function normalizeCoordinates(coordinates) {
return {
top_left: {
x: coordinates.top_left.x + window.pageXOffset,
y: coordinates.top_left.y + window.pageYOffset,
x: coordinates.top_left.x + window.scrollX,
y: coordinates.top_left.y + window.scrollY,
},
bottom_right: {
x: coordinates.bottom_right.x + window.pageXOffset,
y: coordinates.bottom_right.y + window.pageYOffset,
x: coordinates.bottom_right.x + window.scrollX,
y: coordinates.bottom_right.y + window.scrollY,
}
}
}
Expand Down
94 changes: 94 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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': [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 () {
Expand Down