Skip to content

Commit

Permalink
- FIX: Replace deprecated pageXOffset and pageYOffset with scrollX an…
Browse files Browse the repository at this point in the history
…d scrollY respectively

- ADD: Viewport coordinate in bidRequest.ext.vcoords
  • Loading branch information
vivekyadav15 committed Nov 8, 2024
1 parent 18ae4dc commit 394ea83
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
File renamed without changes.
13 changes: 13 additions & 0 deletions libraries/viewportAndViewability/viewport.js
Original file line number Diff line number Diff line change
@@ -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 {};
}
}
2 changes: 1 addition & 1 deletion modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
registerBidder
} from '../src/adapters/bidderFactory.js';

import { percentInView } from '../libraries/percentInView/percentInView.js';
import { percentInView } from '../libraries/viewportAndViewability/percentInView.js';

import { config } from '../src/config.js';

Expand Down
19 changes: 14 additions & 5 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/viewportAndViewability/viewport.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -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$' },
Expand All @@ -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 }
}
}
);
}

Expand Down Expand Up @@ -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,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/omsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';
import {percentInView} from '../libraries/percentInView/percentInView.js';
import {percentInView} from '../libraries/viewportAndViewability/percentInView.js';
import {getUserSyncParams} from '../libraries/userSyncUtils/userSyncUtils.js';

const BIDDER_CODE = 'oms';
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

0 comments on commit 394ea83

Please sign in to comment.