

Google Analytics Proxy
📊 Transparent proxy for tracking page views with Google Analytics
Installing
A release version Docker image can be pulled by running:
docker pull ghcr.io/joshdk/google-analytics-proxy:v0.1.0
Or, a development version binary can be installed by running:
go install github.com/joshdk/google-analytics-proxy@master
Configuration
This tool uses several environment variables as configuration.
Name |
Purpose |
Example |
$LISTEN |
Host and port that the proxy will listen on. |
0.0.0.0:8080 |
$UPSTREAM_ENDPOINT |
Address of the upstream service to be proxied. |
https://example.com |
$UPSTREAM_HOSTNAME |
(Optional) Hostname to used when proxying requests to the upstream. |
example.com |
$GOOGLE_ANALYTICS_TRACKING_ID |
Tracking ID for your Google Analytics property |
UA-123456789-1 |
$GOOGLE_ANALYTICS_PROPERTY_NAME |
Name of your Google Analytics property. |
example.com |
$GOOGLE_ANALYTICS_DRY_RUN |
(Optional) Disables Google Analytics reporting. |
true |
Usage
To run the Docker image, you can use a command like:
docker run \
--rm \
-p 8080:8080 \
-e LISTEN=0.0.0.0:8080 \
-e UPSTREAM_ENDPOINT=https://example.com \
-e UPSTREAM_HOSTNAME=example.com \
-e GOOGLE_ANALYTICS_PROPERTY_NAME=example.com \
-e GOOGLE_ANALYTICS_TRACKING_ID=UA-123456789-1 \
ghcr.io/joshdk/google-analytics-proxy:v0.1.0
Or, to run the local binary, you can use a command like:
LISTEN=0.0.0.0:8080 \
UPSTREAM_ENDPOINT=https://example.com \
UPSTREAM_HOSTNAME=example.com \
GOOGLE_ANALYTICS_PROPERTY_NAME=example.com \
GOOGLE_ANALYTICS_TRACKING_ID=UA-123456789-1 \
$GOPATH/bin/google-analytics-proxy
Browsing to https://localhost:8080 afterwards will display the proxied upstream.
License
This code is distributed under the MIT License, see LICENSE.txt for more information.