Skip to content

Commit

Permalink
Bring back language selector
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaharagon committed Apr 2, 2024
1 parent 8b78ea3 commit cb34ed4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions umami.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ func (p Umami) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.

// Send visitor information to the Umami Events REST API endpoint
go func() {
payload := map[string]interface{}{
"referrer": r.Referer(),
"url": requestPath,
"website": p.WebsiteUUID,
}

hostname, _, err := net.SplitHostPort(r.Host)
if err != nil {
hostname = r.Host
}
payload["hostname"] = hostname

payload["language"] = strings.Split(r.Header.Get("Accept-Language"), ",")[0]

visitorIP, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
Expand All @@ -91,8 +100,6 @@ func (p Umami) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.
}
}

resolution := ""

if p.CookieResolution != "" {
cookie, err := r.Cookie(p.CookieResolution)
if err != nil {
Expand All @@ -108,19 +115,12 @@ func (p Umami) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.
Value: "",
}
}
resolution = cookie.Value
payload["resolution"] = cookie.Value
}

visitorInfo := map[string]interface{}{
"payload": map[string]interface{}{
"hostname": hostname,
"language": r.Header.Get("Accept-Language"),
"referrer": r.Referer(),
"screen": resolution,
"url": requestPath,
"website": p.WebsiteUUID,
},
"type": "event",
"payload": payload,
"type": "event",
}

body, err := json.Marshal(visitorInfo)
Expand Down

0 comments on commit cb34ed4

Please sign in to comment.