device-detector-go

module
v0.0.0-...-f3202c1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: LGPL-3.0

README

device-detector-go

Pure-Go User-Agent and Client Hints parser. The initial rule set detects common browsers, operating systems, Android/iOS devices and major crawlers.

d := detector.New()
result := d.Parse(r.UserAgent(), detector.ClientHintsFromHeader(r.Header))

For net/http, wrap your handler with d.Middleware(handler) and read the parsed result using detector.FromContext(r.Context()).

Matomo-compatible rule corpus

The checked-in rules/matomo directory is a snapshot of the upstream rule corpus; its exact source revision is recorded in rules/matomo/UPSTREAM. It is embedded in the published Go module, so applications load it once at startup without shipping a runtime rule directory:

d := detector.New()
report, err := d.LoadEmbeddedMatomoRules()
if err != nil { panic(err) }
// report.PCREFallback lists patterns routed to the compatibility engine.

LoadMatomoRules(path) remains available when an application needs to load a newer external rule snapshot without rebuilding its binary.

This parser preserves the upstream matching order for bots, browsers, operating systems and device vendors/models. Standard rules use Go's fast RE2 engine; rules with PCRE lookarounds use a timeout-protected compatibility engine.

Inspect the exact skipped rules with:

go run ./cmd/rule-report > docs/pcre-fallback-rules.md

License

Licensed under LGPL-3.0-or-later. This includes the bundled Matomo rule corpus; see NOTICE and rules/matomo/UPSTREAM for its source revision.

Directories

Path Synopsis
cmd
rule-report command
rule-report prints Matomo expressions using the PCRE compatibility engine.
rule-report prints Matomo expressions using the PCRE compatibility engine.
Package detector parses User-Agent strings and browser Client Hints.
Package detector parses User-Agent strings and browser Client Hints.
Package rules exposes the Matomo rule corpus embedded in this module.
Package rules exposes the Matomo rule corpus embedded in this module.

Jump to

Keyboard shortcuts

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