A module for Caddy which sends HTTP request information to Umami as page view events. The data is sent directly from the web server to Umami's /api/send
endpoint without requiring you to include any client-side JavaScript on your website. The visitor's IP is set via the X-Forwarded-For
header or the header specified with client_ip_header, one of which should be set as CLIENT_IP_HEADER
in Umami.
umami [<matcher>] {
event_endpoint <endpoint>
website_uuid <uuid>
# the following are optional:
allowed_extensions <extensions ...>
client_ip_header <name>
cookie_consent [path_only|disable_all] [<name>]
cookie_resolution [<name>]
device_detection
trusted_ip_header <name>
report_all_resources
static_metadata {
<key> <value>
...
<key> <value>
}
}
""
in this list if you want to track URLs which don't end in a file extension, such as /
or /about-us
.htm
.html
.php
X-Forwarded-For
, which contains the visitor's IP address.false
then this plugin will not run. If a name is not set, the default name is umami_consent
.1920x1080
. It is your responsibility to set this cookie with client-side JavaScript (not provided). If this cookie is not set, device type will just be reported as unknown. If a name is not set, the default name is umami_resolution
.Sec-CH-UA-Mobile
/Sec-CH-UA-Platform
, for some rudimentary device detection without cookies. If this and cookie_resolution
are both enabled, a screen resolution set by the cookie will take precedence.X-Forwarded-For
. This may be useful if your Caddy server is behind a reverse proxy.server node1
as the <key> <value>
pair here, when a visitor accesses /about-us
on your website, the path sent to Umami will be /about-us?server=node1
. This allows you to do things like track which Caddy server sent the event data to Umami, and filter events in Umami based on that metadata (because Umami allows filtering by query string, but not by other things like event data).You should specify the order of the umami
directive in your global options, otherwise the umami
block has to be defined inside a route
block.
{
# see: https://caddyserver.com/docs/caddyfile/directives#directive-order
order umami after route
}
example.com {
umami {
event_endpoint "https://umami.example.com/api/send"
website_uuid "4fa2c16a-6c0f-488f-986f-bc26d90c76d1"
allowed_extensions "" .html .htm .php
client_ip_header X-Real-IP
device_detection
}
// ...
}
Copyright © 2024 Jonah Aragon
This source code is made available under the MIT and Apache licenses (i.e. you can pick which one to follow). This is because I generally prefer MIT and chose it first, but later noticed most of the Caddy ecosystem uses Apache 2.0 😄