Skip to content

Commit

Permalink
try to use referer when the path is not forced
Browse files Browse the repository at this point in the history
  • Loading branch information
Guisardo committed Feb 27, 2016
1 parent bfec0d6 commit df8ebf9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ga-beacon/ga-beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,23 @@ func handler(w http.ResponseWriter, r *http.Request) {

// /account -> account template
if len(params) == 1 {
templateParams := struct {
Account string
}{
Account: params[0],
}
if err := pageTemplate.ExecuteTemplate(w, "page.html", templateParams); err != nil {
http.Error(w, "could not show account page", 500)
c.Errorf("Cannot execute template: %v", err)
referer := strings.Replace(strings.Replace(r.Header.Get("Referer"), "http://", "", 1), "https://", "", 1);
if len(referer) != 0 {
params = strings.SplitN(strings.Trim(r.URL.Path, "/") + "/" + referer, "/", 2)
} else {
templateParams := struct {
Account string
Referer string
}{
Account: params[0],
Referer: r.Header.Get("Referer"),
}
if err := pageTemplate.ExecuteTemplate(w, "page.html", templateParams); err != nil {
http.Error(w, "could not show account page", 500)
c.Errorf("Cannot execute template: %v", err)
}
return
}
return
}

// /account/page -> GIF + log pageview to GA collector
Expand Down

0 comments on commit df8ebf9

Please sign in to comment.