Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ docker run \
-e GA_COLLECT_ENDPOINT=/fetch \
-e GA_COLLECT_REDIRECT_ENDPOINT=/fetch_r \
-e GA_COLLECT_J_ENDPOINT=/fetch_j \
-e GA_COLLECT_G_ENDPOINT=/fetch_g \
-e PROXY_IP_HEADER=X-Forwarded-For \
-e PROXY_IP_HEADER_INDEX=0 \
-e ENABLE_SERVER_SIDE_GA_COOKIES=true \
Expand Down Expand Up @@ -86,6 +87,7 @@ docker run \
|```GA_COLLECT_ENDPOINT```|Set the new name for the /collect endpoint.|/fetch|
|```GA_COLLECT_REDIRECT_ENDPOINT```|Set the new name for the /r/collect endpoint.|/fetch_r|
|```GA_COLLECT_J_ENDPOINT```|Set the new name for the /j/collect endpoint. Couldn't find out yet for what this endpoint is. If you know more, please share! :)|/fetch_j|
|```GA_COLLECT_G_ENDPOINT```|Set the new name for the /g/collect endpoint. Couldn't find out yet for what this endpoint is. If you know more, please share! :)|/fetch_g|
|```PROXY_IP_HEADER```|The header variable where the proxy will find the IP address of the user.|X-Forwarded-For|
|```PROXY_IP_HEADER_INDEX```|The header variable value will be split by comma. With this variable you can set the index of the users IP.|0|
|```ENABLE_SERVER_SIDE_GA_COOKIES```|If the proxy should transfer the client id to a serverside cookie, set this to true.|true|
Expand Down
5 changes: 5 additions & 0 deletions server/ga.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func googleAnalyticsJsHandle(w http.ResponseWriter, r *http.Request, path string
re = regexp.MustCompile(`\"/j\/collect`)
body = re.ReplaceAll([]byte(body), []byte(`"`+settingsGGGP.GaCollectEndpointJ))

re = regexp.MustCompile(`\"/g\/collect`)
body = re.ReplaceAll([]byte(body), []byte(`"`+settingsGGGP.GaCollectEndpointG))

re = regexp.MustCompile(`\"/collect`)
body = re.ReplaceAll([]byte(body), []byte(`"`+settingsGGGP.GaCollectEndpoint))

Expand Down Expand Up @@ -301,6 +304,8 @@ func googleAnalyticsCollectHandle(w http.ResponseWriter, r *http.Request) {
clientURL = `https://www.google-analytics.com/r/collect`
case settingsGGGP.GaCollectEndpointJ:
clientURL = `https://www.google-analytics.com/j/collect`
case settingsGGGP.GaCollectEndpointG:
clientURL = `https://www.google-analytics.com/g/collect`
case settingsGGGP.GaCollectEndpoint:
fallthrough
default:
Expand Down
3 changes: 3 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type settingsStruct struct {
GaCollectEndpoint string
GaCollectEndpointRedirect string
GaCollectEndpointJ string
GaCollectEndpointG string
RestrictGtmIds bool
AllowedGtmIds []string
EnableServerSideGaCookies bool
Expand Down Expand Up @@ -135,6 +136,7 @@ func main() {
settingsGGGP.GaCollectEndpoint = os.Getenv(`GA_COLLECT_ENDPOINT`)
settingsGGGP.GaCollectEndpointRedirect = os.Getenv(`GA_COLLECT_REDIRECT_ENDPOINT`)
settingsGGGP.GaCollectEndpointJ = os.Getenv(`GA_COLLECT_J_ENDPOINT`)
settingsGGGP.GaCollectEndpointG = os.Getenv(`GA_COLLECT_G_ENDPOINT`)

settingsGGGP.AllowedGtmIds = strings.Split(os.Getenv(`GTM_IDS`), `,`)

Expand Down Expand Up @@ -229,6 +231,7 @@ func main() {
http.HandleFunc(settingsGGGP.GaCollectEndpoint, collectHandle)
http.HandleFunc(settingsGGGP.GaCollectEndpointRedirect, collectHandle)
http.HandleFunc(settingsGGGP.GaCollectEndpointJ, collectHandle)
http.HandleFunc(settingsGGGP.GaCollectEndpointG, collectHandle)

if err := http.ListenAndServe(`:8080`, nil); err != nil {
panic(err)
Expand Down