-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Media.net Adapter Improvements #2634
Changes from 1 commit
d746d01
06a82aa
4e7a59a
79560e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,12 +82,28 @@ let VALID_BID_REQUEST = [{ | |
'customer_id': 'customer_id', | ||
'prebid_version': $$PREBID_GLOBAL$$.version, | ||
'gdpr_applies': false, | ||
'screen': { | ||
'w': 1000, | ||
'h': 1000 | ||
} | ||
}, | ||
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', | ||
'imp': [{ | ||
'id': '28f8f8130a583e', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-0' | ||
'dfp_id': 'div-gpt-ad-1460505748561-0', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -105,7 +121,19 @@ let VALID_BID_REQUEST = [{ | |
}, { | ||
'id': '3f97ca71b1e5c2', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-123' | ||
'dfp_id': 'div-gpt-ad-1460505748561-123', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -131,13 +159,29 @@ let VALID_BID_REQUEST = [{ | |
'ext': { | ||
'customer_id': 'customer_id', | ||
'prebid_version': $$PREBID_GLOBAL$$.version, | ||
'gdpr_applies': false | ||
'gdpr_applies': false, | ||
'screen': { | ||
'w': 1000, | ||
'h': 1000 | ||
} | ||
}, | ||
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', | ||
'imp': [{ | ||
'id': '28f8f8130a583e', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-0' | ||
'dfp_id': 'div-gpt-ad-1460505748561-0', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -154,7 +198,19 @@ let VALID_BID_REQUEST = [{ | |
}, { | ||
'id': '3f97ca71b1e5c2', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-123' | ||
'dfp_id': 'div-gpt-ad-1460505748561-123', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -339,7 +395,7 @@ let VALID_BID_REQUEST = [{ | |
'consentString': 'consentString', | ||
'gdprApplies': true, | ||
}, | ||
'timeout': 3000, | ||
'timeout': 3000 | ||
}, | ||
VALID_PAYLOAD_FOR_GDPR = { | ||
'site': { | ||
|
@@ -352,12 +408,28 @@ let VALID_BID_REQUEST = [{ | |
'prebid_version': $$PREBID_GLOBAL$$.version, | ||
'gdpr_consent_string': 'consentString', | ||
'gdpr_applies': true, | ||
'screen': { | ||
'w': 1000, | ||
'h': 1000 | ||
} | ||
}, | ||
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', | ||
'imp': [{ | ||
'id': '28f8f8130a583e', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-0' | ||
'dfp_id': 'div-gpt-ad-1460505748561-0', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -374,7 +446,19 @@ let VALID_BID_REQUEST = [{ | |
}, { | ||
'id': '3f97ca71b1e5c2', | ||
'ext': { | ||
'dfp_id': 'div-gpt-ad-1460505748561-123' | ||
'dfp_id': 'div-gpt-ad-1460505748561-123', | ||
'visibility': 1, | ||
'viewability': 1, | ||
'coordinates': { | ||
'top_left': { | ||
x: 50, | ||
y: 50 | ||
}, | ||
'bottom_right': { | ||
x: 100, | ||
y: 100 | ||
} | ||
} | ||
}, | ||
'banner': [{ | ||
'w': 300, | ||
|
@@ -416,6 +500,31 @@ describe('Media.net bid adapter', () => { | |
}); | ||
|
||
describe('buildRequests', () => { | ||
let sandbox; | ||
let mock; | ||
before(() => { | ||
sandbox = sinon.sandbox.create(); | ||
mock = sinon.mock(window); | ||
window.innerWidth = 1000; | ||
window.innerHeight = 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mock does not modify the given object.
This means that setting these read-only values on |
||
let documentStub = sandbox.stub(document, 'getElementById'); | ||
let boundingRect = { | ||
top: 50, | ||
left: 50, | ||
bottom: 100, | ||
right: 100 | ||
}; | ||
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
}); | ||
after(() => { | ||
sandbox.restore(); | ||
mock.restore(); | ||
}); | ||
it('should build valid payload on bid', () => { | ||
let requestObj = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); | ||
expect(JSON.parse(requestObj.data)).to.deep.equal(VALID_PAYLOAD); | ||
|
@@ -456,6 +565,87 @@ describe('Media.net bid adapter', () => { | |
}); | ||
}); | ||
|
||
describe('slot visibility', () => { | ||
let mock; | ||
before(() => { | ||
mock = sinon.mock(window); | ||
window.innerWidth = 1000; | ||
window.innerHeight = 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be updated as well not to modify read-only window properties. |
||
}); | ||
after(() => { | ||
mock.restore(); | ||
}); | ||
it('slot visibility should be 2 and ratio 0 when ad unit is BTF', () => { | ||
let sandbox = sinon.sandbox.create(); | ||
let documentStub = sandbox.stub(document, 'getElementById'); | ||
let boundingRect = { | ||
top: 1010, | ||
left: 1010, | ||
bottom: 1050, | ||
right: 1050 | ||
}; | ||
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); | ||
let data = JSON.parse(bidReq.data); | ||
expect(data.imp[0].ext.visibility).to.equal(2); | ||
expect(data.imp[0].ext.viewability).to.equal(0); | ||
sandbox.restore(); | ||
}); | ||
it('slot visibility should be 2 and ratio < 0.5 when ad unit is partially inside viewport', () => { | ||
let sandbox = sinon.sandbox.create(); | ||
let documentStub = sandbox.stub(document, 'getElementById'); | ||
let boundingRect = { | ||
top: 990, | ||
left: 990, | ||
bottom: 1050, | ||
right: 1050 | ||
}; | ||
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); | ||
let data = JSON.parse(bidReq.data); | ||
expect(data.imp[0].ext.visibility).to.equal(2); | ||
expect(data.imp[0].ext.viewability).to.equal(100 / 75000); | ||
sandbox.restore(); | ||
}); | ||
it('slot visibility should be 1 and ratio > 0.5 when ad unit mostly in viewport', () => { | ||
let sandbox = sinon.sandbox.create(); | ||
let documentStub = sandbox.stub(document, 'getElementById'); | ||
let boundingRect = { | ||
top: 800, | ||
left: 800, | ||
bottom: 1050, | ||
right: 1050 | ||
}; | ||
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ | ||
getBoundingClientRect: () => boundingRect | ||
}); | ||
let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); | ||
let data = JSON.parse(bidReq.data); | ||
expect(data.imp[0].ext.visibility).to.equal(1); | ||
expect(data.imp[0].ext.viewability).to.equal(40000 / 75000); | ||
sandbox.restore(); | ||
}); | ||
it('co-ordinates should not be sent and slot visibility should be 0 when ad unit is not present', () => { | ||
let bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); | ||
let data = JSON.parse(bidReq.data); | ||
expect(data.imp[1].ext).to.not.have.ownPropertyDescriptor('viewability'); | ||
expect(data.imp[1].ext.visibility).to.equal(0); | ||
}); | ||
}); | ||
|
||
describe('getUserSyncs', () => { | ||
it('should exclude iframe syncs if iframe is disabled', () => { | ||
let userSyncs = spec.getUserSyncs(SYNC_OPTIONS_PIXEL_ENABLED, SERVER_CSYNC_RESPONSE); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get the distance from the top left corner of the document (as opposed to viewport) this code should be