I2I: API for position change for amp ads
Currently, Yieldmo is relying on a side effect of the IntersectionObserver API to calculate our format's position on the page (we use this position for interactive animated formats and engagement metrics). However, it may make more sense to introduce a separate API to inform the ad of scroll position changes. (Especially if other ad networks are also relying on IntersectionObserver for scroll position within the viewport). See discussion here: #5603
For instance, amp could add a new API for observing position, that sends position updates periodically as the user scrolls (ideally on each scroll, but we may want to throttle the events for performance reasons).
Information Yieldmo ads need on each update: - scroll position of the amp ad in the top window context - height of page
For completeness, it might make sense to include the full rects for the amp ad and viewport. For our use case, it is important that the coordinates be from the top window's frame of reference. We do not use the ad's scroll position when it is outside the viewport.
@lannka
Also requested in https://github.com/ampproject/amphtml/issues/6857.
@harquail Would this be enough? Even with the old IO, the position is all relative to viewport not to the top window context.
{
adRect: relative to viewport
viewportSize {width, height}
}
As per @jridgewell's comment in #6857, can you just use send-intersections?
@zhouyx yep that would meet our needs
@bradfrizzell That's basically what we're doing now. The motivation behind this is a desired change to the intersection observer to only send change events when the intersection ratio with the viewport changes (not on position changes when the ad is fully inside the viewport). This was a breaking change for us, but @lannka wanted to explore the possibility of adding a separate API for this. (see #5603)
ah I see
We introduced a PositionObserver for amp-inabox project. Eventually, we'll also provide the same API in AMP runtime. So that should address your need.
@jridgewell I suppose this is something we get for free when LayoutManager is done :-).
And I assume we can switch to use the native IntersectionObserver with this done. As it covers the missing rootBound info.
As it covers the missing rootBound info.
Hm? Doesn't native specifically exclude rootBounds?
Yes, native one specifically exclude rootBounds But we provide rootBounds before, and many depend on that to get viewport size. This proposed API can provide an alternative method to get that piece of info instead of using rootBounds
Why the need for the new API though? We're having all these troubles with creating an InOb inside the ad's iframe which would just go away (including this) if we just created it in the AMP Doc's window and sent messages down.
That will work. But I believe using native InOb inside ad's iframe can be a performance improvement, and we should still consider using that when it's possible.
blocked by #7604
This issue hasn't been updated in awhile. @zhouyx Do you have any updates?
This issue hasn't been updated in awhile. @zhouyx Do you have any updates?
Still blocked by privacy review. Will prioritize after that. Adjust to P3 since this achievable with our current implementation of InOb.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.