amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

I2I: API for position change for amp ads

Open harquail opened this issue 9 years ago • 17 comments

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

harquail avatar Jan 04 '17 21:01 harquail

Also requested in https://github.com/ampproject/amphtml/issues/6857.

jridgewell avatar Jan 04 '17 21:01 jridgewell

@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}
}

zhouyx avatar Jan 04 '17 21:01 zhouyx

As per @jridgewell's comment in #6857, can you just use send-intersections?

bradfrizzell avatar Jan 04 '17 21:01 bradfrizzell

@zhouyx yep that would meet our needs

harquail avatar Jan 04 '17 21:01 harquail

@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)

harquail avatar Jan 04 '17 21:01 harquail

ah I see

bradfrizzell avatar Jan 04 '17 21:01 bradfrizzell

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 :-).

lannka avatar Jan 04 '17 22:01 lannka

And I assume we can switch to use the native IntersectionObserver with this done. As it covers the missing rootBound info.

zhouyx avatar Jan 04 '17 22:01 zhouyx

As it covers the missing rootBound info.

Hm? Doesn't native specifically exclude rootBounds?

jridgewell avatar Jan 04 '17 22:01 jridgewell

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

zhouyx avatar Jan 04 '17 23:01 zhouyx

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.

jridgewell avatar Jan 04 '17 23:01 jridgewell

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.

zhouyx avatar Jan 04 '17 23:01 zhouyx

blocked by #7604

lannka avatar Feb 24 '17 23:02 lannka

This issue hasn't been updated in awhile. @zhouyx Do you have any updates?

ampprojectbot avatar Dec 12 '17 05:12 ampprojectbot

This issue hasn't been updated in awhile. @zhouyx Do you have any updates?

ampprojectbot avatar Jun 05 '18 17:06 ampprojectbot

Still blocked by privacy review. Will prioritize after that. Adjust to P3 since this achievable with our current implementation of InOb.

zhouyx avatar Jul 16 '18 17:07 zhouyx

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.

stale[bot] avatar Dec 04 '21 06:12 stale[bot]