feat(docs): add telemetry for page views, referrers and clicks - #107
Merged
Merged
Conversation
Two layers, because one script cannot answer both questions. The counts of the readers, of where they came from and of the speed of a page come from the host of the site. Those scripts are served from this domain, so a content blocker does not stop them, and they write nothing to the device of the reader. The clicks come from an analytics client that loads after the page hydrates. It goes through a proxy on this domain for the same reason a blocker matches the host of a request. It keeps the identity of a reader in the tab and writes nothing to the device, so the site needs no consent dialog. Six events are named by hand: the page view, a search with the number of results it found, a copy with what was copied, the first touch of a demo, the link to the repository and the change of theme. A search that finds nothing is the most valuable of them: the query is the name of a component that is missing. Without VITE_POSTHOG_KEY each function does nothing, and the client is not in the bundle. See docs/src/lib/docs/telemetry/README.md.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
What this adds
Telemetry for the docs site, in two layers. One script cannot answer both
questions, so there are two.
The counts.
src/routes/+layout.tsstarts the analytics and the speedreport of the host. They give the views of a page, where a reader came from,
the country, the device and the speed of a page for real readers. These
scripts come from this domain, so a content blocker does not stop them. That
matters here: the readers of these docs are developers, and many of them run
a blocker. A blocker matches the host of a request, and the requests it stops
never arrive, so the loss is silent and it is not measurable.
The clicks.
$lib/docs/telemetryloads an analytics client after the pagehydrates, in an idle moment, so it does not take the main thread from the
demos. It records each click with the element behind it, and it gives the heat
maps.
hooks.server.tsputs its requests on a path of this domain, for thesame reason as above.
Privacy
The client writes nothing to the device of the reader (
persistence: 'memory'),so the site needs no consent dialog. The cost is that a reader who comes back
tomorrow is a new reader. The first layer carries the counts that need an
identity, so the cost is small. Session recording is off.
The events
$pageviewroutesearchquery,resultsresults: 0is a gap.copysource,detaildemo_interactgithub_clicktheme_changetoEach click also arrives by itself, because the client records them without
instructions. The six above are named by hand, because a name makes a chart.
searchwithresults: 0is the most valuable: the query is the name of acomponent that is missing, or of a page that does not use the word the reader
knows.
To turn it on
Two public variables, read at build time:
VITE_POSTHOG_KEYandVITE_POSTHOG_REGION(euorus, defaulteu). The region must be theregion of the project, or the vendor answers with an error that the browser
does not show. See
docs/src/lib/docs/telemetry/README.md.Without the key each function does nothing, the client is not in the bundle,
and no event leaves a test or a development page.
Also in this diff
pnpm-workspace.yamlhadcore-js: set this to true or false, a placeholder.A new dependency brought
core-jsin, and the placeholder madepnpm install --frozen-lockfileexit 1 withERR_PNPM_IGNORED_BUILDS, whichwould have stopped every job of the CI.
core-jsonly prints a funding noticeat install time, so the answer is
false.Verification
pnpm run lint,pnpm run typecheck(1093 + 4678 files, 0 errors) andpnpm run build:docsare green.cover the proxy: the path it answers, the two hosts, the headers of one hop
that a copied request must not carry, the address of the reader, and a post
with its body.
entry. A build with no key leaves it out of the output.