forked from puppetlabs-toy-chest/wash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics.go
40 lines (37 loc) · 934 Bytes
/
analytics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"encoding/json"
"fmt"
"net/http"
"github.com/puppetlabs/wash/analytics"
apitypes "github.com/puppetlabs/wash/api/types"
log "github.com/sirupsen/logrus"
)
// swagger:route POST /analytics/screenview
//
// Submits a screenview to Google Analytics
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Schemes: http
//
// Responses:
// 200:
// 404: errorResp
var screenviewHandler = handler{logOnly: true, fn: func(w http.ResponseWriter, r *http.Request) *errorResponse {
var body apitypes.ScreenviewBody
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
return badRequestResponse(fmt.Sprintf("Error unmarshalling the request body: %v", err))
}
ctx := r.Context()
err := analytics.GetClient(ctx).Screenview(body.Name, body.Params)
if err != nil {
log.Info(err)
return badRequestResponse(err.Error())
}
return nil
}}