Short links often point to websites you don’t control. You can track what happens at the short-link domain, but adding analytics to every destination isn’t always an option.
I built KH Matomo Tracker to connect YOURLS with Matomo. The plugin records short-link redirects as Matomo events, directly from the YOURLS server. There’s no JavaScript snippet to add to destination websites.
The version covered here is 1.1.0. You can find the code and setup documentation on GitHub.
I’m excited to share my first officially published plugin! It’s also now listed in Awesome YOURLS 🎉
What it does

KH Matomo sends an event when YOURLS redirects an existing short link. Optionally, it also records requests for keywords that YOURLS cannot resolve, which can help surface mistyped links or old links that still receive traffic.
The settings page includes a connection test, IP anonymization, and sampled delivery diagnostics. The interface supports English and Spanish, including Spain and Mexico locales, and diagnostic dates follow YOURLS’ timezone configuration.
This measures activity at the short link. It doesn’t tell you whether the destination finished loading or whether someone completed an action there.
How it works
The plugin listens to two YOURLS hooks: redirect_shorturl and redirect_keyword_not_found. For eligible requests, it builds an event and sends an HTTPS POST to Matomo’s /matomo.php tracking endpoint using PHP cURL.
Both event types use the same category:
| Request | Category | Action | Event name |
|---|---|---|---|
| Existing short link | YOURLS | redirect | Short-link keyword |
| Missing keyword, when enabled | YOURLS | keyword_not_found | Missing keyword |
For example, visiting https://go.example.com/launch produces an event equivalent to:
{
"category": "YOURLS",
"action": "redirect",
"name": "launch",
"url": "https://go.example.com/launch+"
}
This is a readable summary; the actual request uses Matomo’s Tracking API parameters.
The + in the action URL is intentional: opening that URL from Matomo takes you to YOURLS’ statistics page, avoiding another tracked redirect.
Redirect events also send the original destination URL as an action custom variable named YOURLS destination. Matomo needs its CustomVariables plugin to process that field; CustomDimensions alone doesn’t process it. Values may be truncated to 200 characters. The events themselves don’t depend on CustomVariables.
Getting started
You’ll need YOURLS 1.10.x, PHP 8.1 or newer with cURL, and a Matomo Cloud or Matomo 5/6 self-hosted installation accessible over HTTPS. The development reference is YOURLS 1.10.6.
- Copy the plugin into
user/plugins/kh-matomo/, withplugin.phpat the directory root. - Activate KH Matomo Tracker on the YOURLS Plugins page.
- Open Matomo Tracker and enter your connection settings.
For a typical installation:
| Setting | Example or initial choice |
|---|---|
| Matomo base URL | https://analytics.example.com |
| Site ID | Your Matomo site’s numeric ID |
| Authentication token | A token with write access to that site |
| Enable tracking | On |
| Track links not found | Off, unless you want missing-keyword events |
| Anonymize IP | On, the default |
Use the Matomo base URL, without /index.php or /matomo.php. A dedicated Matomo user with write access only to the selected site is sufficient; administrator access isn’t required.
Test connection checks the current form values and token permissions without saving them or sending an event. Click Save settings to apply your configuration. On later edits, leaving the token field blank keeps the saved token.
To verify tracking, visit a valid short link, then open Visitors → Visits Log / Live in Matomo for the configured site and current date. Look for YOURLS / redirect with your keyword. Standard reports may take longer to update through Matomo archiving.
Tracking missing keywords
Missing-keyword tracking is optional and requires both tracking switches to be enabled. It accepts GET requests with a single valid keyword segment, up to 100 bytes, and an optional trailing slash. Query strings are removed from the keyword, so /launch?source=email is recorded as launch.
To limit traffic from scanners, the plugin reserves at most 30 missing-keyword delivery attempts per fixed 60-second window, shared across the installation. Failed deliveries consume quota too. Valid redirect events aren’t subject to this limit.
These events indicate that YOURLS couldn’t resolve a keyword at that point. They don’t necessarily mean the final response was an HTTP 404: another plugin may provide a fallback redirect.
Delivery and data considerations
Tracking runs synchronously before the redirect, with a 500 ms connection timeout and a one-second total timeout. A slow Matomo endpoint can delay the response. Tracking failures don’t cancel the redirect, but there are no retries or persistent delivery queues.
The diagnostics panel provides sampled successes and failures, including HTTP status, cURL error number, duration, and timestamp. It keeps up to ten samples of each outcome. These samples help troubleshoot delivery; they aren’t a complete request log, and an HTTP success doesn’t prove an event appeared in Matomo reports.
IP anonymization is enabled by default, masking IPv4 addresses to /24 and IPv6 addresses to /64 before sending them. Events can also include a valid HTTP(S) referrer and the visitor’s User-Agent. No shared browser cookie is used, so visitor identification may be less precise than browser-based tracking.
Destination and referrer URLs can still contain sensitive paths or query parameters. IP masking doesn’t remove those values. The authentication token is sent in the HTTPS POST body and stored unencrypted in the YOURLS database, so database access and backups need appropriate protection.
Local delivery diagnostics don’t store tokens, keywords, destination URLs, referrers, User-Agents, or client IPs.
Possible next steps
Some areas I’d like to explore next, rather than treat as a committed roadmap:
- CustomDimensions support, as an alternative way to attach destination metadata.
- Configurable destination and referrer filtering, to remove sensitive query parameters or omit those fields.
- Queued delivery with bounded retries, to move network requests out of the redirect path.
- More diagnostic context, such as distinguishing redirect events from missing-keyword events in delivery samples.
For installation details, screenshots, and the full configuration guide, visit the KH Matomo repository and its configuration documentation.