Skip to content

Commit

Permalink
Send proper slot info in case of adUnitPath (#5810)
Browse files Browse the repository at this point in the history
- using `getGptSlotInfoForAdUnitCode` to get `divId` in case of `adUnitPath`
- added test case for visibility via `adUnitPath`

Co-authored-by: monis.q <[email protected]>
  • Loading branch information
monis0395 and monisq authored Oct 1, 2020
1 parent 1df6a22 commit 303ccae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ function getWindowSize() {
}
}

function getCoordinates(id) {
const element = document.getElementById(id);
function getCoordinates(adUnitCode) {
let element = document.getElementById(adUnitCode);
if (!element && adUnitCode.indexOf('/') !== -1) {
// now it means that adUnitCode is GAM AdUnitPath
const {divId} = utils.getGptSlotInfoForAdUnitCode(adUnitCode);
if (utils.isStr(divId)) {
element = document.getElementById(divId);
}
}
if (element && element.getBoundingClientRect) {
const rect = element.getBoundingClientRect();
let coordinates = {};
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {expect} from 'chai';
import {spec} from 'modules/medianetBidAdapter.js';
import { makeSlot } from '../integration/faker/googletag.js';
import { config } from 'src/config.js';

$$PREBID_GLOBAL$$.version = $$PREBID_GLOBAL$$.version || 'version';
let VALID_BID_REQUEST = [{
'bidder': 'medianet',
'params': {
Expand Down Expand Up @@ -1306,6 +1308,30 @@ describe('Media.net bid adapter', function () {
expect(data.imp[1].ext).to.not.have.ownPropertyDescriptor('viewability');
expect(data.imp[1].ext.visibility).to.equal(0);
});
it('slot visibility should be calculable even in case of adUnitPath', function () {
const code = '/19968336/header-bid-tag-0';
const divId = 'div-gpt-ad-1460505748561-0';
window.googletag.pubads().setSlots([makeSlot({ code, divId })]);

let boundingRect = {
top: 1010,
left: 1010,
bottom: 1050,
right: 1050
};
documentStub.withArgs(divId).returns({
getBoundingClientRect: () => boundingRect
});
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({
getBoundingClientRect: () => boundingRect
});

const bidRequest = [{...VALID_BID_REQUEST[0], adUnitCode: code}]
const bidReq = spec.buildRequests(bidRequest, VALID_AUCTIONDATA);
const data = JSON.parse(bidReq.data);
expect(data.imp[0].ext.visibility).to.equal(2);
expect(data.imp[0].ext.viewability).to.equal(0);
});
});

describe('getUserSyncs', function () {
Expand Down

0 comments on commit 303ccae

Please sign in to comment.