Google Analytics is actually a pretty powerful event tracking system allowing you to track events, timing tasks, exceptions along with the traditional pageviews. We use the Google Analytics Measurement Protocol to send events to analytics.
Check out the GoDocs but usage is simple. Create a new GA object with
gameasure.New
passing the TrackingID and an anonymous ClientID which
can be any value. Then use the object to send events.
ga := gameasure.New("UA-XXXXXXX-X", "1231231234")
ga.Event(gameasure.Event{
Category: "Food",
Action: "Eat",
Label: "Invoking Food to Eat",
})
Sending Timing Events:
ga := &gameasure.New("UA-XXXXXXX-X", "1231231234")
t := UserTiming{
Category: "Subscription",
Variable: "Subscribe",
Label: "Stripe"
}
t.Begin()
defer func() {
t.End()
go ga.UserTiming(t)
}()
// Do Stuff
Use it as a middleware to log API requests to Google Analytics:
r := mux.NewRouter()
r.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
trackerIds := map[string]string{
"api.acksin.com": "UA-XXXXXXX-1",
"default": "UA-XXXXXXX-2",
}
http.ListenAndServe(":8080", gameasure.NewGAHandler(r, trackerIds))
Other supported events are:
UserTiming
Pageview
Exception
This is a project of Acksin. Acksin provides tools to make your infrastructure more efficient and cost effective. Check out our spot instance bidding tool ParkingSpot.
Copyright (C) 2016 Acksin hey@acksin.com
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.