Skip to content

fix(tracking): read a fan-out an engine joined with semicolons as each search - #1625

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/tracking-fanout-split
Oct 28, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/tracking-fanout-split

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The agent wrote "How does a ChatGPT subscription;Gemini subscription;Google AIO subscription affect…" as one FAQ question. An engine had returned its fan-out searches joined with ;, and they were kept as one.

  • The tracker (cloro-scraper.js, normalizeSearchQueries) splits semicolon-joined searches from now on.
  • The editor (sources.ts, fanoutQueries) splits stored ones too, and merges a search that repeats: platforms together, searches summed.
  • Merged rows are re-sorted by search count, for the brief's top 40.
  • The person's Sources choices carry over: a split search with no choice of its own inherits the joined row's. One that came only from excluded rows stays excluded.
  • HTML entities aren't split (what&#39;s). The server and the web use the same rule: /(?<!&#?\w+);/u.

The tracker part needs the API deploy. Stored data is read split by the web at once.

Related issue

None. From Ansvisor’s production test of the Content Editor and Send to CMS (2026-10-27).

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. cd server && npx vitest run src/lib/cloro-scraper.test.js
  2. cd web && yarn vitest run src/lib/content/sources.test.ts

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

Checked together with the other PRs from the same test (one integration tree of all eleven on main 3f6a4d4):

  • server/: npm run format, npm run lint and npm test (3,349 tests).
  • web/: yarn format, yarn lint (0 errors, the 7 earlier warnings), yarn typecheck, yarn test (4,385 tests) and yarn build.
  • This branch's own tests were also run on it alone.

Follow-up: the Query Fan-out page and the SQL roll-ups still show old joined rows next to new split ones.

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 28, 2026 00:59
…h search

A page the Content Agent wrote had an FAQ question "How does a ChatGPT
subscription;Gemini subscription;Google AIO subscription affect
tracking?": a fan-out used in its own words, as the fan-out rules ask,
but it was three searches an engine sent as one.

- The tracker reads an engine's searches joined by semicolons as each
  search (cloro-scraper.js normalizeSearchQueries), with its engine and
  platform, from now on.
- The editor's sources read the fan-outs stored before the same way
  (fanoutQueries in sources.ts): one met twice is one row, its platforms
  together and its searches added up. The agent's fan-out rules and the
  Rules tab get the searches one by one.

Split out of fix/agent-fanout-headings (230f7f54); the headings' capital
is its own branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… them by searches again, and never split an HTML entity

Review fixes for reading a joined fan-out as each search:

- A choice in Sources is stored under the fan-out as it was (the joined
  query): a search with no choice of its own now keeps it, so "a;b;c" left
  out keeps a, b and c out. One also met as its own row, left in, stays in.
- Searches added up across joined fan-outs are put in order of how often
  they were searched again: the brief keeps the first ones (its fan-out
  limit), and a search met twice can now be among them.
- The split never cuts an HTML entity ("what&#39;s", "&amp;"), on the
  tracker and in the editor alike, with the same rule; both read "one;" as
  "one" and drop an empty search.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk a question for the tracking side, asked here since this PR is about Cloro's data (Ansvisor's request): could you run this once with the production Cloro key and paste the output here? It lists the countries each engine actually supports. Cloro's docs say GET /v1/countries is the only source of truth, and the lists differ per engine. We'll use it to check PROMPT-015's tracking-country picker, which will also read these lists daily on its own (its PRs come next).

for m in chatgpt perplexity copilot gemini aimode aioverview google; do echo "$m: $(curl -s -H "Authorization: Bearer $CLORO_API_KEY" "https://api.cloro.dev/v1/countries?model=$m")"; done

Also worth a look: Cloro's docs say Grok was discontinued on 15 Oct 2026, and grok isn't in the countries endpoint's model list anymore, while we may still offer grok-web.

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

What I checked:

  • The split rule. /(?<!&#?\w+);/u is the same on both sides. what&#39;s, &amp; and &#x27; stay whole. Leading, trailing and doubled semicolons give no empty search. A name like "AT&T;Verizon" stays one search, which is the safe way to be wrong. It stays fast on long entries.
  • New data. The tracker stores each search as its own item, with the entry's engine and source_platform. Everything that counts fan-outs counts answers, not items: content_draft_sources, report_query_fanout, brand_prompt_fanout_queries, fanout.ts and prompt-improve.js all dedupe within an answer. So a search that ends up twice in one answer after the split is still counted once.
  • Choices. A split search with no choice of its own takes the joined row's choice. If it came from several rows, it's left out only when all of them were. Its own choice, made since, wins. What the agent gets is the web's split list (brief.ts → sources.fanouts → numberSources), so its fan-outs and their refs match the Sources tab.
  • Tests.
    • On this branch, cloro-scraper.test.js passes (41 tests), and sources.test.ts passes (13), with brief.test.ts and _sources-tab.test.tsx beside it.
    • With main's source under the same tests, 2 server and 5 web tests fail.
  • Merge. Clean on main 3f6a4d4.

Before the API deploy: the editor splits the stored rows as soon as the web is out. Answers that come in before the API deploy are stored joined, and the editor splits them too. Nothing breaks.

Follow-ups:

  1. One answer can be counted twice in the merged rows. searched is count(distinct answer_id) per stored query string. Adding up rows on the web is right when the rows come from different answers, for example an old joined row next to a new split one. It counts an answer twice when one stored answer has the same search in two entries, such as "a;b" and "a", or "a;b" and "a;c". Then "a" reads 2 for one answer, and it can move up the brief's top 40. The exact fix is to split in SQL, so the distinct count sees the answer once. In content_draft_sources' fanout_rows, read each part of q.item->>'query' with regexp_split_to_table(…, '(?<!&#?\w+);'), trimmed and with empty parts dropped. The web's merge is then only a safety net for case variants. It needs a migration, so a separate PR is fine. Until then, how often it happens can be measured on the stored answers.
  2. The Query Fan-out page and the SQL roll-ups, as you note: the same SQL split would fix report_query_fanout* and brand_prompt_fanout_queries for old rows too.

@gkhngyk
gkhngyk merged commit c2a5a19 into ansvisor:main Oct 28, 2026
6 checks passed
gkhngyk added a commit that referenced this pull request Oct 28, 2026
…from, read daily from the provider (PROMPT-015, part 5) (#1659)

* feat(prompts): let a person show, hide and order the Tracked Prompts 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]>

* feat(prompts): compare each tracked prompt across its locations in a 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]>

* docs(prompts): describe the Columns panel and sharing a view with the brand (PROMPT-015, part 1)

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

* docs(prompts): describe location columns and the Locations view (PROMPT-015, part 2)

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

* feat(prompts): add locations to many prompts at once, priced before saving, 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]>

* feat(tracking): track prompts in cities, asked by the engines that can 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]>

* fix(prompts): find a city typed without its marks, İstanbul as Ist (PROMPT-015, part 4)

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

* fix(prompts): show the biggest gap card's values as whole numbers (PROMPT-015, part 2)

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

* perf(prompts): open the Locations view on data already read, in one round 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]>

* feat(tracking): offer and run only the countries each engine answers from, read daily from the provider (PROMPT-015, part 5)

PROMPT-015e. The tracking provider supports a different set of countries
per engine, and asking an engine in a country it doesn't support fails;
its GET /v1/countries?model= is the only source of truth (its docs publish
no list). So:
- The daily run reads every engine's list before tracking
  (refreshCloroCountries) into cloro_countries (00364). A list that can't be
  read keeps the last one; an empty or malformed answer never empties it.
  No provider key (self-hosted, local): nothing read, nothing restricted.
- The tracking run skips an engine in a country it doesn't support
  (supportedLocations), and logs how many pairs it skipped: no failed task,
  no spent credit.
- The location picker offers the countries the engines answer from, named
  by the runtime's own region names, with "not on <engine>" where one
  doesn't; cities only where Google's engines answer. Before the first read
  it keeps its own list. Any country code is now valid on save.

Real lists need the provider key: gkhngyk was asked on #1625 to paste them,
to check the first read.

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

* fix(prompts): keep a column change for the person unless they shared 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]>

* fix(prompts): reload the API's schema after adding the column views table (PROMPT-015, part 1)

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

* fix(prompts): read the Locations view three database reads at a time, 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]>

* fix(prompts): read the locations' figures anew after prompts are paused, resumed, deleted or edited (PROMPT-015, part 2)

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

* fix(prompts): add a cell's location to no prompt when its prompt is no 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]>

* fix(tracking): run a city no list names on no engine, rather than country-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]>

* fix(prompts): name Türkiye as Türkiye, found by Turkey and Turkiye too, 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]>

* docs(prompts): keep the guide's formatting as it was, beside the Türkiye name (PROMPT-015, part 4)

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

* test(tracking): keep the cities and the engines that ask from them the same on the web and the API (PROMPT-015, part 4)

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

* fix(tracking): reload the API's schema after adding the engines' country lists (PROMPT-015, part 5)

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

* fix(tracking): read an engine's countries in any shape the provider sends, and keep the last list when a new one shrinks by more than half (PROMPT-015, part 5)

The daily read took only a bare array of codes. It now also reads
`{ countries: [...] }` and entries with a `code` or `country`, logs an
answer in any other shape and keeps the last list. A list under half the
last one is logged and not applied, so an answer cut short can't stop
tracking in most countries at once.

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

* test(tracking): keep the provider's engines and those that ask from a city the same on the web and the API (PROMPT-015, part 5)

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

* test(prompts): type the matrix test's slow read for reads that return a promise (PROMPT-015, part 2)

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 28, 2026
… the plan's locations are used up (PROMPT-015, part 6) (#1660)

* feat(prompts): let a person show, hide and order the Tracked Prompts 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]>

* feat(prompts): compare each tracked prompt across its locations in a 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]>

* docs(prompts): describe the Columns panel and sharing a view with the brand (PROMPT-015, part 1)

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

* docs(prompts): describe location columns and the Locations view (PROMPT-015, part 2)

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

* feat(prompts): add locations to many prompts at once, priced before saving, 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]>

* feat(tracking): track prompts in cities, asked by the engines that can 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]>

* fix(prompts): find a city typed without its marks, İstanbul as Ist (PROMPT-015, part 4)

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

* fix(prompts): show the biggest gap card's values as whole numbers (PROMPT-015, part 2)

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

* perf(prompts): open the Locations view on data already read, in one round 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]>

* feat(tracking): offer and run only the countries each engine answers from, read daily from the provider (PROMPT-015, part 5)

PROMPT-015e. The tracking provider supports a different set of countries
per engine, and asking an engine in a country it doesn't support fails;
its GET /v1/countries?model= is the only source of truth (its docs publish
no list). So:
- The daily run reads every engine's list before tracking
  (refreshCloroCountries) into cloro_countries (00364). A list that can't be
  read keeps the last one; an empty or malformed answer never empties it.
  No provider key (self-hosted, local): nothing read, nothing restricted.
- The tracking run skips an engine in a country it doesn't support
  (supportedLocations), and logs how many pairs it skipped: no failed task,
  no spent credit.
- The location picker offers the countries the engines answer from, named
  by the runtime's own region names, with "not on <engine>" where one
  doesn't; cities only where Google's engines answer. Before the first read
  it keeps its own list. Any country code is now valid on save.

Real lists need the provider key: gkhngyk was asked on #1625 to paste them,
to check the first read.

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

* feat(prompts): say when a new location's first results come, and when the plan's locations are used up (PROMPT-015, part 6)

A location just added to a prompt showed a bare dash until the next daily
run. Its cells now say when its answers come or why they won't:

- "Within 24h": tracked there, asked by the next daily run;
- "Paused": the prompt is paused;
- "No engine here": none of the prompt's engines answers from that
  country (or city), from the engines' country lists (00364).

A custom range that ended before today keeps the plain dash. Once the
plan's prompt locations are used up, + Track reads "Limit reached" and
still opens the dialog with the plan's way out. The dialog's toast says
the first results come within 24 hours.

useTrackingCountries moves into its own module so the matrix can share
it with the location picker.

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

* fix(prompts): keep a column change for the person unless they shared 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]>

* fix(prompts): reload the API's schema after adding the column views table (PROMPT-015, part 1)

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

* fix(prompts): read the Locations view three database reads at a time, 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]>

* fix(prompts): read the locations' figures anew after prompts are paused, resumed, deleted or edited (PROMPT-015, part 2)

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

* fix(prompts): add a cell's location to no prompt when its prompt is no 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]>

* fix(tracking): run a city no list names on no engine, rather than country-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]>

* fix(prompts): name Türkiye as Türkiye, found by Turkey and Turkiye too, 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]>

* docs(prompts): keep the guide's formatting as it was, beside the Türkiye name (PROMPT-015, part 4)

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

* test(tracking): keep the cities and the engines that ask from them the same on the web and the API (PROMPT-015, part 4)

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

* fix(tracking): reload the API's schema after adding the engines' country lists (PROMPT-015, part 5)

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

* fix(tracking): read an engine's countries in any shape the provider sends, and keep the last list when a new one shrinks by more than half (PROMPT-015, part 5)

The daily read took only a bare array of codes. It now also reads
`{ countries: [...] }` and entries with a `code` or `country`, logs an
answer in any other shape and keeps the last list. A list under half the
last one is logged and not applied, so an answer cut short can't stop
tracking in most countries at once.

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

* test(tracking): keep the provider's engines and those that ask from a city the same on the web and the API (PROMPT-015, part 5)

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

* fix(prompts): read a custom range that ended yesterday as past, on the viewer's clock, not as within 24 hours (PROMPT-015, part 6)

A range ending yesterday still counted as reaching today, since its last
moment was less than a day ago, so its locations said "Within 24h". A
range now reaches today only when it ends at or after the start of today
in the viewer's time zone.

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

* fix(prompts): say "No engine here" in a US state only Google's engines would ask, and not for an engine with no country list (PROMPT-015, part 6)

The run asks Google AI Overview and AI Mode country-wide in a US state
and records their answers as the country's, so a Google-only prompt's
state cell said "Within 24h" for good. It now says no engine answers
there. An engine no country list was read for is asked everywhere by the
run, so the cell no longer says no engine answers for it.

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

* fix(prompts): give the keyboard and screen readers why a location has no answers yet, and name a used-up limit as such (PROMPT-015, part 6)

"Within 24h", "Paused" and "No engine here" kept their reason in a title,
which only a mouse reaches. They now show it in a tooltip on hover and
on keyboard focus, and give it to screen readers as the description.
"Limit reached" was announced as "Track … in …"; its label now says the
plan's locations are used up.

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

* test(prompts): keep the engines' provider models, and those left out of a US state, the same on the web and the API (PROMPT-015, part 6)

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

* test(prompts): type the matrix test's slow read for reads that return a promise (PROMPT-015, part 2)

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

* fix(prompts): show a dash, not Within 24h, where an older prompt had no runs in the range

"Within 24h" showed in every tracked location without answers in the
range, so an older prompt whose runs were missing or failed in it read as
a new one. A location now says it only while its first answers can still
come from the next daily run:

- the prompt was added within the last 48 hours; or
- it has answers in another location in the range, so this one was most
  likely just added.

Otherwise the cell keeps the plain dash ("No answers here in this
period"). "Paused" and "No engine here" are unchanged, whatever the
prompt's age. Applies to the Locations view and the Table view's
location columns; the guide says so.

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk no need to run the countries request anymore: Ansvisor shared Cloro's list (250 countries) and we loaded it into the dev database's cloro_countries for local testing. Production needs nothing from this, since the daily run reads GET /v1/countries itself (#1659).

gkhngyk added a commit that referenced this pull request Oct 29, 2026
…e view, as the Locations view does (#1717)

* feat(prompts): let a person show, hide and order the Tracked Prompts 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]>

* feat(prompts): compare each tracked prompt across its locations in a 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]>

* docs(prompts): describe the Columns panel and sharing a view with the brand (PROMPT-015, part 1)

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

* docs(prompts): describe location columns and the Locations view (PROMPT-015, part 2)

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

* feat(prompts): add locations to many prompts at once, priced before saving, 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]>

* feat(tracking): track prompts in cities, asked by the engines that can 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]>

* fix(prompts): find a city typed without its marks, İstanbul as Ist (PROMPT-015, part 4)

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

* fix(prompts): show the biggest gap card's values as whole numbers (PROMPT-015, part 2)

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

* perf(prompts): open the Locations view on data already read, in one round 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]>

* feat(tracking): offer and run only the countries each engine answers from, read daily from the provider (PROMPT-015, part 5)

PROMPT-015e. The tracking provider supports a different set of countries
per engine, and asking an engine in a country it doesn't support fails;
its GET /v1/countries?model= is the only source of truth (its docs publish
no list). So:
- The daily run reads every engine's list before tracking
  (refreshCloroCountries) into cloro_countries (00364). A list that can't be
  read keeps the last one; an empty or malformed answer never empties it.
  No provider key (self-hosted, local): nothing read, nothing restricted.
- The tracking run skips an engine in a country it doesn't support
  (supportedLocations), and logs how many pairs it skipped: no failed task,
  no spent credit.
- The location picker offers the countries the engines answer from, named
  by the runtime's own region names, with "not on <engine>" where one
  doesn't; cities only where Google's engines answer. Before the first read
  it keeps its own list. Any country code is now valid on save.

Real lists need the provider key: gkhngyk was asked on #1625 to paste them,
to check the first read.

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

* feat(prompts): say when a new location's first results come, and when the plan's locations are used up (PROMPT-015, part 6)

A location just added to a prompt showed a bare dash until the next daily
run. Its cells now say when its answers come or why they won't:

- "Within 24h": tracked there, asked by the next daily run;
- "Paused": the prompt is paused;
- "No engine here": none of the prompt's engines answers from that
  country (or city), from the engines' country lists (00364).

A custom range that ended before today keeps the plain dash. Once the
plan's prompt locations are used up, + Track reads "Limit reached" and
still opens the dialog with the plan's way out. The dialog's toast says
the first results come within 24 hours.

useTrackingCountries moves into its own module so the matrix can share
it with the location picker.

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

* fix(prompts): keep a column change for the person unless they shared 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]>

* fix(prompts): reload the API's schema after adding the column views table (PROMPT-015, part 1)

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

* fix(prompts): read the Locations view three database reads at a time, 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]>

* fix(prompts): read the locations' figures anew after prompts are paused, resumed, deleted or edited (PROMPT-015, part 2)

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

* fix(prompts): add a cell's location to no prompt when its prompt is no 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]>

* fix(tracking): run a city no list names on no engine, rather than country-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]>

* fix(prompts): name Türkiye as Türkiye, found by Turkey and Turkiye too, 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]>

* docs(prompts): keep the guide's formatting as it was, beside the Türkiye name (PROMPT-015, part 4)

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

* test(tracking): keep the cities and the engines that ask from them the same on the web and the API (PROMPT-015, part 4)

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

* fix(tracking): reload the API's schema after adding the engines' country lists (PROMPT-015, part 5)

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

* fix(tracking): read an engine's countries in any shape the provider sends, and keep the last list when a new one shrinks by more than half (PROMPT-015, part 5)

The daily read took only a bare array of codes. It now also reads
`{ countries: [...] }` and entries with a `code` or `country`, logs an
answer in any other shape and keeps the last list. A list under half the
last one is logged and not applied, so an answer cut short can't stop
tracking in most countries at once.

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

* test(tracking): keep the provider's engines and those that ask from a city the same on the web and the API (PROMPT-015, part 5)

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

* fix(prompts): read a custom range that ended yesterday as past, on the viewer's clock, not as within 24 hours (PROMPT-015, part 6)

A range ending yesterday still counted as reaching today, since its last
moment was less than a day ago, so its locations said "Within 24h". A
range now reaches today only when it ends at or after the start of today
in the viewer's time zone.

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

* fix(prompts): say "No engine here" in a US state only Google's engines would ask, and not for an engine with no country list (PROMPT-015, part 6)

The run asks Google AI Overview and AI Mode country-wide in a US state
and records their answers as the country's, so a Google-only prompt's
state cell said "Within 24h" for good. It now says no engine answers
there. An engine no country list was read for is asked everywhere by the
run, so the cell no longer says no engine answers for it.

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

* fix(prompts): give the keyboard and screen readers why a location has no answers yet, and name a used-up limit as such (PROMPT-015, part 6)

"Within 24h", "Paused" and "No engine here" kept their reason in a title,
which only a mouse reaches. They now show it in a tooltip on hover and
on keyboard focus, and give it to screen readers as the description.
"Limit reached" was announced as "Track … in …"; its label now says the
plan's locations are used up.

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

* test(prompts): keep the engines' provider models, and those left out of a US state, the same on the web and the API (PROMPT-015, part 6)

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

* test(prompts): type the matrix test's slow read for reads that return a promise (PROMPT-015, part 2)

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

* feat(prompts): say when a new prompt's first results come in the Table view, as the Locations view does

A prompt with no answers in the range showed a dash in every figure
column until its first run. Its row now says it once, in the first
answer column shown (Visibility, Mentions, Citations, Positions, Runs or
Last run, in the person's column order):

- "Within 24h": the next daily run asks it;
- "Paused": the prompt is paused, only when the Status column is hidden,
  since Status already says so.

The reason shows in a tooltip on hover and keyboard focus, and reaches
screen readers as the label's description, as in the Locations view
(LocationPending, now usable without a location). With a location
picked, a prompt tracked there says it for that location ("No engine
here" included); one not tracked there keeps the dash. A custom range
that ended before today keeps the plain dash.

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

* fix(prompts): show a dash, not Within 24h, where an older prompt had no runs in the range

"Within 24h" showed in every tracked location without answers in the
range, so an older prompt whose runs were missing or failed in it read as
a new one. A location now says it only while its first answers can still
come from the next daily run:

- the prompt was added within the last 48 hours; or
- it has answers in another location in the range, so this one was most
  likely just added.

Otherwise the cell keeps the plain dash ("No answers here in this
period"). "Paused" and "No engine here" are unchanged, whatever the
prompt's age. Applies to the Locations view and the Table view's
location columns; the guide says so.

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

* fix(prompts): say Within 24h in the Table view only for a prompt added in the last two days

A row with no answers in the range said "Within 24h" whatever the
prompt's age, so an older prompt whose runs were missing or failed in the
range read as a new one. The row now says it only while the prompt's
first answers can still come from the next daily run (awaitsFirstAnswers):
it was added within the last 48 hours or, with a location picked, it has
answers in another location column shown. Otherwise its first figure
column keeps the plain dash, as the others do.

"Paused" (Status column hidden) and "No engine here" (a location picked)
are unchanged, whatever the prompt's age. The guide now says which ways
of adding a prompt start its analysis right away (Add prompt, Bulk
import) and which wait for the next daily run (Prompt Suggestions).

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

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
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