Skip to content

feat(action-center): measure opportunity actions on their own basket - #956

Merged
gkhngyk merged 1 commit into
mainfrom
feature/basket-measurement
Oct 6, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/basket-measurement

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Second PR of Phase 4 in #857. The Action Center measures a completed action over a window before it was raised and one after it closed, and it reads the whole brand. That suits signal-driven actions. A content opportunity, though, answers maybe 20 of a brand's 700 prompts, and brand-wide numbers bury its effect. The spec asks for the results of a published piece to be measured "for the same basket" (§28). Actions sent from an opportunity are now measured that way.

What is measured (lib/action-center/basket-metrics.js)

The windows are the same as before; only the scope changes.

Metric Over the basket
ai_visibility Share of the prompts' engine-days where the brand was mentioned or cited
share_of_voice The brand's visible engine-days against the competitors' on the same prompts
competitor_lead The brand's visibility minus the strongest competitor's, in points (negative while behind)
mentions Answers to those prompts that mention the brand
citations Citations of the target pages, including variants with a query, www. or a trailing slash
ai_referral_traffic GA AI sessions landing on the target pages
  • A metric the window cannot answer stays unmeasured rather than zero, as the existing validation does. Examples are a basket with no answers, an opportunity with no pages, or a brand without GA.
  • All six read higher-is-better, so the existing deriveOutcome applies unchanged.
  • validation records the scope with the prompt and page counts.

Data (migration 00113)

  • opportunity_basket_metrics returns one window's raw figures.
  • Prompt figures come from the Insights rollups.
  • Page citations come from citation_urls, narrowed through its domain index before the URL match, plus prompt_result_citations.
  • Traffic comes from ga_ai_traffic_stats.
  • On the main test brand, a 20-prompt, 2-page basket reads a 30-day window in about 0.4 s.

Which prompts

  • The prompt ids are now fixed in the payload when an opportunity is sent, so a later re-clustering does not change what the action is judged by.
  • Actions sent before this change take them from the opportunity's clusters as they are now.

UI

  • The new metric's label, "Lead over top competitor", is added to the KPI registry copy used by History and the opportunity's Results card.
  • The Results card shows points with a sign.

Tried on production data

  • The function is applied to the hosted database (recorded there as 00112_opportunity_basket_metrics; the repo file became 00113 after main took 00112).
  • The four opportunity actions on production were measured read-only, over the 30 days before each was raised and the last 30 days. Every metric returned a value or a deliberate null.
  • The rank tracker opportunity's 2 pages had 418 citations in the window, which the brand-wide totals would have hidden. Its basket trails the strongest competitor by 81 points.

Related issue

Part of #857 (Phase 4)

Type of change

  • feat — New feature
  • test — Adding or updating tests

How to test

  1. Complete an action sent from an opportunity. Once its after-window has passed, the nightly validation sweep measures it.
  2. History and the opportunity's Results card show the six basket metrics before and after, and validation.scope.kind is basket.

basket-metrics.test.js covers URL scoping, the metric arithmetic and unmeasured metrics.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint, yarn typecheck, yarn format:check, yarn test (418) and yarn build pass (run from web/)
  • yarn lint, yarn format:check and yarn test (1002) pass (run from server/)
  • supabase/schema.sql rebuilt with build-schema.sh

🤖 Generated with Claude Code

The Action Center measured every completed action on the whole brand. For
a piece of content answering 20 of a brand's 700 prompts, that buries its
effect, and the spec asks for results "for the same basket" (#857, Phase 4).

- Actions sent from a content opportunity are measured over the same
  before/after windows on their own prompts and pages: AI visibility and
  share of voice on the prompts, lead over the strongest competitor, brand
  mentions, citations of the target pages, and AI referral traffic to them.
  A metric the window cannot answer stays unmeasured, not zero.
- Migration 00113 adds opportunity_basket_metrics, reading the Insights
  rollups, the citation tables and GA AI traffic for one window.
- The prompt ids are fixed on the action when it is sent, so a later
  re-clustering does not change what it is judged by. Actions sent before
  take them from the opportunity's clusters.
- "Lead over top competitor" has a label, and points render with a sign.
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 6, 2026
@gkhngyk
gkhngyk merged commit a275b5b into main Oct 6, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the feature/basket-measurement branch October 6, 2026 20:47
gkhngyk added a commit that referenced this pull request Oct 7, 2026
Two migrations shared 00113 after #956 merged alongside another. This
moves opportunity_basket_metrics to the next free number. The file only
create-or-replaces a function, so running it again is harmless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant