Setup and data
How to track outbound link clicks without collecting private URLs
An outbound click leaves your host. Count the destination host, not the full URL, so emails, tokens and signed links never reach analytics.
The CrispStats team · · 8 min read
In short
A pageview ends at your domain. The click that leaves, toward a docs site you do not host, a partner, an app store or a calendar, is invisible unless you record the click itself. This guide defines that click, says what to store, and shows a listener that sends the host and nothing else. The glossary entry for an outbound link is the short definition. How to track button clicks is the other event: a control that stays on your site.
What counts as an outbound link click?
A click on a link whose destination host differs from the current page’s host, when the link is http or https. Same host means it is not outbound, even if the path is new.
- Outbound.
https://docs.partner.com/guideclicked fromhttps://example.com/blog. The hosts differ. - Not outbound.
https://example.com/pricingclicked fromhttps://example.com/blog. The next pageview on your own site is the record. - A subdomain is a decision.
docs.example.comclicked fromwww.example.comis outbound under a strict host check, and internal if you treat the whole site as one. Decide once and keep it. If both hosts run the same analytics script, you already see the arrival as a pageview and may not need an outbound event. - Not a link click.
mailto:andtel:are not http links. A mailto link also contains an email address, which does not belong in analytics. Count them as their own events, with no address, or do not count them.
A middle click and a modified click open the destination in a new tab. They are still outbound clicks. A listener that only watches the ordinary click event misses the middle button. Count that click as well, or the people who open links in tabs disappear.
Why track outbound clicks at all?
Because the outcome you care about happens on a site that will not send you a pageview. The click is the last fact you can observe.
Typical uses are a partner or affiliate link, a documentation site on another domain, a community, or a booking page. The click is intent, not the sale, the signup or the meeting. The partner’s report is still the record of what happened after the click. Your event answers a narrower question: which of your pages, and which of your links, send people away.
Without the event, a high exit rate on a resource page looks like a failure. With it, you can see that most of those exits were the link the page was written to offer. That is the difference between a page that leaks and a page that does its job.
What should the event contain?
The destination host is enough to answer which site people left for. Add a path only when you already know the path is public and stable, such as a documentation article. Do not send the full URL if it can contain an email, a token or a signed query.
| What you send | What you can learn | What can leak |
|---|---|---|
| Host only | Which external site was clicked | Nothing from the path or the query |
| Host and a public path | Which article or product page | A token or an email, if one was built into the path |
| Full URL, with query and fragment | The exact link, including campaign tags | Reset tokens, inbox links, signed downloads, and addresses in the query |
Query strings are the common leak. A newsletter tool that appends the subscriber’s email, a password-reset link, or a download signed with a token, all look like ordinary URLs. The fragment is the other one: #access_token= never appears in a server log and still identifies the holder. PII in analytics is the longer list of how those values get into a report.
How do you send the click without the full URL?
Listen for clicks on links, compare hosts, and send an event whose only property is the destination host.
The call is crispstats("outbound click", { host: url.host }). host is the hostname and port, never the path or the query. The same shape works with any tracker that accepts an event name and flat properties: pass the host, and do not pass link.href.
document.addEventListener("click", function (event) { var el = event.target; var link = el && el.closest ? el.closest("a") : null; if (!link) return; var url; try { url = new URL(link.href, location.href); } catch (err) { return; } if (url.protocol !== "http:" && url.protocol !== "https:") return; if (url.host === location.host) return; crispstats("outbound click", { host: url.host });});Put the listener once, on the document, not on each link. Links added later, including links inside a post body, are covered because the click bubbles. Skip the listener entirely if the tool already records outbound clicks and you have checked what it stores. Two listeners send two events.
- Name the link yourself when the host is not specific enough. Two links to the same partner host need a property you control, such as
slot: "footer", set in your HTML. Do not derive that label by reading the query string. - Ignore your own domains on purpose. If the blog and the app are different hosts and both carry the script, a strict check records a click you will also see as a landing pageview. Drop hosts you own, or accept the double record and do not add the two numbers together.
- Do not read the link text into the event if the text is an email address. A link whose visible label is
ada@example.comis personal data even when the property you meant to send was the host.
How is this different from a button click?
A button click is a control on your site: a toggle, a signup, a tab. An outbound click is a departure. They answer different questions and should not share an event name.
Mixing them produces a report where “click” means everything. A pricing toggle and a partner link then look like one feature. Keep outbound click for leaving the host, and use a specific name for each of your own controls, as in how to track button clicks. A link to your own /signup is a button-style event, or just the next pageview. It is not outbound.
What does a resource page’s outbound traffic look like?
Group the clicks by host, then divide by the pageviews of the page that offered the links. The rate is about the page. The split across hosts is about which link earned the click.
A worked example: three external links
This example uses made-up numbers. A tools page gets 4,000 pageviews in a month. The listener records 220 clicks to calendar.example, 140 to github.com, and 40 to status.example. No query strings were stored.
Outbound clicks are 400. The outbound click rate is 400 ÷ 4,000 = 10%. The calendar link is 220 ÷ 400 = 55% of the exits. That is the link to test first, by position or label. It is not a conversion rate: the meetings booked are in the calendar product, not in this event. If the calendar links had been stored in full, and each one carried the visitor’s email as a query parameter, the analytics tool would now hold 220 addresses. The host-only event does not.
How does CrispStats record outbound clicks?
Turn on outbound clicks with data-outbound on the script tag. A click or a middle click on an http or https link to another host sends an event named Outbound link. The destination is a url property with the fragment removed and the query string cut the same way as the page URL, so parameters other than campaign tags are dropped. Mailto and tel links are not included. The core script without that module is about 2.2 KB gzipped.
<script defer src="https://in.crispstats.com/d.js" data-outbound data-site="YOUR_SITE_KEY"></script>That automatic URL is safe for a public article and unsafe for a link that embeds a secret in the path, because the path is kept. When the href can contain an email or a token, do not use the module for those links. Send host yourself with crispstats("outbound click", { host }), and keep the automatic module off, or you will store both. The event is a custom event: it counts toward the plan, and a session that only fires it is not a bounce.
Terms in this guide
Free tools
- UTM builderBuild UTM-tagged links one at a time or in bulk from pasted rows, with presets, checks for capitals and spaces, CSV export and a channel preview.
- Analytics cost calculatorPick a monthly volume and compare list prices of privacy-friendly analytics tools at that exact volume. Dated, and never estimated between tiers.
- A/B test URL generatorBuild one tagged URL per variant of a test. The variants share source, medium and campaign, and each gets its own utm_content.
More guides
All guides- Engagement · 9 minHow to track button clicksGA4 does not track button clicks by default. Three ways to add them: a gtag call, a Tag Manager trigger, or one HTML attribute, with the steps for each.
- Privacy · 13 minPII examples: what counts as personal data in analytics, by regulatorPII examples from NIST, the GDPR and the CCPA side by side: names, emails, IP addresses, cookie ids and more, and where each one leaks into analytics.
- Revenue · 11 minHow to calculate conversion rate, with worked examplesConversion rate is conversions divided by visitors, times 100. Worked examples for funnels, delayed conversions, channel mix and how many visitors you need.