your http.HandlerFunc · open source (MIT) · ask in plain English

Add analytics to Go (net/http) Go (net/http).

smolanalytics tracks a Go net/http service two ways: server-side events posted with the standard library from your handlers, and a browser snippet for any HTML you serve that autocaptures pageviews and clicks. You ask your numbers in plain English and get deterministic reports, with a CI test proving they can't be hallucinated.

your http.HandlerFunc
package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

func track(name, distinctID string, props map[string]any) {
    body, _ := json.Marshal(map[string]any{
        "name":        name,
        "distinct_id": distinctID,
        "properties":  props,
    })
    req, _ := http.NewRequest("POST", "https://YOUR-INSTANCE/v1/events", bytes.NewReader(body))
    req.Header.Set("Authorization", "Bearer WRITE_KEY")
    req.Header.Set("Content-Type", "application/json")
    http.DefaultClient.Do(req)
}

func signupHandler(w http.ResponseWriter, r *http.Request) {
    // ... create the user ...
    go track("signup", userID, map[string]any{"plan": "pro"}) // off the request path
    w.WriteHeader(http.StatusOK)
}

// Web autocapture (if you serve HTML): two tags in your template <head>
// <script src="https://YOUR-INSTANCE/sdk.js"></script>
// <script>smolanalytics.init("WRITE_KEY", { host: "https://YOUR-INSTANCE" })</script>

run track() in a goroutine (shown) so the POST never blocks the handler. batch into a slice under real load.

how do I add analytics to go (net/http)?

smolanalytics tracks a Go net/http service two ways: server-side events posted with the standard library from your handlers, and a browser snippet for any HTML you serve that autocaptures pageviews and clicks. You ask your numbers in plain English and get deterministic reports, with a CI test proving they can't be hallucinated.

This one is Go all the way down: smolanalytics itself is a single Go binary, and your net/http server talks to it with nothing but the standard library. Marshal a name, a distinct_id and a properties map, POST it to /v1/events with a Bearer header, and run it in a goroutine so the handler returns clean. If you render html/template pages, the two script tags add browser autocapture on the same write key.

Self-host the binary next to your service for free (MIT) or run it hosted from $29/mo, cookieless with no consent banner. Every answer is a deterministic report with a CI test that proves it can't be invented. Ask in plain English from the dashboard bar or from your editor over MCP, no SQL.

Honest pricing: 14-day full trial, no credit card. Then Solo $29/mo, never metered on seats or sites. Overage is $5/million with an emailed receipt, the dashboard never locks, and self-hosting the single Go binary is free forever (MIT).

Add analytics to Go (net/http) tonight.

One snippet, or one endpoint. Tomorrow morning the verdict tells you which part of the funnel to fix.

questions

How do I add analytics to Go (net/http)?
smolanalytics tracks a Go net/http service two ways: server-side events posted with the standard library from your handlers, and a browser snippet for any HTML you serve that autocaptures pageviews and clicks. You ask your numbers in plain English and get deterministic reports, with a CI test proving they can't be hallucinated.
Do I need a cookie banner?
Not in cookieless mode. smolanalytics can run without storing anything on the device, so there is no consent banner to add. You still get visitors, referrers, funnels, retention, and paths, and AI-assistant referrals (chatgpt.com, claude.ai, perplexity.ai) show up as their own channel.
Is it enough for a real product, or just page counts?
It does funnels, retention, paths, cohorts, and a daily verdict on what to fix, from the same events, and you ask it in plain English. It deliberately skips session replay, feature flags, and experiments. If you want a straight answer on what to fix, that you own and can self-host free, it fits.

keep reading