# Go analytics

> Live analytics for Go: middleware for net/http, chi, Gin and Echo sends crawler visits, 404s, panics, response times and your own events, with the standard library only.

Source: https://status.mettr.app/integrations/go

## One middleware

```bash
go get github.com/mettrhq/mettr-go
```

```go
client := mettr.New(mettr.Options{})
defer client.Close()

http.ListenAndServe(":8080", client.Middleware(mux))
```

Gin and Echo have their own (`mettrgin`, `mettrecho`); chi and gorilla/mux take the `net/http` one. It reads `METTR_SECRET_KEY` and `METTR_PUBLIC_KEY`. Go 1.23 or later, the standard library only.

## What it sends on its own

- **Crawler visits**, with their page and status: search engines and AI crawlers seldom run the [browser script](/docs/browser-script), so only your server sees them.
- **404s** of people, as errors.
- **Panics**, by their type only, never the message; then the panic goes on.
- **Response times** of one request in twenty, by the route's pattern.
- **The browser script**, served from `/_live` on your own domain with `client.ScriptTag()`: page views and who is online, past most ad blockers.

## Your own events

```go
mettr.SetUser(r.Context(), user.ID)
client.Event(r.Context(), "signup", mettr.Props{"plan": "pro"})
```

Events wait a second to go together, off the request's path. Sending never panics into your app.

## Revenue, history and deploys

Billing of your own? `client.Subscription` sends each subscription as it changes, and mettr works out [MRR, churn and revenue by source](/features/revenue). `client.Import` brings your history, and `client.Annotation` marks a [deploy](/docs/deploys) under the traffic chart.

## Open source

`mettr-go` is MIT licensed, on [GitHub](https://github.com/mettrhq/mettr-go) and [pkg.go.dev](https://pkg.go.dev/github.com/mettrhq/mettr-go). [The full guide](/docs/go).
