Repository navigation
Count downloads: the Download button opens a counted download page - #574
Merged
Alejandro Lopez (soyalejolopez) merged 1 commit intoOct 29, 2026
Conversation
The button now opens r/<slug>/download/, which saves the file and logs a Clarity resource_download event. Loads of that page are read from the Clarity URL export and added to resource-stats.json as downloads per resource, kept separate from views. Download pages are noindex and stay out of the sitemap and feed. Moves the Clarity parsing helpers into stats-state.js so the whole export-to-stats path is covered by tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Alejandro Lopez (soyalejolopez)
merged commit Oct 29, 2026
2e9691e
into
microsoft:master
5 checks passed
Alejandro Lopez (soyalejolopez)
deleted the
soyalejolopez-counted-downloads
branch
October 29, 2026 16:44
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.
Category
What's in this pull request?
Makes downloads countable in
resource-stats.json. Follow-up to #573, which added the Download button but could only log clicks to the Clarity dashboard. Clarity's export API exposes page URLs and not custom events, so the button now opens a small page per resource,r/<slug>/download/, and each load of that page is one download.How it works
r/<slug>/download/instead of the file.resource_downloadevent and tags the resource./r/<slug>/download/loads are now added to each resource's daily bucket intraffic-data/clarity-views.jsonasdownloads, then summed intoresource-stats.jsonasdownloads(with"downloads": "clarity"undersources). They are never added toviews.Download pages are
noindex, point their canonical at the resource page, and stay out of the sitemap and feed. Only the 24 resources that have a Download button get one; archived resources, bundles, declarative agents and Markdown resources are unchanged.What changed
tools/catalog-build/stats-state.js: newdownloadSlugFromClarityUrl;downloadsis a valid persisted metric. The Clarity parsing, window-differencing and totalling helpers moved here frombuild-stats.js(unchanged behavior for views) so the whole export-to-stats path can be tested. Metric keys are written in a fixed order so reruns stay byte-stable.tools/catalog-build/build-stats.js: uses those helpers and writesdownloadsper resource.tools/catalog-build/site-pages.js,index.js,assets/resource-page.js,assets/resource-page.css: the download page template (header and footer are now shared helpers; the other 34 resource pages are byte-for-byte unchanged), the generator, the auto-download and event logic, and button styling.index.html: the landing Download button opens the counted page; the direct-file link and its separate click handler are gone.test-stats-state.jscovers URL mapping (a download page is never a view), rolling and dated exports, window differencing including a negative difference, daily totals, and persisted-state validation.test-site-output.jscovers the button, the download page markup, noindex and canonical, sitemap and feed exclusion, and the landing button.docs/CATALOG-METADATA.md,traffic-data/README.md,CHANGELOG.md: document the page and the new metric.Verified
npm run checkpasses.resource_downloadand a resource page still logs onlyresource_view; the landing button is hidden for a bundle.build-stats.jsrun against a mocked Clarity export (the real API needs a token): the 1, 2 and 3-day windows became daily buckets with views and downloads, andresource-stats.jsongot{"views": 9, "viewsUniques": 6, "downloads": 4}with the new source entry. The data files were restored afterwards.Notes
resource-stats.jsongainssources.downloadsand per-resourcedownloadsat the next scheduled stats run. The landing page does not display downloads yet.Related issues
Follows #573.
Checklist
npm ci --prefix tools/catalog-build && npm run check --prefix tools/catalog-build(passes)versionandupdatedwere bumped (not applicable: no resource content changed)See CONTRIBUTING.md for details.