-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Visibility Trigger for Non AMP Elements #29172
Visibility Trigger for Non AMP Elements #29172
Conversation
f8db886
to
ea2494f
Compare
@micajuine-ho Thanks! |
@airroot We are expecting a 2-week delay before I can resume work on this; we are waiting for IntersectionObserverPolyfill clean up. |
@micajuine-ho That sounds great! Thanks! |
e18eb1c
to
1584e2f
Compare
Please remind me. Did we agree to only support non AMP element when the selector is an array? |
Discussed offline; originally we did agree on this but after revisiting the decision, we believe this should be a default feature of the visibility trigger (and not just allowed within array of selectors). |
f946069
to
9506ea2
Compare
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.
LGTM. A few nit picks
9506ea2
to
4d65e3c
Compare
Realized one more thing.
What was our decision on |
6aa3382
to
252d68d
Compare
Discussed offline: waitFor in an array of selectors applies the Only |
I want to review the default readyPromise for non AMP element again. Ideally we want to send visible event that is meaningful to end users that's why we wait for |
For non-ads case, we are only aware of publishers wanting to track For the ads case, I talked the ads team (cc @lannka), and we are ok with non-AMP elements visibility trigger firing potentially before the ad is fully visible or loaded.
|
*/ | ||
setDefaultWaitForElement_(waitForSpec, element) { | ||
if (!waitForSpec) { | ||
const isAmpElement = element.classList.contains('i-amphtml-element'); |
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.
nit: can use isAmpElement
.then((elements) => { | ||
const unlistenCallbacks = []; | ||
for (let i = 0; i < elements.length; i++) { | ||
unlistenCallbacks.push( | ||
visibilityManager.listenElement( | ||
elements[i], | ||
visibilitySpec, | ||
this.getReadyPromise(readyPromiseWaitForSpec, elements[i]), | ||
this.getReadyPromise( | ||
this.setDefaultWaitForElement_(waitForSpec, elements[i]), |
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.
nit: I find it cleaner to embed the logic to getReadyPromise()
. There's no need to update the waitForSpec
, simply return a none readyPromise when the element is not AMP.
@@ -839,6 +839,8 @@ not specified, it waits for element's [`ini-load`](#ini-load) signal. See | |||
for that signal before sending the event. This is useful, for example, in | |||
sending analytics events when the page is closed. | |||
|
|||
Tracking non-AMP elements are best effort. For example, tracking a `<div>` element that contains an `<amp-iframe>`, may not accurately wait for the iframe to load before sending the signal out. |
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.
Move the paragraph to where we document waitFor
.
Also I wouldn't say it's best effort, because we always track them.
1025a32
to
6187968
Compare
21ccd2a
to
80a8fad
Compare
80a8fad
to
2cb04f0
Compare
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.
LGTM. Thanks for adding this! Worth expanding our e2e/integration test as well. Not blocking.
@zhouyx Should we create an e2e test for this? I currently don't see many e2e tests for analytics. |
2cb04f0
to
eddda22
Compare
There're integration tests |
Discussed offline, will add to integrations tests. |
* init * Manual test * Make default behavior * WaitFor changes * Suggested changes * Clean and add error msg
Closes #20607
Overview:
Now that a universal IntersectionObserver polyfill is deployed in all AMP modes, we can rely on it to observe non amp elements under the visibility trigger for amp-analytics. We've decided to make this the default behavior for the visibility trigger.
Changes:
visibility-trigger-improvements
) and for non-special selectorsini-load
and non-AMP elements default tonone
.none
) for non-AMP elementsgetAmpElements()
=>getElements()
, and change tests accordinglyNotes: