amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Allow `on: visible` to listen to `amp-list` items.

Open erakor opened this issue 6 years ago • 8 comments

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.

erakor avatar Apr 17 '20 18:04 erakor

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?

caroqliu avatar Apr 20 '20 13:04 caroqliu

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?

erakor avatar May 07 '20 01:05 erakor

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.

erakor avatar May 07 '20 01:05 erakor

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.

erakor avatar May 07 '20 03:05 erakor

Other closed issue (#3857) supposedly fixed.

erakor avatar May 07 '20 13:05 erakor

cc @ampproject/wg-analytics

caroqliu avatar May 07 '20 13:05 caroqliu

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 avatar May 07 '20 18:05 zhouyx

@zhouyx @caroqliu Placing <amp-analytics> within the <amp-list> did the trick. Thank you both!

erakor avatar May 20 '20 01:05 erakor