Skip to content

feat: optional US state-level geo-targeting for AI prompt tracking - #579

Merged
gkhngyk merged 1 commit into
mainfrom
feature/us-state-geo-targeting
Aug 2, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/us-state-geo-targeting

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

US brands can now optionally pick a state (USPS two-letter code) and get state-localized AI answers: the tracking worker forwards the state to the scraping provider on AI-endpoint tasks, which routes the request through an in-state proxy.

  • 00043 migration — nullable brands.state with a two-letter CHECK; NULL = nationwide, so every existing brand keeps today's behavior. Already applied to the hosted DB.
  • Static US_STATES list (50 states + DC) in web/src/config/prompt-options.ts — no runtime dependency on the provider's states endpoint.
  • "State (optional)" select on the Add Brand market step, the onboarding market step, and the brand settings General tab (Region is now editable there too). The field only renders when the region is US, includes an explicit "Nationwide (no state)" option, and switching the region away from US clears the value both in the UI and in updateBrand.
  • Server — the worker reads brands.state and passes it to submitScraperTask; buildRequestBody includes state only when country === 'US' and the task is an AI endpoint (chatgpt-web, chatgpt-shopping, copilot-web, grok-web, perplexity-web, gemini-web). Google AIO / AI Mode payloads are untouched — they use a different sub-country mechanism.
  • 6 new unit tests cover the request-body matrix (AI endpoints, shopping, Google exclusions, non-US regions, missing state).

Related issue

Closes #554

Type of change

  • feat — New feature

How to test

  1. Brand settings → General: with region US, pick a state and save; switch region to another country — the state field disappears and the stored value clears.
  2. Create a brand (Add Brand or onboarding) with region US + a state; verify brands.state holds the code.
  3. Run tracking for a US+state brand: AI-endpoint requests to the provider include state; google-aio / google-aimode payloads don't.
  4. Brands without a state (or non-US) behave exactly as before.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Brands with region US can now pick an optional USPS state; the tracking
worker forwards it to the scraping provider so AI answers localize to
that state.

- 00043 migration: nullable brands.state (two-letter check); NULL keeps
  today's nationwide behavior for every existing brand
- Static US_STATES list (50 + DC) in web config — no runtime dependency
  on the provider's states endpoint
- State select (visible only when region is US, with an explicit
  Nationwide option) on the Add Brand step, onboarding market step, and
  brand settings General tab; switching region away from US clears it
  in the UI and in updateBrand
- buildRequestBody adds state only when country is US and the task is
  an AI endpoint (chatgpt-web/-shopping, copilot, grok, perplexity,
  gemini); Google AIO / AI Mode payloads are untouched — 6 new tests

Closes #554
@gkhngyk
gkhngyk merged commit ce85112 into main Aug 2, 2026
5 checks passed
@gkhngyk
gkhngyk deleted the feature/us-state-geo-targeting branch August 2, 2026 21:33
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.

US brands: optional state-level geo-targeting for AI prompt tracking

1 participant