A Caddy v2 plugin to track requests in HitKeep from the server side. Inspired by caddy-plausible-plugin.
The plugin uses HitKeep's server-side pageview ingest endpoint (POST /api/ingest/server/pageview), which expects a Bearer-token-authenticated, server-to-server request. You will need an API client / personal access token with the site.manage_data scope for the site you want to track.
hitkeep [<matcher>] {
api_key <your-api-token>
domain_name <your-site-domain>
base_url <alternative-api-url>
}
api_key(required): Bearer token used to authenticate against the HitKeep ingest endpoint (can be loaded from envrionment likeapi_key {env.HITKEEP_API_KEY}).domain_name(optional): The domain of a site you have configured in HitKeep in case you want to override the tracked request's actual URL.base_url(optional): Defaults tohttps://cloud.hitkeep.eu. Point it at your self-hosted instance if you run one.
Because this directive does not come standard with Caddy, you need to put the directive in order. The correct place is up to you, but usually putting it near the end works if no other terminal directives match the same requests. It's common to pair a HitKeep handler with a file_server, so ordering it just before is often a good choice:
{
order hitkeep before file_server
order hitkeep before reverse_proxy
}
Alternatively, you may use route to order it the way you want. For example:
localhost
root * /srv
route {
hitkeep * {
[...]
}
file_server
}
Track all requests to HTML pages in HitKeep. You might want to extend the matcher regexp to also include / or, alternatively, match everything but assets (like .css, .js, ...) since usually you wouldn't want to track those.
{
order hitkeep before file_server
}
http://localhost:8080 {
@html path_regexp .*\.html$
hitkeep @html {
api_key {env.HITKEEP_API_KEY}
domain_name muetsch.io
}
file_server
}
xcaddy build --with github.com/muety/caddy-hitkeep-plugin=.Apache 2.0