Plausible
The Plausible extension enables your Go-Mojito project to track pagevisits and custom events without ever injecting the plausible script into your site. By using middleware and/or a custom request context, you can enable privacy-friendly server-side tracking.
Don't know Plausible? You can find more information here.
Important
This extension requires a registered site at plausible.io or a self-hosted instance of Plausible.
What is the benefit of server-side analytics?
You save the users a bit of data, the execution of an analytics script that they might not want and grant them complete anonymity, while also ensuring that your analytics cannot be blocked or detected by any browser extension. A true win-win situation for user and developer.
Enabling Pageview Tracking
Enabling Plausible pageview tracking is as simple as registering a middleware on your router.
package main
import (
plausible "github.com/go-mojito/extension-plausible"
"github.com/go-mojito/mojito"
)
func init() {
// Configure Plausible Tracking
plausible.Configure("go-mojito.infinytum.co")
// Only necessary if you self-host plausible
// plausible.SetInstanceURL("https://my.plausible.instance")
}
func main() {
mojito.WithMiddleware(plausible.Middleware)
}
Tracking Custom Events
To track custom events you can use plausible.Context
in your handler to trigger custom
events.
package main
import (
plausible "github.com/go-mojito/extension-plausible"
"github.com/go-mojito/mojito"
)
func init() {
// Configure Plausible Tracking
plausible.Configure("go-mojito.infinytum.co")
// Only necessary if you self-host plausible
// plausible.SetInstanceURL("https://my.plausible.instance")
}
func main() {
mojito.GET("/", func(ctx plausible.Context) {
ctx.Trigger("Download", nil)
ctx.Trigger("DownloadWithParams", map[string]string{
"file": "cool_thing.jpg",
})
})
}