Skip to content

feat: Choice Ad placement with 50/50 A/B test#496

Open
leo-gravity wants to merge 1 commit intoCodebuffAI:mainfrom
leo-gravity:gravity/choice-ad-placement
Open

feat: Choice Ad placement with 50/50 A/B test#496
leo-gravity wants to merge 1 commit intoCodebuffAI:mainfrom
leo-gravity:gravity/choice-ad-placement

Conversation

@leo-gravity
Copy link
Copy Markdown

@leo-gravity leo-gravity commented Apr 9, 2026

Summary

  • Adds a new Choice Ad placement type that renders 4 ads as side-by-side cards (CTA button + domain per card, hover effects, theme-aware) instead of a single banner
  • 50/50 A/B test: users are deterministically assigned to either the existing banner or the new choice variant via SHA-256 hash of their userId
  • Gracefully handles partial fills — if Gravity returns 1, 2, or 3 ads instead of 4, the cards expand to fill the available width

Files changed

File Change
web/src/app/api/v1/ads/_post.ts A/B variant assignment, requests 4 placement IDs for choice variant, stores all ads to DB
cli/src/hooks/use-gravity-ad.ts New AdData union type, choice ad cache, fires impressions for all choice ads
cli/src/components/choice-ad-banner.tsx New — 4-column card layout with calculated widths, uniform height, hover effects
cli/src/chat.tsx Renders ChoiceAdBanner when variant is choice

Before launching: Gravity dashboard setup required

@jamesgravity — Before enabling this in production, 4 new placements need to be created on the Gravity publisher dashboard for Codebuff:

Placement type Placement ID Description
below_response choice-ad-1 Choice Ad slot 1
below_response choice-ad-2 Choice Ad slot 2
below_response choice-ad-3 Choice Ad slot 3
below_response choice-ad-4 Choice Ad slot 4

These should use the same placement type (below_response) as the existing code-assist-ad placement. The backend requests all 4 in a single API call for users in the choice variant. If fewer than 4 ads are available, the UI adapts automatically.

The existing code-assist-ad placement remains unchanged and continues to serve the banner variant for 50% of users.

Test plan

  • Create the 4 placement IDs listed above on the Gravity dashboard
  • Verify choice variant renders 4 cards when all placements fill
  • Verify partial fills (1-3 ads) render correctly with cards expanding
  • Verify banner variant is unchanged for users in the control group
  • Verify hover effects work on each card (border + text highlight)
  • Verify clicking a card opens the correct clickUrl
  • Verify impressions fire for all visible choice ads
  • Verify credits accumulate correctly for choice ad impressions

🤖 Generated with Claude Code

Introduces a new "Choice Ad" placement that shows 4 ads as
side-by-side cards instead of a single banner. Users are
deterministically assigned to either the existing banner or the new
choice variant via a hash of their userId (50/50 split).

Backend: requests 4 placement IDs (choice-ad-1 through choice-ad-4)
from Gravity API for the choice variant. All returned ads are stored
to ad_impression and impressions fire for each card.

Client: new ChoiceAdBanner component renders equal-width bordered
cards with CTA button + domain per card, hover effects, and
theme-aware styling. Gracefully handles partial fills (1-4 ads).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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