Skip to content

Laravel Go ​

The official github.com/simplestats-io/laravel-go-client module brings SimpleStats to apps built on Laravel Go. It tracks the same data as the Laravel client package: visitors with their UTM parameters, referrer and entry page, registrations, logins, payments, page views, custom events and custom properties. Everything lands on the same dashboard, so Laravel apps on PHP, Rust and Go can live side by side in the same team.

TIP

This page covers the setup. Every option, the payment interface, custom properties and the differences to the PHP client are explained in the README on GitHub.

Requirements ​

  • Laravel Go 0.1 (beta)
  • Go 1.27 or later
  • A queue worker (page views stay off on the sync queue)

Installation ​

Add the module to your app (the package is called simplestats in your code):

bash
go get github.com/simplestats-io/laravel-go-client@latest

Register the package in bootstrap/app.go and tell it which model your users are:

go
// bootstrap/app.go
import (
	simplestats "github.com/simplestats-io/laravel-go-client"
	laravel "go.laravel.com"

	"app/models"
)

func Options() laravel.Options {
	return laravel.Options{
		Packages: []laravel.Package{
			simplestats.New(
				simplestats.TrackUsers[models.User](),
			),
		},
		// ...
	}
}

Your user model needs no methods: its key is the id SimpleStats knows the user by, and its CreatedAt field is the registration time. Models that differ add TrackingID or TrackingTime, see Tracking Users in the README.

Add the API token of your project to your .env:

bash
SIMPLESTATS_API_TOKEN=your-project-token

From the next request on, visitors, page views, registrations and session logins are tracked. The API calls run through your queue, so keep a worker running:

bash
laravel queue:work

Check Your Setup ​

bash
laravel simplestats:status

The command shows whether your token works, the API is reachable and page views are on. Without the Laravel CLI, run go run . simplestats:status.

Payments ​

Laravel Go has no Cashier, so there are no payment provider presets. Implement the TrackablePayment interface on the model where you store your payments and register it with simplestats.TrackPayments[models.Payment](). That works with any provider. Amounts are in cents:

go
// bootstrap/app.go
simplestats.New(
	simplestats.TrackUsers[models.User](),
	simplestats.TrackPayments[models.Payment](),
),
go
// models/payment.go
func (p *Payment) TrackingPerson(ctx context.Context) (simplestats.Person, error) {
	user, err := model.Find[User](ctx, p.UserID)
	if err != nil {
		return nil, err
	}

	return simplestats.User(&user), nil
}

func (p *Payment) TrackingGross() int64     { return p.Gross } // in cents
func (p *Payment) TrackingNet() int64       { return p.Net }   // in cents
func (p *Payment) TrackingCurrency() string { return p.Currency }

TrackingPerson returns who paid: simplestats.User(&user) attributes the payment to the user's registration, simplestats.Visitor{Hash: ...} to a visit (guest checkout). The payment's key and CreatedAt field are used as id and time, like on the user model.

Subscriptions (for MRR and ARR), guest checkouts and payments that should wait for a completed status (PassesTrackingCondition) are covered in the README.

Logins, Custom Events and Properties ​

Session logins are detected automatically. Logins through an API token, custom events and custom properties are one call each. The first argument is the request (r) or a context derived from it, the event id makes an event unique, so a retry never counts it twice:

go
simplestats.TrackLogin(r, &user)
simplestats.TrackCustomEvent(r, fmt.Sprint(order.ID), "order_shipped", simplestats.User(&user))
simplestats.TrackCustomProperties(r, map[string]any{"plan": "pro"}, simplestats.User(&user))

Good to Know ​

  • Pages behind a login: routes behind auth.Authenticate, auth.RequireVerifiedEmail or an auth.Via request guard are left out of page views, like in the PHP client. Add other areas you want to skip to except (e.g. SIMPLESTATS_EXCEPT=admin*).
  • Reverse proxies: add your proxy to m.Proxies in bootstrap/app.go, so visitors get their real IP address and country (see Trust your reverse proxy). Laravel Cloud trusts its proxies automatically.
  • Bot detection: a built-in heuristic filters bots by default. You can plug in your own detector with simplestats.DetectBots, see the README.
  • Headless and SPA setups: set SIMPLESTATS_TRACKING_STORAGE=cache and SIMPLESTATS_MIDDLEWARE_GROUPS=api, as described in Headless, SPA & Stateless.
  • Static caching and marketing sites: enable the beacon with SIMPLESTATS_BEACON_ENABLED=true.
  • Beta framework: Laravel Go is still a 0.x beta. The module follows semantic versioning, and the release notes tell you when an update needs a change in your app.