Skip to content

feat(tracking): track prompts in cities, asked by the engines that can answer from one (PROMPT-015, part 4) - #1658

Merged
gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-city-tracking
Oct 28, 2026
Merged

gkhngyk merged 38 commits into
ansvisor:mainfrom
cihan-gyk:feature/prompts-city-tracking

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

PROMPT-015, part 4 of 6: track prompts in cities, asked only by the engines that can answer from one.

Stacked on #1657. This PR's own change is its commits after part 3's.

A city is a new location code, <country>~<CITY> (e.g. TR~ISTANBUL). The same 51 major cities are listed in server/src/lib/cities.js and web/src/config/cities.ts, with the same ids.

  • Google AI Overviews and AI Mode ask from the city: the provider gets the city's Google name as location, beside the country.
  • The API models (OpenAI, Claude) get user_location with the city and its region.
  • ChatGPT, Perplexity, Copilot, Gemini and Grok can't target a city through the provider, so they skip city codes. There's no second country-wide run and no double cost.
  • On the plan, a city counts as one location, like a country, on every plan (a product decision).

Pre-push review fixes:

  • dd4b6b5: a city code no list names now runs on no engine, and is logged. Before, it ran country-wide and the answer was saved under the city's code.
  • e9b76a9: a test keeps the city list and the city-capable engines the same on the web and the API.
  • 8b76219: the country is named Türkiye everywhere people see it: lists, labels and docs.
    • The picker still finds it, and its cities, when someone types "Turkey" or "Turkiye".
    • @gkhngyk: the Google location names spell the country Turkiye, from one constant (GOOGLE_TURKIYE in cities.js). Could you confirm with one real Google AI Mode request for Istanbul,Istanbul,Turkiye? If Google wants another spelling, only that line changes.

Where people see it: the location picker lists cities ("City · Türkiye") with a note on which engines ask there, and a Locations view city column is marked "AI Mode · AIO · APIs".

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. In the location picker, type "ist" or "turkey": Türkiye and its cities appear, as "City · Türkiye".
  2. Add İstanbul to a prompt tracked on ChatGPT and AI Mode: only AI Mode (and the API models) run there.
  3. cd server && npx vitest run src/lib/cities.test.js src/lib/locations.test.js
    cd web && npx vitest run src/lib/region.test.ts

Browser check: local, 1024 px. The search finds Türkiye and its cities by "turkey".

Related issue

PROMPT-015 (location matrix and custom columns), spec and mockup in Drive › Prompt. No GitHub issue.

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

Full checks at the top of the stack (part 6, 29f649d):

  • server format, lint and npm test: 248 files, 3,364 tests passed;
  • web format, lint (0 errors; 7 warnings already on main), typecheck, vitest (453 files, 4,403 tests) and build: all pass;
  • schema.sql matches build-schema.sh.

A pre-push review found 9 issues; all are fixed in this stack (the fix(...) commits). Migrations 00363 and 00364 are applied on the dev database.

Follow-ups, not in this stack:

🤖 Generated with Claude Code

cihan-gyk and others added 29 commits October 28, 2026 03:46
…columns, and share them with the brand (PROMPT-015, part 1)

PROMPT-015a. A Columns panel beside the table's search:
- show or hide every column but Prompt, and reorder them by dragging or with
  the arrows;
- saved per person and brand (00363 prompt_table_views, RLS);
- an admin or manager can share their columns with everyone on the brand,
  who see them until they change their own;
- Reset goes back to the brand's view, or the default.

Nobody who never opens Columns sees a change: the default is today's
columns in today's order. The table builds its header and cells by column
id, unchanged inside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Locations view (PROMPT-015, part 2)

PROMPT-015b. A Table | Locations switch above Tracked Prompts:
- Locations shows each prompt in each location the brand tracks, side by
  side: Visibility, Position, Mentions or Citations; an average row; a Gap
  column (best minus worst location); and three cards: the weakest and
  strongest location and the prompt that differs most between them.
- Cells use Brand Visibility's Topics vs competitors shades (HEAT_SHADES,
  moved beside heatShade). A cell opens the prompt's Positions panel on that
  location; a location the prompt isn't tracked in offers + Track (its Edit
  dialog for now).
- The Columns panel can add "<metric> · <location>" columns to the table.
- getPromptLocationMatrix reads each location with the table's own reads
  (visibility summaries, position sums), side by side, so a location's
  numbers equal the table filtered to it. No migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… brand (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aving, with more countries (PROMPT-015, part 3)

PROMPT-015c. Track in more locations, from the Locations view's
+ Add location or a cell's + Track:
- pick countries or US states (LocationPicker), and the prompts to ask
  there: the one clicked, the selected, a topic, or all shown;
- Plan usage shows used → after of the plan's prompt locations before
  anything is saved, with the same arithmetic the save enforces
  (planBulkLocationChange, bulkUpdatePromptLocations);
- past the limit the dialog says what the choice needs and what is left,
  with the plan's way out (Starter: upgrade or a custom plan; Growth: a
  custom plan; Enterprise: raise the limit), and Save stays off.

Prompts can be tracked in about 50 countries (TRACKING_COUNTRIES), not 18;
a brand's own region keeps the shorter list that volumes and audits read.
PromptLimitActions moves to its own file (a page can't export it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n answer from one (PROMPT-015, part 4)

PROMPT-015d. A city is the location code `<country>~<CITY>` (`TR~ISTANBUL`),
51 major cities in both lists (server/src/lib/cities.js,
web/src/config/cities.ts; same ids):
- Google AI Overview and AI Mode ask from the city: the provider gets the
  city's Google canonical name as `location` beside the country.
- The API models (OpenAI, Claude) get `user_location` with the city and its
  region.
- ChatGPT, Perplexity, Copilot, Gemini and Grok can't target a city through
  the provider, so locationsForScraper skips city codes for them: no second
  country-wide run, no double cost. A prompt tracked only in cities runs
  nothing on them.
- A city counts one location on the plan, like a country (decision 6), on
  every plan.

Web: the location picker lists cities ("City · Turkey") with a note on which
engines ask there; the Locations view marks a city column "AI Mode · AIO ·
APIs"; Track in more locations turns a city off, and says why, when none of
the chosen prompts runs one of those engines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ound of reads (PROMPT-015, part 2)

The user's bar: data within 1–2 s of a choice. Measured locally (dev, hosted
dev DB) the matrix read took 1.4–1.8 s.
- getPromptLocationMatrix starts every read at once: the plan's engines no
  longer wait in front of the locations' reads.
- A matrix read stays a minute in the browser (loadLocationMatrix), so going
  Table ↔ Locations, or back to a location column, reads nothing again;
  switching the metric was already in the browser.
- The Locations button reads ahead on hover or focus, so the view opens on
  data already there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…their own view with the brand (PROMPT-015, part 1)

Someone looking at the brand's shared view without one of their own
changed it with every click: a member got "Only admins and managers can
share" errors, and a manager hiding one column changed it for everyone.
Changes now update the brand's view only after an admin or manager
shared their own, which sharing now also saves as theirs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able (PROMPT-015, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ations-view

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_columns-panel.tsx
… and each location once a minute (PROMPT-015, part 2)

Up to twelve locations ran two heavy aggregates each, all at once, on
every open, every read-ahead on hover and every new location column.
The server now runs at most three of them at a time, the page sends one
read at a time, read-ahead included, and each location's figures are
kept for a minute on their own, so a new location column reads only its
location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed, resumed, deleted or edited (PROMPT-015, part 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-locations

# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
…o longer shown, not to every prompt (PROMPT-015, part 3)

Track in more locations opened from a Locations view cell fell back to
every prompt shown when the cell's prompt had left the rows. It now
targets none, says to choose the prompts, and keeps the save button off
until a scope is picked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-tracking

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_add-locations-dialog.tsx
…ntry-wide under its name (PROMPT-015, part 4)

An unknown city code read as its country: Google's engines ran without a
location and the API models without a city, and both answers were saved
with the city's code. The worker now skips such a code for every engine
and logs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o, and ask Google from its cities as Turkiye (PROMPT-015, part 4)

The location lists, labels and docs say Türkiye. The picker finds it,
and its cities, typed as Turkey or Turkiye. The cities' Google location
names spell the country Turkiye, from one constant, to be confirmed
with a real request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iye name (PROMPT-015, part 4)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e same on the web and the API (PROMPT-015, part 4)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a promise (PROMPT-015, part 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit ffcdf8b.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward (8356ba3) through the stack; no new conflicts on this branch. Typecheck and lint pass on the chain tip.

@gkhngyk gkhngyk 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.

Looks good, with follow-ups

Reviewed this PR's own change (part 3's head 518770c → 773461a).

What I checked

  • City codes end to end. TR~ISTANBUL parses the same way on both sides (server/src/lib/locations.js, web/src/lib/region.ts), and cities.test.js keeps the two city lists and the city-capable engines in step. Google AI Mode and AI Overview get the city's Google name as location beside country; no other engine ever gets location (tested in cloro-scraper.test.js). The API models get user_location with the city and its region.
  • Cost. A city never causes a second, country-wide run: the engines that can't ask from a city drop the code (locationsForScraper), and the Google collapse keeps cities apart from states. A city code no list names runs on no engine and is logged, instead of running untargeted under the city's name. The progress total (totalTasks) counts the same tasks the run submits, and a job whose prompts end up with no tasks still settles (plannedTasks <= 0 stamps).
  • Plan limits. No new write path. Cities go through the existing updatePromptLocations / bulkUpdatePromptLocations server actions, which re-read the prompts' current locations, check the org's usage against the plan on the server, and reject codes isValidLocation doesn't know (so an unknown city can't be saved from the app). A city counts as one location, as the PR says.
  • Dialog. "None of these prompts runs an engine that answers from a city" disables the save; the partial case says the city still counts on the plan for the prompts that won't ask it.
  • Search. "Turkey", "Turkiye" and "Ist" find Türkiye and İstanbul; withoutMarks is a fixed, linear pass over short labels.
  • Tests on this tree: server cities, locations, cloro-scraper, workers/* (97 passed); web region, _add-locations-dialog, _columns-panel, _location-matrix (37 passed). At the top of the stack: web tsc clean, eslint and prettier clean on every touched file, full server suite passes apart from the known timing-sensitive tests under load (content-people, content-agent, page-content, audit).
  • Merge on current main: only supabase/schema.sql conflicts, and that comes from part 3's 00363.

Before merging

  • The web goes out on merge, the API doesn't. Today's API reads TR~ISTANBUL as no location at all, so a city added before the API deploy would run every engine untargeted and save those answers under the city's code. Deploy the API with this part first, or at the same time.

Follow-ups

  1. GOOGLE_TURKIYE: confirm the spelling with one real AI Mode request, as the PR asks.
  2. The per-prompt location picker on the brand's prompts page (and the suggestion card) lets anyone add a city to a prompt with no city engine. It shows only the general city note, and the city still counts on the plan. The bulk dialog blocks or warns here; the picker could do the same when none of the prompt's platforms/models answers from a city.
  3. Docs: the list has 51 cities, the guide says "about 50" (part 5 changes it to "50 major cities").

@gkhngyk
gkhngyk merged commit ceac6d4 into ansvisor:main Oct 28, 2026
4 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 28, 2026
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