~evanj/evanjon.es

b4cc7cbe9006d98ba51ef0549168fdfb7409945d — Evan M Jones 3 months ago c6045df
Feat(track): Adding one more opt to segment server side analytics.
1 files changed, 13 insertions(+), 0 deletions(-)

M track/track.go
M track/track.go => track/track.go +13 -0
@@ 1,6 1,7 @@
package track

import (
	"fmt"
	"net/http"
	"time"



@@ 29,6 30,7 @@ func New(secret string) Track {
func (t Track) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	client := analytics.New(t.secret)
	defer client.Close()

	client.Enqueue(analytics.Page{
		UserId:    userId,
		Name:      r.URL.Path,


@@ 39,4 41,15 @@ func (t Track) ServeHTTP(w http.ResponseWriter, r *http.Request) {
			Set("Referer", r.Referer()).
			Set("RequestURI", r.RequestURI),
	})

	client.Enqueue(analytics.Track{
		UserId:    userId,
		Event:     fmt.Sprintf("PageView: %s", r.URL.Path),
		Timestamp: time.Now(),
		Properties: analytics.NewProperties().
			Set("Path", r.URL.Path).
			Set("UserAgent", r.UserAgent()).
			Set("Referer", r.Referer()).
			Set("RequestURI", r.RequestURI),
	})
}