-
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
Conversation
I think you have a logical error in determining ad positioning for before or after the fold. You're using From: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
It's possible the discrepancy wouldn't be terrible depending on how fast the library loaded how long it took before this viewability code ran (if it ran before the user had done any scrolling). Let me know if you want to update, otherwise I can merge. |
Hey @snapwich , As you mentioned there are following cases
Code currently assigns smallest size (by area) to the container, and figures out if its gonna be in view or not.
Correct visibility would be determined.
Yes current code would make it "look"
I'm not quite sure I understood this point, wouldn't the entire lib load as one monolithic code and execute ? The execution of the slot visibility code is inside I would've loved if prebid's core lib could've given us slot visibility info. Happy to give a PR for that! |
Hi @ruturajv So I'm guessing the intent is to determine if an element is above the fold considering the use of If you want these functions to always tell you whether the element was placed above the fold then coordinates.top_left = {
y: rect.top + window.pageYOffset,
x: rect.left + window.pageXOffset,
};
coordinates.bottom_right = {
y: rect.bottom + window.pageYOffset,
x: rect.right + window.pageXOffset,
}; |
modules/medianetBidAdapter.js
Outdated
coordinates.bottom_right = { | ||
y: rect.bottom, | ||
x: rect.right, | ||
}; |
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
coordinates.top_left = {
y: rect.top + window.pageYOffset,
x: rect.left + window.pageXOffset,
};
coordinates.bottom_right = {
y: rect.bottom + window.pageYOffset,
x: rect.right + window.pageXOffset,
};
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 comment
The reason will be displayed to describe this comment to others. Learn more.
A mock does not modify the given object.
Does not change the object, but returns a mock object to set expectations on the object’s methods.
This means that setting these read-only values on window
will most likely throw errors (in Safari I believe) and also not be reset after your test suite runs. To solve this you can either use a helper function to get the screen dimensions and stub that to get the results you want or you can make your tests more tolerant of various screen sizes (as the browserstack tests will run across multiple devices).
before(() => { | ||
mock = sinon.mock(window); | ||
window.innerWidth = 1000; | ||
window.innerHeight = 1000; |
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.
Needs to be updated as well not to modify read-only window properties.
Hey @snapwich , Thanks for review and clarification on Ruturaj |
… window properties
@snapwich , We have updated the code as requested. Can you please have a look ? Also we have exposed |
@@ -566,17 +566,16 @@ describe('Media.net bid adapter', () => { | |||
}); | |||
|
|||
describe('slot visibility', () => { | |||
let mock; | |||
let sandbox = sinon.sandbox.create(); |
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.
You should just put the sandbox creation in the outermost describe
block's beforeEach
and the restore
in its afterEach
. Doing this multiple times in different nested-levels of describe
make it difficult to see if the sandbox is being properly cleaned up.
edit - just edited to say that they should be in a beforeEach
and afterEach
as well, as opposed to before
and after
which only run once per describe block.
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(); | ||
documentStub.restore(); |
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.
Since the documentStub
was created with the sandbox it should be cleaned up by the sandbox automatically by the sandbox.restore()
in the afterEach
. Doing documentStub.restore()
might double restore, which can do weird things.
@vedantseta Exposing |
… and afterEach hooks
@snapwich , We have made changes as requested. Can you please have a look? |
Type of change
Description of change
This PR adds functionality adds slot visibility in request to bid optimally.