Skip to content

pirsch-analytics/caddy-pirsch-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caddy Plugin for Pirsch Analytics

A Caddy v2 plugin to track requests in Pirsch Analytics.

Usage

pirsch [<matcher>] {
    client_id <pirsch client ID>
    client_secret <pirsch client secret or access key>
    base_url <alternative-api-url>
}

You can obtain these parameters from the Settings section of your Pirsch dashboard. We recommend using an access key, as it doesn't require a roundtrip to get an oAuth token first. If you use the access key, the client ID must be left empty.

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 Pirsch handler with a file_server, so ordering it just before is often a good choice:

{
	order pirsch before file_server
}

Alternatively, you may use route to order it the way you want. For example:

localhost
root * /srv
route {
	pirsch * {
		[...]
	}
	file_server
}

Example

Track all requests to HTML pages in Pirsch. 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 pirsch before file_server
}

http://localhost:8080 {
    @html path_regexp .*\.html$

    pirsch @html {
        client_id <client ID>
        client_secret <client secret or access key>
    }

    file_server
}

Building Caddy

To compile Caddy with the Pirsch plugin, install and use xcaddy:

xcaddy build --with github.com/pirsch-analytics/caddy-pirsch-plugin@plugin-tag

Replace plugin-tag with the plugin version, e.g. v1.0.2.

License

Apache 2.0

About

A Caddy v2 plugin to track requests using Pirsch Analytics.

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • Go 95.4%
  • Makefile 4.6%