Allow `on: visible` to listen to `amp-list` items.
What
When you use amp-list (way below the fold), it should be possible to add a visibility tracker on those amp-list's items when they start showing up. It's currently not possible as the id the listeners are attached to are not present yet.
Additional context
The visibilitySpec options don't seem to help.
Thanks for filing this feature request! Can you provide more information on how you anticipate using this? Since AMP actions and events can be used to create dynamic experiences, and something like a on: visible event would be passively triggered rather than intentionally done with user interaction, would this feature be able to fulfill your use case with a low-trust event?
Hi @caroqliu!
We load recommended articles via amp-list at the end of our articles.
We would like to track impressions of the list items.
However, expectedly, browser throws an error when trying to track visibility for something that's not there yet:
"visibilityReco_1": {
"on": "visible",
"request": "event",
"selector": "#list_item_1",
"visibilitySpec": {...}
}
Throws
Uncaught (in promise) Error: Element "#list_item_1" not found: null
Is this enough info?
I found another thread issue (from 2017) for a similar request that ended up with the addition of the ini-load trigger.
I don't think the solution was what was requested though.
Actually, I keep mentioning on: visible as the trigger we're looking forward to having but none of the triggers work for amp-list items as far as we're concerned.
We'd love to see more opportunities to use amp-analytics within amp-list.
Other closed issue (#3857) supposedly fixed.
cc @ampproject/wg-analytics
Thanks for reporting this. Yes this is a known issue. <amp-analytics> observe elements during initialization once. Because of that dynamic element that's loaded after <amp-analytics> initialization won't be observed.
Another restriction that you may encounter is: AMP doesn't support tracking the visibility of non AMP elements. We are working to remove this restriction.
#21727 is related. And you may be able to fix it by placing the <amp-analytics> within the <amp-list>.
@zhouyx @caroqliu
Placing <amp-analytics> within the <amp-list> did the trick.
Thank you both!