Repository navigation
Description
Problem
Two related gaps in how geo-targeting is modelled.
1. Only one US state can be selected. State targeting lands on the brand, not the prompt: brands.state is a single text column (CHECK (state IS NULL OR state ~ '^[A-Z]{2}$'), see the 00043 block in supabase/schema.sql), and the UI exposes it as a single-select in onboarding, brand creation and brand settings. A brand that wants to see how answers differ between, say, California and Texas has to choose one — even though prompts.regions is already a text[] and country-level targeting has always been multi-select.
2. Quota ignores how much tracking a prompt actually buys. Plan limits are enforced on the row count of prompts — getOrgPromptCount and the cap check in savePromptSet both count rows. But the tracking cost scales with regions: the worker computes prompt × (models + scrapers) × regions (tracking-worker.js#L178-L185). So one prompt tracked in 3 regions consumes 3× the scraper spend of a single-region prompt while counting as 1 against a 50-prompt plan. Adding multi-state targeting on top of that widens the gap further.
Proposal
Treat prompt × location as the billable unit, and let a prompt target several US states.
Quota: a prompt targeting N locations counts as N against maxPrompts. The capacity endpoint and the save-time cap both switch from row counts to the summed location count, and the wizards' inline counter ("X of 50 used") reflects the same number so users see the cost before they save rather than after.
Multi-state: two shapes are worth weighing before implementation — whoever picks this up should pick one deliberately and note why:
- extend the existing
prompts.regionsarray with sub-country codes (US-CA,US-TX), keeping one list as the single source of truth for "where is this tracked"; or - add a separate per-prompt
states text[], leavingregionsas country-level.
The first keeps one code path for counting, quota and task expansion; the second avoids touching existing region parsing. Either way the value belongs on the prompt rather than the brand, so different prompts can target different states.
Note that Google AI Overview / AI Mode use a different sub-country mechanism and never read brands.state — that asymmetry needs to survive the change (or be addressed explicitly).
Migration and billing risk — please handle deliberately
This changes what an existing customer's plan allows. Any brand that already tracks prompts across multiple regions will jump in usage the moment the new counting lands, and some orgs will land over their limit without having done anything.
Decide up front and state it in the PR:
- do existing prompt sets get grandfathered until their next save, or is the new count applied immediately?
- does exceeding the cap block only new saves, or does it also stop tracking for existing prompts?
- is there a warning surface before it bites (Settings → Billing, or the prompts page)?
A query over current data — how many orgs would exceed their plan under the new counting — should come before the code, since it decides whether this needs a comms plan.
Acceptance criteria
- A prompt can target multiple US states; tracking produces one result per prompt × location, as it already does for regions.
- Quota counts locations, not prompt rows, in the capacity endpoint, the save-time cap and the wizard counters — with the error message spelling out the location math.
- The chosen storage shape is documented in the PR, along with how Google AIO / AI Mode sub-country targeting continues to work.
- Existing customers' migration path is explicit and implemented (grandfathering or immediate), not left implicit.
Activity
gkhngyk commentedon Aug 10, 2026
Clarifying the billable unit, since it drives the whole design:
A location is every place a prompt is actually sent to — country and state alike. One prompt tracked in the US and Germany is 2; one prompt tracked in California and Texas is 2; one tracked in Germany plus two US states is 3. The rule follows the tracking cost directly: each location produces its own set of scraper and model calls (
prompt × (models + scrapers) × locationsin the worker), so it is the unit the plan should meter.Two consequences worth stating explicitly:
gkhngyk commentedon Aug 10, 2026
The check has to cover editing, not just adding
Concretely: an org on a 50-prompt plan that has used all 50 must be refused when it opens one existing prompt and adds a second country or state to it. That request grows tracked locations from 50 to 51 exactly like creating a 51st prompt would, so it has to fail the same way, with the same message.
That's not how the code is shaped today, and two things stand in the way:
updatePromptcannot change locations at all. It only acceptstext,category,platforms,modelsandisActive(prompt.ts#L302-L311) —regionsisn't in the payload, so editing a saved prompt's targeting isn't possible in the product right now. Multi-state targeting is worth little without it, so that capability belongs in this issue.updatePromptenforces no plan limit, which was harmless while quota counted rows (an edit never changed the count) and becomes a hole the moment locations are the unit.So every write path that can raise the location total needs the same guard, not just the two that have it today:
savePromptSetaddPromptToSetenforceLimit(maxPrompts)addPromptToBrandupdatePromptregionsThe rule to implement is the delta, not the total: an edit should be measured by how many locations it adds, so that re-saving a prompt unchanged at exactly the limit still succeeds, while adding one more location at the limit fails. Removing a location must free capacity immediately.
Worth mirroring in the UI too — if the org is at its cap, the location selector should show why an additional pick is unavailable rather than failing after the fact.
gkhngyk commentedon Aug 10, 2026
Cloud-only: self-host must stay unmetered
The location-based counting is a plan limit, so it applies on cloud only. Self-host has no prompt ceiling today and must not gain one here.
The existing plumbing already guarantees this and simply needs to be left intact:
getPlanshort-circuits toPLANS.self_hostedwheneverIS_CLOUD !== 'true'(server/src/config/plans.js#L158), and that plan carriesmaxPrompts: -1, which every cap check reads as unlimited (maxPrompts !== -1gates the rejection). The same-1is mirrored in web/src/config/plans.ts for the client-side capacity display.So the requirement for this work is a negative one — don't regress it:
self_hosted; the sentinel must keep flowing through the new location-count checks exactly as it does through today's row-count ones.-1, so it must stay unmetered too.Worth a test that pins it: a self-host org at any number of prompts and locations can still add another. It is the kind of guarantee that breaks quietly, since a cloud-only test suite would never notice.
gkhngyk commentedon Aug 23, 2026
Scope note for part 2, out of the #781 review: the plan cards still label
maxPromptsas "N prompts" (web/src/components/settings/plan-switcher.tsxand the onboarding plan step). That stays literally accurate while the UI can only create single-location prompts, but the moment multi-location targeting ships the displayed unit diverges from the metered one. Part 2 should relabel these to prompt locations (i18n strings included) alongside the multi-state work.fix(prompts): aggregate the location quota count in Postgres
feat(prompts): count plan quota by tracked location rather than promp…
gkhngyk commentedon Aug 24, 2026
Part 2 is up in #783 (part 1 was #781, merged).
One deploy-ordering constraint worth repeating outside the PR body:
00071_prompt_state_locations.sqlmust be applied after the server deploy, not before. It rewrites the one brand that usesbrands.statefrom['US']to['US-DE'], and the currently running worker passes a prompt's region straight through as Cloro'scountryfield — so that row would be submitted as country "US-DE" and rejected, failing that brand's tracking until the deploy landed. The new worker parses the code first, so once it is live the order stops mattering. The migration is deliberately left unapplied.feat(prompts): target prompts at multiple countries and US states (#783)
feat(prompts): break the per-prompt health columns down by location (#…
feat(tracking): ask Google AI Overview and AI Mode from a US state, b…