Currently, AMP analytics tags for ads require a selector (e.g. "selector": "#anim-id"). However, the amp-ad's id isn't necessarily known when the analytics tags are generated. Instead of requiring a selector, when the analytics events are added to the page as the result of an ad request, they should apply to the ad with which they are served.
Along with that, when shadow-DOM isn't supported, the analytics tags need to be hoisted from the ad response and placed in the main AMP page, not the iframe. Then, the AMP runtime can correctly track the viewability of the ad and fire the events.