caddilytics

package module
v0.0.0-...-97af1ee Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 13 Imported by: 0

README

Caddilytics

GoDoc

This repository contains a minimal Caddy module for tracking HTTP requests via Google Analytics Measurement Protocol.

Any advice/criticism/PRs are welcome!

Version 2 Compatibility

Caddilytics is compatible with Caddy V2 only. Earlier commits supported Caddy pre V1, so feel free to browse history for info.

Tracking Info

All requests are being tracked as pageviews with the following data:

  • dl (location URL)
  • dr (referer)
  • ua (user agent)
  • ul (language)

Tracking is done asynchronously with a timeout of 1 second.

Usage (configurable per site):

caddilytics UA-1234-5 session-cookie

You will also have to define a global order (or a route) in your Caddyfile:

{
  order caddilytics before header
}

A http only, secure session cookie will be set with an unencrypted random UUID if none is set already.

TODO (unordered ideas)

  • Clean up specs.
  • Allow non secure cookies.
  • Better documentation, especially about building caddy.
  • Log exceptions with exd (exception description) as hit type exception.
  • Track qt (queue time).
  • Track timing.

License

Copyright (c) 2017 Jasper Rädisch. See the LICENSE file for license rights and limitations (MIT).

Documentation

Overview

Package caddilytics implements a minimal Caddy module for tracking HTTP requests via Google Analytics Measurement Protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	TrackingID        string
	SessionCookieName string
	// contains filtered or unexported fields
}

Middleware implements an HTTP handler that ensures a session cookie and sends analytics data to Google.

func (Middleware) CaddyModule

func (Middleware) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*Middleware) Provision

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

Provision implements caddy.Provisioner.

func (Middleware) ServeHTTP

func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP ensures a session cookie before and sends tracking data asynchronously after calling next middleware.

func (*Middleware) UnmarshalCaddyfile

func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

func (*Middleware) Validate

func (m *Middleware) Validate() error

Validate implements caddy.Validator.

Jump to

Keyboard shortcuts

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