Skip to content

feat: GPT modernization (Phase 0 + 2) — lifecycle events, SRA, collapseDiv, CLS reserve#3

Draft
LockeAG wants to merge 2 commits into
mainfrom
feat/gpt-modernization-phase-0-2
Draft

feat: GPT modernization (Phase 0 + 2) — lifecycle events, SRA, collapseDiv, CLS reserve#3
LockeAG wants to merge 2 commits into
mainfrom
feat/gpt-modernization-phase-0-2

Conversation

@LockeAG

@LockeAG LockeAG commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Two-phase GPT/PubAds modernization. Public-package safe — additive, opt-in, no API breakage. Forbes-MX and Fortuna y Poder unaffected.

Phase 0 — observability + SRA + truthful docs (feat(gpt))

  • Adds three slot-lifecycle CustomEvents: ad:requested, ad:response, ad:loaded
  • Maps to GPT's slotRequested / slotResponseReceived / slotOnload (filtered per-instance, cleaned up in disconnectedCallback)
  • Explicit pubads().enableSingleRequest() opt-in before enableServices()
  • Removes the @deprecated JSDoc on Slot.setTargeting (it isn't) and corrects inline comments

Phase 2 — collapseEmptyDivs + CLS reserve + typed setConfig (feat(config))

  • New DreamsAdConfig.init({ collapseEmptyDivs }) option → routes to setConfig({ collapseDiv }), the modern replacement for the deprecated pubads().collapseEmptyDivs(). Default DISABLED preserves current behavior.
  • Page-level GPT settings (lazyLoad, threadYield, collapseDiv) consolidated into a single atomic setConfig call. setCentering and setPrivacySettings stay on PubAdsService — no authoritative setConfig equivalent exists yet.
  • #computeReserveHeight falls back to this.sizing when no mapping is configured. Closes a guaranteed CLS spike for consumers using the sizing-only attribute pattern.
  • Typed PageSettingsConfig interface replaces Record<string, unknown> on googletag.setConfig. Forward-compat via index signature.

Bundle impact

Before After Δ
Raw 76.26 kB 76.76 kB +0.5 kB
Gzip 19.45 kB 19.58 kB +0.13 kB

Compatibility

  • All public attributes, properties, exports, event names unchanged
  • New events are additive — consumers listening only to existing events see no difference
  • collapseEmptyDivs defaults to DISABLED — current consumers see no behavior change unless they opt in
  • enableSingleRequest() is idempotent per GPT docs — safe even if a publisher already enabled SRA

What did NOT change (deliberately)

  • pubads().setCentering(true) — kept. No verified setConfig equivalent.
  • pubads().setPrivacySettings(...) — kept. Still the current Google API; migrating would risk compliance regressions.
  • Empty-slot collapse to minHeight: 0 on isEmpty / tracking-pixel — kept. Existing UX behavior preserved regardless of collapseDiv setting.

Verification

  • Local: pnpm build clean (verified)
  • forbes.do staging — verify slots still render
  • fortunaypoder.com staging — verify slots still render
  • Browser DevTools: confirm new ad:requested / ad:response / ad:loaded fire in expected order
  • Check console for any new GPT warnings

Release plan

Suggest cutting 0.7.0 once verified — minor bump because collapseEmptyDivs adds a new config field (semver minor for additive API).

LockeAG added 2 commits May 13, 2026 09:39
Adds three GPT slot lifecycle CustomEvents dispatched per dreams-ad-engine
instance:

  - ad:requested      → slotRequested (request sent to GAM)
  - ad:response       → slotResponseReceived (response received)
  - ad:loaded         → slotOnload (creative iframe finished loading)

Pairs with the existing ad:rendered / ad:viewable / ad:visibility events
to give consumers full funnel observability. All three filter by
container id and clean up in disconnectedCallback.

Also adds explicit pubads().enableSingleRequest() before enableServices().
SRA is GPT's default but documenting intent guards against future default
changes and matches Google's published best practice.

Fixes inaccurate JSDoc and inline comments that claimed Slot.setTargeting
was deprecated. It is not — slot.setConfig({ targeting }) is a newer batch
alternative, not a replacement.
Adds opt-in support for GPT's modern collapseDiv setConfig key, the
documented replacement for the deprecated pubads().collapseEmptyDivs()
call:

  DreamsAdConfig.init({
    collapseEmptyDivs: 'DISABLED' | 'AFTER_FETCH' | 'BEFORE_FETCH'
  })

Default 'DISABLED' preserves the existing CLS-reserve behavior — no
change for current consumers.

Also consolidates page-level GPT settings (lazyLoad, threadYield,
collapseDiv) into a single atomic googletag.setConfig() call instead of
multiple separate invocations. setCentering and setPrivacySettings stay
on PubAdsService since current GPT docs do not provide a setConfig
equivalent; comment in the code explains why.

Hardens CLS reserve height computation: when a consumer passes only the
sizing attribute (no mapping), reserve now falls back to the max
non-tracking-pixel height from sizing instead of the previous 2px
default. Eliminates a guaranteed layout shift on fill for that consumer
pattern.

Introduces a typed PageSettingsConfig interface to replace the loose
Record<string, unknown> on Googletag.setConfig — typed-key autocomplete
for known fields with an index signature for forward compatibility.
LockeAG added a commit that referenced this pull request May 14, 2026
Combined entry covering PR #3 (GPT modernization) + PR #5 (Phase 3a
diagnostics). All changes additive — no public API removals or renames.

Sections:
- Added: lifecycle events (ad:requested, ad:response, ad:loaded),
  ad:error CustomEvent + AdErrorPhase types, window.dataLayer bridge,
  debug toggle (3-tier precedence), DreamsAdConfig.openConsole(),
  Logger.dispatchAdError() helper, collapseEmptyDivs config,
  explicit SRA opt-in, PageSettingsConfig interface, CLS reserve
  fallback from sizing attribute, new exported types
- Changed: console.* sites now route through Logger (prod-quiet by
  default), firstUpdated reordered for stable slotId, 11 GPT calls
  wrapped with granular phases, targeting timeout dispatches ad:error
LockeAG added a commit that referenced this pull request May 14, 2026
Prerelease for cobertura360.mx staging verification. Combines PR #3
(GPT modernization — lifecycle events, SRA, collapseDiv, CLS reserve
fallback) and PR #5 (Phase 3a diagnostics — ad:error, Logger wiring,
debug toggle, openConsole, dataLayer bridge).

Publish with:
  pnpm publish --tag next --access public

Pinning consumers to @next isolates the RC from `latest` (still 0.6.4).
After staging verifies, the real 0.7.0 cut bumps from RC and promotes
to latest via a separate release commit on main.
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.

1 participant