1. Initial Setup of GTM Server
Understanding the Docker Image
- We started by pulling the GTM server Docker image:
docker pull gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
- By analyzing the image, we identified the components and configuration files necessary for running a GTM server locally. The server dynamically loads its code each time it runs, based on the
CONTAINER_CONFIG
environment variable, which ensures it uses either the stable
or latest
configuration depending on the setup.
- Key components extracted from the Docker image:
server_bin.js
: The main entry point for the GTM server.
container-config.json
: Essential for configuring the container.
Reconstructing the Server Installation
- We rebuilt the GTM server by mimicking the environment within the Docker container:
- Installed dependencies (e.g., Node.js).
- Created a directory structure similar to the container.
- Configured environment variables and essential files.
- Challenges included:
- Lack of documentation for local installations.
- Misconfigured paths and missing dependencies during the reconstruction.
2. Running Dual Instances for Preview and Setup
The Need for Two Instances
- A breakthrough occurred when we realized that:
- One instance is required for the GTM tagging server.
- Another instance is needed for the GTM preview server.
- Without this separation, the preview functionality failed, leading to issues with debugging tags.
Preview Server Configuration
- Enabled the preview server by setting the following environment variables:
-e RUN_AS_PREVIEW_SERVER=true
- Example Docker command for the preview server:
docker run -d \
--name gtm-preview \
-p 4000:8080 \
-e CONTAINER_CONFIG=<config-string> \
-e RUN_AS_PREVIEW_SERVER=true \
gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
Tagging Server Configuration
- The main tagging server was configured without the preview server URL:
docker run -d \
--name gtm-server \
-p 3000:8080 \
-e CONTAINER_CONFIG=<config-string> \
gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
3. Google Tags: Transition and Configuration
Google Tags vs GA4 Tags
- Transitioning to the new Google Tags format required:
- Replacing legacy configurations.
- Understanding that GA4 Configuration Tags have been replaced with Google Tags.
Setting Up Google Tags
- Configured a Google Tag to send data to Analytics via the GTM server. The new Google Tag client is designed to import the web container definitions into the local GTM server instance, helping offload processing from client devices to the server, thereby increasing throughput capacity.
- Updated
transport_url
in the Google Tag settings to point to the GTM server:
https://www.example.com/tag
Common Issues
- Missing triggers for events.
- Incorrect client configuration, resulting in tags firing but not sending data to Analytics.
4. Nginx Reverse Proxy Configuration
Basic Setup
- Nginx was configured to route traffic between the local GTM server and external clients:
location /tag {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;