Skip to content
/ gaxy Public

Google Analytics / Google Tag Manager Proxy

License

Notifications You must be signed in to change notification settings

duyet/gaxy

Repository files navigation

gaxy

Deployment: https://project-gaxy.appspot.com/ga.js

Docker Go test

Google Analytics / Google Tag Manager Proxy by Go.

How it works?

Development

Start server in local:

go run *.go

Build binary:

go build -o gaxy .
./gaxy

Testing:

go test

Installation

Using Docker

https://github.com/users/duyet/packages/container/package/gaxy

docker run -it -p 3000:3000 \
    -e ROUTE_PREFIX=/analytics \
    -e GOOGLE_ORIGIN=https://www.google-analytics.com \
    ghcr.io/duyet/gaxy:latest

Using Helm

https://github.com/duyet/charts/tree/master/gaxy

helm repo add duyet https://duyet.github.io/charts
helm install google-analytics-proxy duyet/gaxy

Using Google App Engine

https://cloud.google.com/appengine/docs/standard/go/quickstart

# 1. install gcloud
# 2. install app-engine-go component
gcloud components install app-engine-go
# 3. deploy
gcloud app deploy

Environment variables

The following environment values are provided to customize Gaxy:

  • ROUTE_PREFIX: Gaxy proxy prefix (e.g. /analytics). Default ""

  • GOOGLE_ORIGIN: Hostname to Google Analytics. Default https://www.google-analytics.com

  • INJECT_PARAMS_FROM_REQ_HEADERS: Convert header fields (if gaxy is behind reverse proxy) to request parameters.

    • e.g. INJECT_PARAMS_FROM_REQ_HEADERS=uip,user-agent will be add this to the collector URI: ?uip=[VALUE]&user-agent=[VALUE]

    • To rename the key, use [HEADER_NAME]__[NEW_NAME] e.g. INJECT_PARAMS_FROM_REQ_HEADERS=x-email__uip,user-agent__ua

    • List all the parameters of Google Analytics:

      - https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
      - https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
      
  • PORT: Gaxy webserver port. Default: 8080

Usage

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://project-gaxy.appspot.com/analytics.js'></script>
<!-- End Google Analytics -->

License

MIT