Skip to content

Commit

Permalink
Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Apr 22, 2018
1 parent cf05070 commit 9bdf85b
Show file tree
Hide file tree
Showing 691 changed files with 128,864 additions and 34,848 deletions.
57 changes: 28 additions & 29 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

[[constraint]]
name = "google.golang.org/grpc"
version = "~1.10.0"
version = "~1.11.1"

[[constraint]]
name = "github.com/go-yaml/yaml"
revision = "c95af922eae69f190717a0b7148960af8c55a072"
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"

[[constraint]]
name = "github.com/satori/go.uuid"
revision = "063359185d32c6b045fa171ad7033ea545864fa1"
revision = "36e9d2ebbde5e3f13ab2e25625fd453271d6522e"

[[constraint]]
name = "github.com/rubenv/sql-migrate"
revision = "6edbfbd6a369ee82463312ec67b2c92f97a1d4dc"
revision = "081fe17d19ff4e2dd9f5a0c1158e6bcf74da6906"

[[constraint]]
name = "github.com/lib/pq"
revision = "83612a56d3dd153a94a629cd64925371c9adad78"
revision = "d34b9ff171c21ad295489235aec8b6626023cd04"

[[constraint]]
name = "github.com/gorilla/handlers"
Expand All @@ -36,28 +36,28 @@

[[constraint]]
name = "github.com/gorilla/websocket"
revision = "292fd08b2560ad524ee37396253d71570339a821"
revision = "eb925808374e5ca90c83401a40d711dc08c0c0f6"

[[constraint]]
name = "github.com/yuin/gopher-lua"
revision = "7d7bc8747e3f614c5c587729a341fe7d8903cdb8"
revision = "84ea3a3c79b3c4b3b39606cc96f255cd63635ce0"

[[constraint]]
name = "github.com/gorhill/cronexpr"
revision = "d520615e531a6bf3fb69406b9eba718261285ec8"

[[constraint]]
name = "golang.org/x/crypto"
revision = "1875d0a70c90e57f11972aefd42276df65e895b9"
revision = "88942b9c40a4c9d203b82b3731787b672d6e809b"

[[constraint]]
name = "github.com/gobuffalo/packr"
revision = "6434a292ac52e6964adebfdce3f9ce6d9f16be01"
version = "~1.10.7"

[[override]]
name = "github.com/prometheus/client_golang"
revision = "d49167c4b9f3c4451707560c5c71471ff5291aaa"

[[constraint]]
name = "github.com/stretchr/testify"
version = "~1.1.4"
version = "~1.2.1"
117 changes: 117 additions & 0 deletions ga/ga.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2018 The Nakama Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ga

import (
"bytes"
"errors"
"fmt"
"net/http"
"net/url"
"regexp"
)

const gaURL = "https://www.google-analytics.com/collect"

var gacodeRegexp = regexp.MustCompile(`^UA-\d+-\d+$`)

// Event is a GA event.
type Event struct {
Ec string // event category
Ea string // event action
El string // event label
Ev string // event value
}

// AppInfo represents a mobile app info GA event.
type AppInfo struct {
An string // app name
Aid string // app identifier
Av string // app version
Aiid string // app installer identifier
}

// SendAppInfo will send the AppInfo struct to GA over HTTP.
func SendAppInfo(httpc *http.Client, gacode string, cookie string, app *AppInfo) error {
values := url.Values{}
values.Add("an", app.An)
values.Add("av", app.Av)
values.Add("aid", app.Aid)
values.Add("aiid", app.Aiid)
return SendValues(httpc, gacode, cookie, values)
}

// SendEvent will send the event struct to GA over HTTP.
func SendEvent(httpc *http.Client, gacode string, cookie string, event *Event) error {
if len(event.Ec) < 1 || len(event.Ea) < 1 {
return errors.New("event category/action must be set")
}

values := url.Values{}
values.Add("ec", event.Ec)
values.Add("ea", event.Ea)

if len(event.El) > 0 {
values.Add("el", event.El)
}
if len(event.Ev) > 0 {
values.Add("ev", event.Ev)
}

values.Add("t", "event")
return SendValues(httpc, gacode, cookie, values)
}

// SendValues will send supplied values to GA over HTTP.
func SendValues(httpc *http.Client, gacode string, cookie string, values url.Values) error {
if !gacodeRegexp.MatchString(gacode) {
return errors.New("invalid tracking id")
}

// Add required params
values.Add("v", "1")
values.Add("tid", gacode)
values.Add("cid", cookie)

// Send request
buf := bytes.NewBufferString(values.Encode())
resp, err := httpc.Post(gaURL, "application/x-www-form-urlencoded", buf)
if err != nil {
return err
}

defer resp.Body.Close()

if resp.StatusCode >= 400 {
return fmt.Errorf("request failed with '%v' status", resp.StatusCode)
}
return nil
}

// SendSessionStart will send a session start event to GA over HTTP.
func SendSessionStart(httpc *http.Client, gacode string, cookie string) error {
values := url.Values{}
values.Add("t", "event")
values.Add("sc", "start")
return SendValues(httpc, gacode, cookie, values)
}

// SendSessionStop will send a session stop event to GA over HTTP.
func SendSessionStop(httpc *http.Client, gacode string, cookie string) error {
values := url.Values{}
values.Add("t", "event")
values.Add("sc", "end")
return SendValues(httpc, gacode, cookie, values)
}
Loading

0 comments on commit 9bdf85b

Please sign in to comment.