Automattic/newspack-popups

"Load" events fire only intermittently in AMP Plus using non-AMP ads

Closed this issue Β· 8 comments

dkoo commented

On sites using AMP Plus + non-AMP ads, "Load" events firing on the ini-load AMP Analytics trigger only happen intermittently, not on every pageview as would be expected.

Leaving the original description for the record:

We have a conflict between the AMP Analytics trigger ini-load and AMP Plus behavior, specifically when JS causes the document layout to shift (a big AMP no-no, but allowed in AMP Plus). If JS causes a content layout shift after the document loads, ini-load event triggers will never happen. Our "Load" events are supposed to fire on this ini-load trigger when a prompt is loaded and ready to display.

To test:

  1. On a test site with Google Analytics connected, disable the AMP plugin.
  2. On the front-end, open the dev tools > network tab and filter by "Newspack Announcement" (which will display event requests to GA).
  3. Observe that "Seen" events fire as expected when a prompt is shown in the viewport, but that "Load" events fire only intermittently, not on every pageview.
  4. Turn on AMP. Repeat step 2 and observe that "Load" events fire on every pageview as expected.
  5. Turn on AMP Plus and repeat step 2. Observe that "Load" events still fire on every pageview as expected.

I can't reproduce the issue, with layout-shifting above-header ad, the Load event (both for overlay and inline prompts) does fire.

Asana task with more context: 1202719992789620-as-1203051680681375

dkoo commented

I can't reproduce the issue

I can't explain why that isβ€”I'm able to reliably reproduce on my local test site and RAS1, across browsers. The fix in #980 also reliably fixes the issue across browsers for me in both my local test site and RAS1.

I also note the the evidence from two live sites which supports (but doesn't prove) this theory:

  • Site A does not use non-AMP ads and has no ad in the above-header placement. They're seeing "Load" and "Seen" events in the expected proportion.
  • Site B does use non-AMP ads, and has an ad in the above-header placement. They're seeing far fewer "Load" events than "Seen" events reported.
dkoo commented

@adekbadek With more testing, I think you're right! ini-load may be a red herring. I notice on RAS1 that the "Load" event does occasionally fire even with the content shifting. But it's very intermittent, in my experience. On most pageviews, I do not see "Load" events firing when AMP Plus is on. If I turn off AMP Plus ads with the NEWSPACK_AMP_PLUS_ADS_DISABLED constant, "Load" events seem to fire more consistently on every pageview. Does that line up with what you're seeing?

dkoo commented

The intermittent firing of "Load" events also happens on live Site B (which uses non-AMP ads).

dkoo commented

I have a new hypothesis on this. It turns out Site B in this case is using AMP Transitional mode, which causes analytics events to be processed by vanilla JS instead of AMP Analytics. Automattic/newspack-plugin#2065 fixes the event handler used to fire the ini-load events in non-AMP so that they're much less likely to be blocked by third-party resources.

πŸŽ‰ This issue has been resolved in version 2.6.1 πŸŽ‰

The release is available on GitHub release

Your semantic-release bot πŸ“¦πŸš€

πŸŽ‰ This issue has been resolved in version 2.7.0-alpha.2 πŸŽ‰

The release is available on GitHub release

Your semantic-release bot πŸ“¦πŸš€