caddy_plausible_plugin

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

Go Coding Time

caddy-plausible-plugin

A Caddy v2 plugin to track requests in Plausible Analytics from the server side. Inspired by caddy-pirsch-plugin.

Usage

plausible [<matcher>] {
    domain_name <your-project-domain>
    base_url <alternative-api-url>
}

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 plausible before file_server
    order plausible before reverse_proxy
}

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

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

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

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

    plausible @html {
    }

    file_server
}

Development

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

License

Apache 2.0

Documentation

Index

Constants

View Source
const DefaultBaseUrl = "https://plausible.io"

Variables

This section is empty.

Functions

This section is empty.

Types

type EventPayload

type EventPayload struct {
	Name     string `json:"name"`
	Url      string `json:"url"`
	Domain   string `json:"domain"`
	Referrer string `json:"referrer"`
}

type PlausiblePlugin

type PlausiblePlugin struct {
	BaseURL    string `json:"base_url,omitempty"`
	DomainName string `json:"domain_name,omitempty"`
	// contains filtered or unexported fields
}

func (PlausiblePlugin) CaddyModule

func (m PlausiblePlugin) CaddyModule() caddy.ModuleInfo

func (*PlausiblePlugin) Provision

func (m *PlausiblePlugin) Provision(ctx caddy.Context) error

func (*PlausiblePlugin) ServeHTTP

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL