Repository navigation
fix(search-console): count clicks from anonymized searches - #388
Merged
PascaleBeier merged 2 commits intoOct 5, 2026
Merged
Conversation
Search Console reports undercounted clicks, and on a small site showed zero, because Google leaves anonymized searches out of any Search Analytics response grouped by query and every import was grouped by query. The sync now also imports totals that keep those clicks, the reports read them, and a manual sync repairs days imported before this change. No search text is collected. Checked against the live API: date, date+page, date+country, date+device and date+country+device keep every click; any set with query, or page combined with country or device, loses the anonymized ones. - Worker: each day makes three concurrent requests (query rows, page totals by date+page, audience totals by date+country+device) and replaces the day only after all succeed. - Store: each report reads one row shape. Overview and series use audience totals (page totals under a page filter), the page report page totals, country and device reports audience totals, the query report and page+country/device filters query rows. Days without totals fall back to query rows. - Catch-up: the first sync and a manual sync import the recent seven days plus every older day in the 90-day range still lacking audience totals, newest first, so a sync cut short resumes where it stopped. - Migration adds google_search_console_sync_state.totals_backfilled_property_uri. A completed catch-up records the property; later manual syncs skip it, and remapping to another property catches up again. The upsert only sets it. - recordSyncFailure writes with an uncancelled context (10s limit), so a sync that hit its deadline or lost its caller still records the failure and clears the manual flag. Limits: a page filter combined with a country or device filter still undercounts; existing installs only catch up on a manual sync.
Collaborator
|
Thanks @joshpurvis , merged! I only tested everything and added some checkpoints, this is a great piece of work towards #261 <3 |
Contributor
Author
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Search Console reports in HitKeep undercount clicks, and on a small site they can show zero. Google leaves anonymized searches out of any Search Analytics response grouped by query, and every HitKeep import was grouped by query.
The sync now imports totals that keep those clicks, and the reports read them. A manual "Sync now" also repairs days imported before this change.
No search text is collected. The new rows are the per-page, per-country and per-device totals Search Console already shows the site owner, and they match its chart. Google still hides the anonymized searches themselves.
What I found
I queried the live API for one property, one day at a time, with each dimension set:
date,date,page,date,country,date,device,date,country,devicequery, andpagecombined withcountryordeviceA single request that drops
querybut keepspage,countryanddevicereturns the same zeros, so page totals and audience totals need separate requests.What changed
worker/search_console.go: each day makes three requests concurrently, and the day is replaced only after all three succeed:date,query,page,country,device, as before)date,page)date,country,device)database/store_search_console.go: each report reads one shape of row, so nothing is counted twice:2026_10_04_000000_add_search_console_totals_backfilled_property.sqladdstotals_backfilled_property_uritogoogle_search_console_sync_state. When that import completes, the worker records the property, and later manual syncs go back to the seven-day window. It names the property, so a site remapped to another property gets the same import again. The upsert only ever sets it, so the handler and failure paths that rebuild the row can't clear it.recordSyncFailurenow writes with an uncancelled context, with a 10s limit. Before, a sync that hitRunDue's deadline or lost its HTTP caller couldn't record its failure, so the site stayed pending with the manual flag set.Limits
RunDue's one-minute budget, so I've left that up to you.Testing
go test -race ./database ./worker ./server/userpasses.completeQA passed on the final source snapshot (run20261005T184731-bae2b14f):go-format,go-fix,go-lint,go-vet,go-staticcheck,go-race-database,go-race-server,go-race-rest,govulncheck.Contributor Checklist
No docs, OpenAPI or Agent Skills changes. Reports keep the same fields and now show the numbers Search Console shows. MCP, Ask AI and Opportunities read Search Console through the same store functions, so their numbers now include anonymized clicks. The tools stay read-only and aggregate-only, and no search text is added.
Maintainer follow-up
Completed totals imports now checkpoint empty days as well as days with rows. Checkpoints are scoped to site/property/data state and committed with fact replacement, so interrupted initial backfills can progress past empty dates without fabricated analytics rows. Shared and tenant migrations, analytics reset, and tenant-split fixtures include the checkpoint table.
TDD reproduced the empty-day retry failure before the fix. Regression coverage verifies restart/resume, scoped and idempotent replacement, rollback, reset, and tenant transfer. Gortex coverage and guards completed; its contract audit timed out.
The dedicated Search Console workspace and versioned datasets remain staged follow-ups in #261.