Skip to content

muety/caddy-hitkeep-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go

caddy-hitkeep-plugin

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.

Usage

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 like api_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 to https://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
}

Example

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
}

Development

Build

xcaddy build --with github.com/muety/caddy-hitkeep-plugin=.

License

Apache 2.0

About

A Caddy v2 plugin to track requests in HitKeep analytics from the server side.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages