Track outbound GitHub clicks explicitly in PostHog#4974
Open
vfanucci wants to merge 1 commit into
Open
Conversation
Add an explicit `outbound_click` event for clicks on github.com links across the site. PostHog is initialized with autocapture disabled, so no click events are currently recorded — including clicks through to the repo, which blocks OSS-conversion attribution. Rather than re-enabling global autocapture, add a single delegated, passive, capture-phase listener on document that fires one well-named event only for github.com outbound links. Survives Astro SPA navigations and covers dynamically injected links with no re-binding. No new dependency (reuses the existing posthog-js singleton); no change to existing PostHog config. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| if (!link) return | ||
|
|
||
| const url = link.href | ||
| if (!url.includes("github.com")) return |
Contributor
☁️ Cloudflare Worker Preview Deployed!🔗 https://ks-track-outbound-github-clicks-docs.kestra-io.workers.dev ## 🔦 Lighthouse Benchmark
Scores (0–100, higher is better)
Core Web Vitals (lower is better)
Legend🟢 improved · 🔻 regressed · (blank) no significant change |
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
Adds an explicit
outbound_clickevent for clicks ongithub.comlinks across the site. We currently have no way to measure how many visitors click through to the GitHub repo, which blocks OSS-conversion attribution (e.g. measuring whether the Reddit always-on campaign or organic traffic drives repo visits).Why this is needed (root cause)
PostHog is initialized in
src/scripts/cookieconsent.tswith autocapture disabled:Because
autocapture: false, PostHog never records any click events — including outbound clicks to the repo. This is not a markup issue: the GitHub links themselves are standard<a href="https://github.com/kestra-io/kestra" target="_blank">(17 files). The capture mechanism is simply off.Rather than re-enable global autocapture (more event volume, and it was likely turned off deliberately), this PR adds a single delegated listener that fires one explicit, well-named event only for GitHub outbound clicks. Surgical, no change to existing PostHog config.
Changes
src/scripts/outbound.js— a delegated, passive, capture-phaseclicklistener ondocumentthat capturesgithub.comoutbound links.src/components/layout.astro— register the script alongsideanalytics.js(same PROD/PREVIEW guard).Design notes (for review)
document, not per-link. Survivesastro:page-loadSPA navigations and covers links injected after load. No re-binding needed.{ passive: true }. We never callpreventDefault— the browser follows the link normally — so the handler is declared passive. The browser doesn't wait on it, protecting INP.{ capture: true }. Ensures the handler runs before navigation on same-tab links (most GitHub links aretarget="_blank", but this covers the rest).posthog.capture()batches viasendBeacon, so the event survives page unload.closest("a[href]")short-circuits ~99% of clicks in one operation before any further work.posthog-jssingleton already imported byanalytics.js/cookieconsent.ts.Core Web Vitals impact
Negligible by design. LCP and CLS: zero (no rendering, no DOM mutation, no layout shift). INP: the only theoretically affected metric, but the handler does only a
closest()+ string test + async non-blockingcapture()— sub-millisecond, well under the 200 ms threshold — and{ passive: true }keeps it off the critical interaction path. Bundle weight: a few hundred bytes gzipped.Known limitation (not solved here)
Because PostHog only initializes after analytics consent (EU = opt-in, see
cookieconsent.ts), this event will not fire for sessions without consent. Anyoutbound_clickcount is therefore a lower bound, consistent with the existing Consent Mode v2 gap. This PR does not attempt to fix consent gating; it should be documented wherever the metric is reported.How to verify after merge
outbound_clickevent appears withurl,source_path,link_text,targetproperties.outbound_clickbroken down byutm_source/source_pathto start attributing repo clicks to channels.🤖 Generated with Claude Code