How do I count clicks on links that leave my site?

Add a named event goal, then send it from a single listener that checks whether a clicked link points to another host. PostDeploy does not track outbound links on its own, and an event carries no destination address, so give each destination you want to compare its own goal. Links opened from a right-click menu are not counted.

Last updated 26 November 2026. By Paul Badarau.

A fictional podcast links every episode to three places: a podcast app, a video site and the RSS feed. The host wants to know which one listeners pick. They add three named event goals, listen_app, listen_video and listen_rss, and tag each link with its goal. A month later the report shows 410, 120 and 35 clicks, and the episode pages that sent them.

To count outbound clicks:

  1. Ask an Owner or Administrator to add a named event goal for each destination you want to tell apart, plus one called outbound_click for every other external link. If you only want a total, outbound_click alone is enough.
  2. Tag the links that have their own goal: <a href="https://feed.example/show.xml" data-goal="listen_rss">RSS</a>.
  3. Add one script for the whole site: function outbound(event) { var link = event.target.closest('a[href]'); var http = link && (link.protocol === 'http:' || link.protocol === 'https:'); var external = http && link.host === location.host ? null : http; if (external) window.postdeploy?.track(link.dataset.goal || 'outbound_click'); } document.addEventListener('click', outbound); document.addEventListener('auxclick', outbound);
  4. Click one tagged link and one untagged link, and check that both goals appear in the report.

The listener catches ordinary clicks, Enter on a focused link and middle clicks. It ignores mailto: and tel: links. When the click leaves the page, the PostDeploy script hands the event to the browser's beacon where it can, which is built to deliver requests while a page unloads.

An event carries the goal name and the page it happened on, not the address of the link. That is why each destination needs its own goal, and why one outbound_click goal can tell you which pages send people away but not where they went. Conversions break down by page, so read that goal by page. A Project holds at most 40 goals, archived ones included, so keep per-destination goals for the links you would act on.

Some clicks never reach the listener. Opening a link from the right-click menu, or by a long press on a phone, fires no click event, so those visits to the destination go uncounted. Links to another host of the same Project, such as your app, also count as outbound with this script. Add a check for that host if you want them left out. Completion counts include repeats, and a visit keeps at most 20 goal events, so a visit stops adding completions once it has 20 goal events of any kind.

The product page for this is Analytics.

Start your 14-day free trial