Skip to content

✨ [amp-analytics] Let AMPHTML ads opt in to initializing while hidden - #40580

Open
jburger424 wants to merge 2 commits into
ampproject:mainfrom
jburger424:amp-analytics-initialize-when-hidden
Open

jburger424 wants to merge 2 commits into
ampproject:mainfrom
jburger424:amp-analytics-initialize-when-hidden

Conversation

@jburger424

Copy link
Copy Markdown

Closes #40579

The AMPHTML ad iframe runtime (amp4ads-v0.js) loads a creative while the document is hidden (for example, in a background tab), while <amp-analytics> waits for ampdoc.whenFirstVisible() before initializing. As a result, ini-load is sent when the page is first shown rather than when the creative loaded, and never if the page is never shown.

Changes

  • amp-analytics.js: Allow <amp-analytics data-initialize-when-hidden> in inabox (amp4ads-v0.js) to initialize when the document is hidden and document.prerendering is false.
  • analytics-root.js: Measure ini-load with whenContentIniLoadMeasure in inabox before first visibility, since IntersectionObserver does not report in a hidden document.
  • events.js: Defer VisibilityTracker.add until ampdoc.whenFirstVisible() when the document has not been visible yet, so visible and hidden triggers still start from first visibility.
  • amp-analytics.md & unit tests: Document data-initialize-when-hidden and cover hidden inabox initialization, prerendering, non-inabox documents, ini-load measurement, and deferred visibility tracking.

/cc @ampproject/wg-components @ampproject/wg-ads-reviewers

@amp-bundle-size
amp-bundle-size Bot requested a review from alanorozco November 18, 2026 22:16
@erwinmombay
erwinmombay requested review from erwinmombay and removed request for alanorozco November 18, 2026 22:41
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jburger424
❌ erwinmombay
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I2I: Let amp-analytics in AMPHTML ads initialize while the document is hidden

3 participants