Skip to content

✨ Implements amp-analytics support for amp-next-page#26451

Merged
wassgha merged 17 commits intoampproject:masterfrom
wassgha:amp-next-page-analytics
Feb 27, 2020
Merged

✨ Implements amp-analytics support for amp-next-page#26451
wassgha merged 17 commits intoampproject:masterfrom
wassgha:amp-next-page-analytics

Conversation

@wassgha
Copy link
Copy Markdown
Contributor

@wassgha wassgha commented Jan 23, 2020

Changes

  • Fixes amp-analytics calculates wrong scroll triggers for embedded shadow documents #18735 by introducing ignoreResize to the scrollSpec of <amp-analytics>. This prevents counting subsequent loaded document heights as part of the host/parent page's scrollable area, which means that at 100%, the first/parent document has been fully read and the user is now transitioning to the next document.
  • Fixes scroll trigger calculations for embedded documents (next pages) by using their viewport as a point of reference as opposed to the host/parent page's viewport (now uses viewport.getLayoutRect() instead of viewport.getScrollWidth/viewport.getScrollHeight)
  • Verifies that visibility and timer triggers have been fixed as part of ✨Manual management of amp-next-page document visibility #25388
  • Changes the visibility management policy to prerender partially visible pages in order to prevent loaders and placeholders from being shown until the page is fully scrolled into view
  • Adds analytics to the manual tests

Assumptions (will be enforced by validator changes):

  • Only one amp-next-page element per AMP document
  • amp-next-page is always the last child of the body so there is no content after it (footers will be declared inside the amp-next-page element)
  • The footer's visibility is controlled solely by amp-next-page and the footer is not counted as part of the host document's scrollable area

@amp-bundle-size amp-bundle-size bot requested a review from zhouyx January 28, 2020 23:56
@wassgha wassgha marked this pull request as ready for review January 30, 2020 06:26
@wassgha
Copy link
Copy Markdown
Contributor Author

wassgha commented Jan 30, 2020

@zhouyx this is ready for review but I'd be extra careful with it, might have some unexpected implications

Copy link
Copy Markdown
Contributor

@caroqliu caroqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I realized that many of these changes rely on synchronously measuring the layout, such as scrollTop and scrollWidth, which could cause layout thrashing. Please refactor to use measureMutateElement/mutateElement where appropriate. Happy to discuss further if you'd like.

Approving amp-next-page changes once all comments are addressed. Deferring to @zhouyx for overall approvals for merge. :)

const scrollEvent = {
top: e.top,
left: e.left,
top: e.top - layoutRect.top,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this expected to be a breaking change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, could you please expand a bit on what are the this.viewport_.getScrollTop(), layoutRect.top. thanks

Copy link
Copy Markdown
Contributor Author

@wassgha wassgha Feb 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a breaking change for the non-shadow case because for the top-level page, this.root_ is equivalent to the document body which means that for the existing case, layoutRect.top and layoutRect.left would be 0 (so it doesn't change the existing behavior). For the ShadowDOM case, this.root_ becomes the ShadowDOM's container, in which case the layoutRect.top and layoutRect.left would serve to offset the calculations to become relative to the ShadowDOM's container as opposed to the top level container.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhouyx are there any test suites / manual tests we can do here to ensure that nothing breaks?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing that tests shadow dom that I'm aware of. Please feel free to create and add new ones. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. One more question on the viewport.getScrollTop() for the non-shadow case. Does the shadow doc share the same viewport service as the parent? What is the scrollTop value here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, it does not, the shadow docs will have a viewport service for their own ampdoc instance ( AmpDocShadow as opposed to AmpDocSingle) so viewport.getScrollTop will yield the distance between top of the page and the position of the shadow doc.

Copy link
Copy Markdown
Contributor

@caroqliu caroqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing approvals for now.

const scrollEvent = {
top: e.top,
left: e.left,
top: e.top - layoutRect.top,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question, could you please expand a bit on what are the this.viewport_.getScrollTop(), layoutRect.top. thanks

@wassgha wassgha requested a review from dvoytenko February 6, 2020 09:45
@wassgha
Copy link
Copy Markdown
Contributor Author

wassgha commented Feb 6, 2020

Added @dvoytenko for sanity checking

@wassgha wassgha requested a review from caroqliu February 6, 2020 18:09
Copy link
Copy Markdown
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor and rename request.

(No strong preference on specific nouns btw, as long as the structure/positive boolean is kept).

Copy link
Copy Markdown
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG from amp-next-page code itself. I'm leaving analytics review to the respective wg

@wassgha wassgha requested a review from alanorozco February 7, 2020 00:28
@wassgha wassgha force-pushed the amp-next-page-analytics branch from 0603aa1 to c445ee1 Compare February 7, 2020 00:39
} = layoutRect;
/** {./scroll-manager.ScrollEventDef} */
const scrollEvent = {
top: e.top - scrollTop,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, it does not, the shadow docs will have a viewport service for their own ampdoc instance ( AmpDocShadow as opposed to AmpDocSingle) so viewport.getScrollTop will yield the distance between top of the page and the position of the shadow doc.

I'm a bit lost : ) If that's the case, e.top is the distance of the element to the shadow doc top. Do we still need to minus the scrollTop here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)) So that an element placed at the top of the shadow doc would be considered at 0% of the top (where top refers to the top of the embedded document, not the entire page)

@wassgha wassgha requested review from alanorozco and zhouyx February 13, 2020 07:46
@wassgha wassgha requested a review from zhouyx February 19, 2020 06:33
@wassgha
Copy link
Copy Markdown
Contributor Author

wassgha commented Feb 24, 2020

Are we waiting for anything on this one?

@zhouyx
Copy link
Copy Markdown
Contributor

zhouyx commented Feb 24, 2020

No, didn't get a chance to review the change. Will do today.

@zhouyx
Copy link
Copy Markdown
Contributor

zhouyx commented Feb 25, 2020

one more unresolved comment #26451 (comment)

Copy link
Copy Markdown
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@wassgha
Copy link
Copy Markdown
Contributor Author

wassgha commented Feb 26, 2020

@alanorozco @caroqliu ping

Copy link
Copy Markdown
Contributor

@caroqliu caroqliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wassgha wassgha merged commit 7785d74 into ampproject:master Feb 27, 2020
@wassgha wassgha deleted the amp-next-page-analytics branch February 27, 2020 22:56
robinvanopstal added a commit to jungvonmatt/amphtml that referenced this pull request Mar 2, 2020
* master:
  Launch `amp-next-page` v2 & clean up experiment (ampproject#27035)
  ✨Implement Display Locking on amp-accordion (ampproject#25867)
  📖<amp-next-page> documentation and validation (ampproject#26841)
  Improve visibility event tests (ampproject#26847)
  amp-geo: Fall back to API for country (ampproject#26407)
  ✨ Add customization options to <amp-story-quiz> (ampproject#26714)
  navigation: Minor test improvements (ampproject#26926)
  ♻️ Alias video.fullscreen action for symmetry with interface names (ampproject#27017)
  ✨ Implements `amp-analytics` support for `amp-next-page` (ampproject#26451)
  ✨ amp-video-iframe integration: global jwplayer() singleton by default (ampproject#26969)
  Fix unit tests broken by ampproject#26687 (ampproject#27000)
  Filter redirect info from emails (ampproject#27012)
  📖 Make amp-bind doc valid, fix amp-form stories filter (ampproject#27003)
  url-replacements: Minor test improvement (ampproject#26930)
  viewport: Minor test improvement (ampproject#26931)
  amp-consent fullscreen warning (ampproject#26467)
  dep-check: USE CAPS FOR IMPORTANCE (ampproject#26993)
  fix img url (ampproject#26987)

# Conflicts:
#	extensions/amp-next-page/amp-next-page.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

amp-analytics calculates wrong scroll triggers for embedded shadow documents

7 participants