Skip to content

foomo/sesamy-go

Go Report Card GoDoc GitHub Stars

sesamy-go

Sesamy Go SDK

Go SDK for server-side tag management — receive, enrich, and forward Google Analytics 4 traffic on your own infrastructure.

sesamy-go lets you run a first-party tagging endpoint in Go. It accepts inbound GA4 traffic in both protocols GA4 uses — GTag (the form-encoded protocol used by gtag.js) and Measurement Protocol v2 (JSON) — runs your enrichment and validation middleware, then forwards events to a downstream tagging server (sGTM, GA4, BigQuery, vendor endpoints).

It pairs with foomo/sesamy-cli, which generates the GTM container that points gtag.js at your sesamy-go endpoint and emits matching Go event types.

Features

  • GTag + MPv2 — decode, encode, and round-trip between both wire formats.
  • Composable middleware — client ID, session ID, user ID, IP override, page location, engagement time, user-agent, debug mode, timeouts, logging, OpenTelemetry trace correlation.
  • Typed events — generic Event[P] with 44 predefined GA4 event names and your own param structs.
  • Direct client — emit events server-to-GA without going through a browser (client.MPv2, client.GTag).
  • Providers — Cookiebot consent, Emarsys marketing events, Tracify attribution.
  • Grafana Loki integration — ship events via protobuf + snappy with batched delivery and backoff retry.
  • Bring your own router — exposes http.HandlerFunc values; no framework lock-in.

Install

go get github.com/foomo/sesamy-go

Quick start

package main

import (
  "log"
  "net/http"

  "github.com/foomo/sesamy-go/pkg/collect"
  "go.uber.org/zap"
)

func main() {
  l, _ := zap.NewProduction()

  c, err := collect.New(l,
    collect.WithTagging("https://sgtm.example.com"),
  )
  if err != nil {
    log.Fatal(err)
  }

  mux := http.NewServeMux()
  mux.HandleFunc("/g/collect", c.GTagHTTPHandler)  // gtag.js
  mux.HandleFunc("/mp/collect", c.MPv2HTTPHandler) // Measurement Protocol v2

  log.Fatal(http.ListenAndServe(":8080", mux))
}

Point gtag.js at https://your-domain/g/collect (via the GTM container generated by sesamy-cli) and events flow through your middleware to the configured tagging server.

Documentation

Start at the Getting Started guide and the core concepts page.

Packages

Import path Purpose
pkg/sesamy Core Event[P], EventName constants, decode helpers.
pkg/encoding/gtag, pkg/encoding/mpv2 Protocol payload types (form-encoded and JSON).
pkg/encoding/gtagencode, pkg/encoding/mpv2encode Convert GTag ↔ MPv2.
pkg/http, pkg/http/gtag, pkg/http/mpv2 HTTP handlers and middleware chains for each protocol.
pkg/client Direct GTag and MPv2 senders for server-to-GA traffic.
pkg/collect High-level collect server: handlers + forwarding to a tagging URL.
pkg/session Parse _ga (client ID) and _ga_<id> (session ID + number) cookies.
pkg/provider/cookiebot Cookiebot consent cookie type.
pkg/provider/emarsys Emarsys typed events (cart, category, purchase, view).
pkg/provider/tracify Tracify attribution events.
integration/loki Push events to Grafana Loki (protobuf + snappy).

Development

make check        # tidy + generate + lint + test
make test         # tests with -tags=safe
make test.race    # tests with race detector
make lint.fix     # auto-fix lint

Requires mise for tool management (mise install).

References

How to Contribute

Contributions are welcome! Please read the contributing guide.

Contributors

License

Distributed under MIT License, please see the license file within the code for more details.

Made with ♥ foomo by bestbytes

About

Server Side Tag Management System (sesamy) Go SDK

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors