ampproject / amphtml

The AMP web component framework.
https://amp.dev
Apache License 2.0
14.89k stars 3.89k forks source link

amp-analytics doesn't find an element #30997

Open gurodrigues opened 3 years ago

gurodrigues commented 3 years ago

What's the issue?

I am using amp-analytics to track my ads, but when using amp-analytic with amp-auto-ads it doesn’t track for the elements created after the amp-analytics has been loaded.

I believe this is happening with all amp extensions that dynamically loads elements on the page and not only amp-auto-ads.

Error message

Element "XXX" not found: null

How do we reproduce the issue?

I created 2 environments trying to simulate a delay on the extension so I can reproduce the error that occurs depending on user’s network:

1 – I delayed in 1 second the amp-analytics request: https://delay-amp-analytics.denakop.com/amp.html

2 – I delayed in 1 second the amp-auto-ad request: https://delay-amp-auto-ads.denakop.com/amp.html

When delaying the amp-analytics the error will not occur because the selector exists.

When delaying amp-auto-ad the amp-analytics will throw an error because when it is loaded the <amp-ad> elements is not created yet

What browsers are affected?

I managed to reproduce the error on all major browsers and devices.

Which AMP version is affected?

I believe this issue is happening in all AMP versions

micajuine-ho commented 3 years ago

Hi @gurodrigues, how are you dynamically loading you ad?

gurodrigues commented 3 years ago

Hi @micajuine-ho, I am using amp-auto-ads extension to dynamically load ads.

micajuine-ho commented 3 years ago

Thanks @gurodrigues. I am curious, why do you want to track the ad visibility yourself? Most of these ad vendors will provide tracking scripts in their creative and show the tracking data through their platform.

gurodrigues commented 3 years ago

@micajuine-ho Usually the most ad vendors doesn't provide an advanced report in real time. Using amp-analytics I am able to extract the report the way i need and also in the moment i need using a streaming process (real time).

I can also use this info to compare the reports with the ad vendors reports, so i can check if there is something wrong

micajuine-ho commented 3 years ago

I see. Unfortunately, amp-analytics cannot track dynamically loaded ads through amp-auto-ads. Is this feature something that you need?

gurodrigues commented 3 years ago

Denakop is the first Ad Network in Brazil delivering real time analytics for its supported ad formats, our platform allows publishers to quickly enable and disable multiple ads format without changing a single line in the code.

We usually delivery ads through doubleclick using the amp-ad extension and we collect the ad information using amp-analytics, without collecting the ad information at the time it is delivered we will not be able to continue making ad data available in real time to our customers in the same way as in HTML.

We are currently delivering more than 1.5 billion ad requests per month, mostly through HTML, but it is more and more frequently pages that use only AMP or that are migrating to this technology and we are also looking for the best way to adapt our technology to AMP.

That's why this functionality is so important to us, if you believe there is any other way to achieve the same result I would appreciate to hear your opinion.

micajuine-ho commented 3 years ago

Is using amp-auto-ads required here?

gurodrigues commented 3 years ago

Yes, we are using amp-auto-ads extension to allow publishers to enable or disable the ad formats with only one click through our platform, so they don't need to insert/edit anything in the code.

micajuine-ho commented 3 years ago

Ok that sounds good. After talking with @zhouyx, we see 3 options here to build feature:

  1. Have amp-analytics listen for a custom signal from amp-auto-ads when it inserts a new ad onto page. This will cause amp-analytics to then add that trigger.
  2. Change amp-auto-ads to insert an amp-analytics element each time it ads a new ad onto the page.
  3. Change amp-analytics to listen for dynamically added elements that will trigger it add these new found triggers into the page.

Option 1 and 2 are short term solutions and option 3 is a long term solution but also much larger in scope.

I'm leaning towards option 1 as it could also set the groundwork for option 3 in the future.

@zhouyx Thoughts?

gurodrigues commented 3 years ago

@micajuine-ho Glad to know that you understand the problem and are willing to help us :)

Any of the 3 options mentioned above would solve this problem, another alternative would be:

micajuine-ho commented 3 years ago

Sync'd with @zhouyx offline: option 1 sounds like a good solution since amp-analytics already has tooling built in to listen for custom events and then trigger based on that, so it should be possible to dispatch custom events for within amp-auto-ads and have amp-analytics trigger requests.

@gurodrigues What sort of tracking would you like to do for the amp-auto-ads?

gurodrigues commented 3 years ago

I use these triggers for tracking the ads: ad-response-end, ad-iframe-loaded, ad-refresh and visible.

zhouyx commented 3 years ago

I think it's reasonable to have amp-auto-ad fire custom events. to @ampproject/wg-monetization @powerivq to triage. cc @lannka

llguedes commented 3 years ago

Hi @micajuine-ho I'm really glad you could take a look on our issue. This means a lot for us and even makes my heart beats faster lol. If there is anything else that we could provide you with let us know.