How to Track Outbound Link Clicks with plausible-hugo
plausible-hugo enables outbound link click tracking by appending the .outbound-links suffix to the Plausible JavaScript filename when you set params.plausible.outbound_link to true.
The plausible-hugo module simplifies adding Plausible Analytics to Hugo sites, including automatic tracking of external link clicks without requiring manual markup on individual anchor tags. By configuring a single site parameter, the module injects the appropriate Plausible script variant that records whenever visitors click links pointing to different hosts. This integration leverages the official Plausible outbound-links script plugin through dynamic script URL generation in the module's partial templates.
How Outbound Link Tracking Works
When outbound link tracking is activated, plausible-hugo modifies the Plausible script URL to load the outbound-links variant. In layouts/partials/plausible_head.html, lines 28-31 construct the filename by checking the outbound_link parameter and appending .outbound-links to the base script name when enabled.
This generates a <script> tag that loads script.outbound-links.js from your configured Plausible domain. Plausible then automatically records click events whenever a visitor follows a link that points to a different host than your site, treating these as custom events in your analytics dashboard.
Enabling Outbound Link Tracking
Basic Configuration
Add the outbound_link parameter to your site configuration file:
[params.plausible]
enable = true
domain = "example.com"
outbound_link = true # Activates outbound link click tracking
Set enable to true to activate the module, specify your Plausible domain, and set outbound_link to true to trigger the script suffix addition.
Adding the Head Partial
Include the plausible_head.html partial in your site's <head> section, typically in layouts/_default/baseof.html or your main layout template:
<head>
{{ partial "plausible_head.html" . }}
<!-- other head elements -->
</head>
The partial reads your configuration and outputs the correct script tag with the .outbound-links suffix when the flag is enabled.
Netlify Proxy Configuration
If you deploy on Netlify and use the proxy feature to avoid ad-blockers, enable the proxy_netlify flag alongside outbound_link:
[params.plausible]
proxy_netlify = true
outbound_link = true
In this mode, layouts/partials/plausible_redirects_netlify.html (lines 2-6) handles the outbound-links script selection through Netlify redirect rules rather than modifying the script tag directly. The partial generates redirect rules that serve the appropriate outbound-links script based on the same configuration flag, while plausible_head.html omits the suffix from the src attribute since Netlify rewrites the request at the edge.
What Gets Tracked
Once enabled, the integration works automatically for all external links across your site. You do not need to add classes, data attributes, or JavaScript handlers to individual <a> tags. Plausible records outbound clicks as custom events, allowing you to analyze which external resources your visitors find most valuable without additional frontend code.
Summary
plausible-hugoappends.outbound-linksto the Plausible script filename whenparams.plausible.outbound_linkistrue- Configure the feature in
config.tomlby settingoutbound_link = truewithin the[params.plausible]block - Include the partial
plausible_head.htmlin your layout's<head>section to load the tracking script - Netlify deployments use
proxy_netlify = trueto handle outbound-links via redirect rules inplausible_redirects_netlify.html - No markup required on individual links—tracking applies site-wide to all external URLs automatically
Frequently Asked Questions
Do I need to modify my HTML links to track outbound clicks?
No. Once you enable outbound_link = true in your configuration and include the plausible_head.html partial, the Plausible script automatically detects and records clicks on any anchor tag pointing to a different domain. The tracking happens at the script level, so your HTML remains unchanged.
What file controls the outbound-links script URL generation?
The layouts/partials/plausible_head.html file controls standard script URL generation, specifically lines 28-31 where it conditionally appends .outbound-links to the script name. For Netlify proxy setups, layouts/partials/plausible_redirects_netlify.html (lines 2-6) manages the redirect rules that determine which script variant gets served.
Can I use outbound link tracking with Netlify's proxy feature?
Yes. Set both proxy_netlify = true and outbound_link = true in your configuration. The module then delegates script selection to Netlify redirect rules defined in plausible_redirects_netlify.html, ensuring the outbound-links script loads correctly while maintaining the proxy benefits for ad-blocker circumvention.
What value should I use for the domain parameter when tracking outbound links?
Use the domain name exactly as it appears in your Plausible dashboard (e.g., "example.com" without protocol or trailing slashes). This domain identifies your site in Plausible's system and determines where the outbound-links script loads from, regardless of which outbound links you want to track on your pages.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →