Skip to content

feat: execute creative and provider lifecycle tracking - #7389

Open
vpol wants to merge 4 commits into
mainfrom
codex/ad-slot-lifecycle
Open

vpol wants to merge 4 commits into
mainfrom
codex/ad-slot-lifecycle

Conversation

@vpol

@vpol vpol commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Execute Skadi's versioned lifecycle action map when an ad is fetched, rendered, becomes visible, or is clicked. Existing impression pixels retain the original viewport marker and image path, including the old-browser fallback and no focus requirement for impressions.

  • Gate the rollout with the GrowthBook feature ad_slot_lifecycle, default false. Strip lifecycle configuration before caching or returning ads when disabled, and guard actions on already-cached creatives. Unresolved feature flags continue serving legacy ads.
  • Add typed lifecycle events and fetch/render hooks across display ad slots. Visibility milestones measure the creative and include visible, half-visible, visible-for-1s, and viewable.
  • Preserve default native viewability callbacks and first-party viewed pixels. Additional visibility hooks do not move the impression trigger. Switching the flag off preserves mounted card roots, impression images, and completed viewability measurement.
  • Run pre-render in a layout effect after DOM mount and before paint; run post-render in a passive effect. The creative renders on the first commit.
  • Capture regular and middle-button ad clicks on existing card roots across feed, sidebar, comments, squad discovery, and widget ads. No additional wrapper DOM. Compact menus forward only the data-ad-click marker; unrelated advertise and upgrade links remain excluded.
  • Keep the original request error semantics: non-JSON initial failures reject so React Query retries, and failed refreshes reject even for JSON error bodies. Fetch-error transitions observe failures without converting them into cached no-fill results.
  • Carry lifecycle actions for sponsor-strip creatives while retaining existing impression, click, viewed, and visible-time behavior. Wait for resolved consent before measuring lifecycle milestones or executing actions, so pending milestones are not lost.
  • Deduplicate non-click actions by creative generation in a bounded map, including cloned/restored creatives. Every click remains eligible. Limit analytics event actions to known AdActions names. New non-impression URL actions use HTTPS and macro substitution; legacy impression images retain existing URL behavior.

Post-fetch semantics: run actions for every creative returned in the sponsor pool, including those not displayed. This is intentional: it records availability/fetching rather than an impression. Taboola AVAILABLE maps to post-fetch, as agreed. Impression and visibility actions still depend on the mounted creative's existing triggers.

Skadi configuration and provider mappings: https://github.com/dailydotdev/skadi/pull/577 (deployed). Response-defined actions begin at post-fetch; pre-fetch is available as a local fetch transition. Non-slot consumers, such as email rendering, do not gain browser lifecycle hooks.

Validation: full webapp suite (90 suites, 726 tests), shared ad/monetization/feed-widget regression suites (66 suites, 566 tests), webapp typecheck, shared and webapp lint/format, and the changed-file strict TypeScript guard. Regression coverage includes default-off and unresolved flags, cached-ad rollback, legacy impression fallback, initial-request retries, consent-delayed sponsor milestones, wrapper-free click capture including portaled menus, generation deduplication, and analytics filtering.

Preview domain

https://codex-ad-slot-lifecycle.preview.app.daily.dev

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
daily-webapp Ready Ready Preview Nov 20, 2026 11:17am UTC
1 Skipped Deployment
Project Deployment Actions Updated
storybook Ignored Ignored Preview Nov 20, 2026 11:17am UTC

Request Review

@capJavert capJavert left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against dailydotdev/skadi#577: the lifecycle wire shape (version: 1, on, {type: pixel|event}), all 9 event names, legacy /v1/a + sponsor-strip fields, and the viewable contract (viewable impression event + &viewed=true pixel) all match. Thanks for the detailed description.

Blocking: please put the apps-side lifecycle execution behind a GrowthBook flag

Skadi#577 already attaches lifecycle to every display ad (displayAdLifecycle runs unconditionally for Custom/Post/Squad/AdvertiserBar/Digest/Engagement). So this PR is not opt-in per configured creative: the moment it ships, 100% of ad traffic moves to the new Configured* paths, on webapp and extension. The only way to turn it off would be a revert plus a new extension release, and extension builds already in the wild would keep running it.

The client already has the right seam: with lifecycle absent, AdPixel, AdSlot and AdViewability all fall back to today's behaviour. Please add a flag (e.g. ad_slot_lifecycle, default false). When it is off, drop lifecycle from the ad before it is cached / rendered, in useAdQuery, useFetchAd (feed + rotation/refresh) and useSponsorStripAds. Then we can ramp it gradually, per platform, while watching impressions / viewable impressions / clicks, and switch it off instantly if numbers move. The behaviour changes that sit outside the lifecycle path (lib/ads.ts error handling, DropdownMenu) are not covered by such a flag, which is another reason to keep them minimal.

Behaviour that changes at merge: needs explicit approval

Because of the above, these go live for everyone immediately, without anyone configuring a creative:

  • Provider pixels mapped by Skadi (e.g. post-fetch and click beacons) start firing for every ad.
  • Direct/BSA/EthicalAds impression pixels should be unchanged (same list as pixel). Please confirm on the preview with a real response.

The inline comments cover the rest. For each one that changes existing behaviour, please either confirm it is intended and get explicit approval, or revert it to how it was if it changed by accident.

Not verified by me: I did not run the tests or the preview locally (CI is green), and provider pixels and the sponsor strip have not been checked end to end on real responses.

Reviewed by AI.

Comment thread packages/shared/src/lib/ads.ts Resolved
Address review feedback with a default-off rollout flag, legacy fetch retry semantics, wrapper-free click capture, pre-paint render hooks, consent-safe sponsor milestones, bounded generation deduplication, and known analytics event names. Preserve mounted impression and viewability trackers when disabling lifecycle for cached creatives.

@capJavert capJavert left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of dd1264b: thanks. The flag, error handling, dropdown, consent, pre-render, wrapper-free click capture, dedup and event allowlist are all addressed. One remaining issue (see inline): the lifecycle flag shouldn't be part of the query keys. It's not a problem at merge with the flag off by default, but please fix it before ramping.

Reviewed by AI.

consent?.consentString ?? '',
consent?.consentExists ?? '',
isLoggedIn,
isLifecycleEnabled,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix before ramping ad_slot_lifecycle: the flag in the query key causes a refetch. useConditionalFeature returns the default (false) until GrowthBook is ready, then switches to true for the rollout cohort. Because the flag is part of the key, that switch fetches a new ad for the post page, sidebar, comment and hero slots. The slot can swap creative after the first one was shown, which costs an extra request and possibly an extra impression. That only happens to flag-on users, so it would also skew the metrics we watch during the ramp.

Unlike the refresh engine flag, this flag doesn't change the request (Skadi always sends lifecycle), so there's no need to key or wait on it. Suggested fix:

  1. Remove isLifecycleEnabled from the key.
  2. Move resolveAd out of queryFn into select: resolveAd, so the raw response is cached and the flag is applied on read.

Removing it from the key alone is not enough: queryFn would still strip lifecycle before caching, so ads fetched before GrowthBook is ready would stay stripped for their whole cache lifetime. The kill switch still holds with select, since every action already checks isEnabled at run time.

Accepted trade-off: post-fetch actions don't fire for an ad fetched before the flag resolves, because useAdSlotFetch sees it as off at that moment. Render, visibility and click actions still fire once it resolves.

Reviewed by AI.

AdPlacement.SponsorStrip,
consent?.gdprApplies,
consent?.consentString ?? '',
isEnabled,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as in useAdQuery. isEnabled in the key refetches the strip when the flag resolves to true, which can deal a different set of creatives after the first set was shown. The read side already strips (pools runs resolveAd over data), so please:

  1. Remove isEnabled from the key.
  2. Drop the resolveAd map in queryFn and cache the parsed creatives as received.

Reviewed by AI.

This branch was successfully deployed

2 active (1 outdated) deployments
Preview – daily-webapp — dd1264b2 Deployed Nov 20, 2026 by vercel[bot]
Preview – storybook — 18e4ef80 Deployed Nov 17, 2026 by vercel[bot]
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.

2 participants