summaryrefslogtreecommitdiffstats
path: root/mixpanel.go
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2011-08-10 03:02:23 -0700
committerraylu <raylu@mixpanel.com>2011-08-10 03:02:23 -0700
commitd1bfe384e796cf2db9a057271b78666b310d0184 (patch)
tree0bc69ca17fa7bf63d4b491e31aa191c2b5021537 /mixpanel.go
parent5a4a473b7a5538be87837ea760205ede90a8482e (diff)
downloadaudioaxis-d1bfe384e796cf2db9a057271b78666b310d0184.tar.xz
add mixpanel tracking
Diffstat (limited to 'mixpanel.go')
-rw-r--r--mixpanel.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/mixpanel.go b/mixpanel.go
new file mode 100644
index 0000000..6c370bd
--- /dev/null
+++ b/mixpanel.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "http"
+ "encoding/base64"
+ "json"
+ "log"
+)
+
+func init() {
+ log.SetFlags(log.Ltime | log.Lshortfile)
+}
+
+func track(event, ip, id, song, user string) {
+ const token = "643bb718adc5d66de18617b4f0bf3489"
+
+ data := make(map[string]interface{})
+ data["event"] = event
+ properties := make(map[string]string)
+ properties["token"] = token
+ properties["ip"] = ip
+ properties["id"] = id
+ if song != "" {
+ properties["song"] = song
+ }
+ if user != "" {
+ properties["user"] = user
+ }
+ data["properties"] = properties
+
+ dataJSON, err := json.Marshal(data)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ values := make(http.Values)
+ values.Add("data", base64.StdEncoding.EncodeToString(dataJSON))
+ r, err := http.PostForm("https://api.mixpanel.com/track/", values)
+ if err == nil {
+ r.Body.Close()
+ }
+}