Outbound links Pro
Capture clicks on any anchor that points to a different hostname. Useful for measuring traffic you send to other domains: affiliate links, social share buttons, links out to your GitHub, npm, or documentation on a separate subdomain.
Enable
init
init("proj_xxx", { extensions: { outboundLinks: true } })
// or, in React:
<Analytics projectId="proj_xxx" extensions={{ outboundLinks: true }} />What fires
One outbound_click event per matched click, with three properties:
| Property | Example | Notes |
|---|---|---|
url | https://github.com/clamp-sh/clamp | Full resolved URL, including path and query. |
host | github.com | Hostname only. Use this to group by destination. |
pathname | /clamp-sh/clamp | Path portion of the destination URL. |
What counts as outbound
- Any anchor whose resolved hostname differs from
location.hostname. Subdomains count as different hosts — a click fromclamp.shtoapp.clamp.shfires. - Relative URLs are resolved against the current page with
new URL(href, location.href), so they always match the current hostname and are never outbound. - Only
http:andhttps:protocols are tracked.mailto:,tel:,javascript:, and custom schemes are skipped. - Anchors without an
hrefattribute are skipped. Button elements are never matched — only<a>.
How it works
A single delegated click listener is attached to document in the capture phase, so it runs before any stopPropagation further down the tree. On click, the SDK walks up the DOM from the target using closest("a"). One listener per page regardless of how many links exist — cheap.
Gotchas
- Subdomains are treated as different hosts. If that’s wrong for your setup, don’t enable this extension and instead track cross-property clicks with explicit
track()calls. - Navigation triggered by JavaScript (
window.open,location.href = ...) never fires. This extension only captures real<a>clicks. - Right-click “open in new tab” does fire — it dispatches a click event. Middle-click and Cmd/Ctrl-click also fire.
- Every outbound click costs one event against your monthly quota. Busy pages with many external links can consume quota quickly; estimate before enabling on high-traffic pages.
Related
- File downloads — similar click-based capture for file links.
- Data attributes — opt-in markup-driven tracking for specific outbound links you care about most.