Repository navigation
feat: tag maintainer visits, track code copies and add social cards - #83
Merged
Merged
Conversation
- ?internal=1 stores a flag in localStorage and every Google Analytics event then carries traffic_type=internal, so the Internal Traffic data filter can drop maintainer visits. ?internal=0 removes it. The project docs on the same origin read the same flag. - Copying a code block sends a copy_code event with the section it is in (snippet) and the file name above it (code_title). - Open Graph and Twitter tags on every page, with a 1200x630 card. - The 404 page is titled "Page not found" instead of "cpp-linter". - robots.txt lists the sitemaps of this site and the project docs. - Redirect pages for old URLs that Google Analytics recorded as 404s. - The home page title names what the site is: a C/C++ linter with clang-format and clang-tidy.
✅ Deploy Preview for cpp-linter-github-io ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This was referenced Oct 18, 2026
Contributor
|
I made |
shenxianpeng
added a commit
to cpp-linter/cpp-linter-rs
that referenced
this pull request
Oct 18, 2026
These docs are served from the cpp-linter.github.io origin, but unlike the organization site they have no Google Analytics. So there is no record of what readers look at once they leave the organization's home page. This PR adds the same property the organization site uses (`G-JKH4SXC7HC`). It also adds the maintainer flag from cpp-linter/cpp-linter.github.io#83, so the maintainers' own reading can be filtered out. This PR only changes the site. The Google Analytics side (the Internal Traffic filter, key events) is handled separately. ## Before / After (改动前 / 改动后) | | Before (live site, `origin/main`) | After (this branch) | |---|---|---| | Google Analytics | No gtag on any page | `G-JKH4SXC7HC` on every page | | Maintainer visits | — | `traffic_type=internal` while the `cpp-linter-internal` flag is set (`?internal=1` / `?internal=0` on any page of the origin) | | 404 page `<title>` | `Cpp-Linter` (same as the home page) | `Page not found - Cpp-Linter` | The overrides live in `docs/overrides/`, next to `docs/docs/`, so they are not published as pages. ### Evidence: built `<head>` of `index.html` ```html <script> try { var param = new URLSearchParams(location.search).get("internal"); if (param === "1") localStorage.setItem("cpp-linter-internal", "1"); if (param === "0") localStorage.removeItem("cpp-linter-internal"); if (localStorage.getItem("cpp-linter-internal") === "1") { window.dataLayer = window.dataLayer || []; (function () { dataLayer.push(arguments); })("set", { traffic_type: "internal" }); } } catch (e) { // localStorage is unavailable when storage is blocked; the visit is then not tagged. } </script> <script id="__analytics">function __md_analytics(){ /* … the theme's snippet, unchanged … */ var t=document.createElement("script");t.async=!0,t.src="https://www.googletagmanager.com/gtag/js?id=G-JKH4SXC7HC",document.getElementById("__analytics").insertAdjacentElement("afterEnd",t)}</script> ``` I did not run the full docs build locally, because it compiles the Rust CLI generator. The theme changes were built with the same mkdocs 1.6.1 / mkdocs-material 9.7.7 pins from `docs/pyproject.toml`, with a temporary config that inherits `docs/mkdocs.yml` and leaves out the gen-files plugins and the other nav pages. The `Build docs` job in this PR runs the full build. ## Notes - The flag snippet runs in the theme's `analytics` block, before the theme's own snippet. That way `gtag('set', {traffic_type: 'internal'})` is queued ahead of the first `page_view`. The same snippet was tested end to end with the real gtag.js and a fake measurement ID in cpp-linter/cpp-linter.github.io#83: `tt=internal` is sent after `?internal=1` and stops after `?internal=0`. - None of these changes alters a page's layout, so there are no screenshots. - `cspell.config.yml` gains `htmltitle` (a Jinja block name in `docs/overrides/404.html`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added a custom “404 - Not found” page to the documentation site. * Configured Google Analytics for the documentation site, including support for distinguishing internally tagged visits. * Updated the documentation theme configuration to load custom overrides. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.
Follow-up to a review of this site's Google Analytics and Search Console data. Over the last 90 days roughly 55% of users came from data-center cities with 0 s engagement. Maintainer visits were about 21% of engaged sessions and half of the
click_githubkey events. Nothing recorded that a reader copied a workflow or hook. Links shared in chats had no preview card, and crawlers asking for/robots.txtlanded on the 404 page.This PR only changes the site. The Google Analytics side (turning the Internal Traffic filter on, key events, custom dimensions) and Search Console are handled separately.
Before / After (改动前 / 改动后)
None of these changes alters a page's layout. The only new visual is the social card, shown below.
Behaviour
origin/main)?internal=1stores a flag inlocalStorage; from then on every event carriestraffic_type=internal(sent astt=internal).?internal=0removes it. The project docs under/cpp-linter-action/etc. read the same flag.copy_codeevent withsnippet(section id, orcl-workflowfor the home page block) andcode_title(the file name above the block)<title>cpp-linter(same as a real page)Page not found - cpp-linter/robots.txtAllow: /plus the sitemaps of this site and the four project docs<title>C/C++ Linting - cpp-linterC/C++ Linter with clang-format and clang-tidy - cpp-linterOld URLs that Google Analytics recorded as 404s
hooks/redirects.pywrites a small redirect page for each one after the build. Each page has a meta refresh,location.replace, a canonical link andnoindex./docs//getting-started//merch//sponsor/#t-shirt-perk/inputs-outputs/,/examples/,/permissions/,/pr-review-caveats//cpp-linter-action//cli_args/cpp-linter/cli_args.html/cpp_linter_rs/,/cpp_linter_rs/cli.html/cpp-linter-rs/,/cpp-linter-rs/cli/Evidence: events sent by the real gtag.js
Built this branch with the measurement ID swapped for a fake one (
G-TESTTEST00), so nothing reached the real property. I served it locally and recorded everyg/collectrequest in a browser while going through the pages in this order:tt(traffic_type)ep.snippetep.code_title/getting-started/(no flag)on-every-pull-request.github/workflows/cpp-linter.yml/getting-started/?internal=1internalinternalbefore-every-commit.pre-commit-config.yaml/(no parameter, flag still stored)internalinternalcl-workflow.github/workflows/cpp-linter.yml/blog/?internal=0/blog/Evidence: built
<head>of the home pageBefore (live):
After (
mkdocs build --strict):Social card
Before: no card. After:
Notes
analyticsblock, before Material's own snippet. That waygtag('set', {traffic_type: 'internal'})is queued ahead of the firstpage_view, which rows 3 and 5 above confirm.snippetandcode_title, they need to be registered as event-scoped custom dimensions in Google Analytics. That happens outside this PR.robots.txtlists/cpp-linter/sitemap.xml, which is added by docs: add Google Analytics and a sitemap cpp-linter#237. Until that one is deployed, that URL returns 404 to crawlers, which is harmless.After merging
Open
https://cpp-linter.github.io/?internal=1once on each device and browser you use. To check it is working, wait about a day, open any GA4 report, add the comparison "Test data filter name = Internal Traffic" (it exists while the filter is in Testing), and confirm your own visits show up there. Only then should the filter be switched to Active.