Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

Server-side GTM preview opens blank: the preview server you're missing

You set up a server-side Google Tag Manager container on your own server, open Preview, and get a blank screen. Nothing in the logs explains it. On a self-hosted setup, the cause is almost always the same: the preview se

You set up a server-side Google Tag Manager container on your own server, open Preview, and get a blank screen. Nothing in the logs explains it. On a self-hosted setup, the cause is almost always the same: the preview server is missing or misconfigured.

Key points

  • A self-hosted server container runs as two containers: the tagging server and the preview server.
  • PREVIEW_SERVER_URL must be a public HTTPS URL. An internal Docker hostname is rejected and the tagging container crash-loops.
  • The preview server needs its own subdomain with SSL, behind your reverse proxy.
  • Set the Server container URL in GTM Admin, or Preview won't open.

The two-container setup

Both containers use the same official image and the same container config. One runs as the preview server:

services:
  sgtm:
    image: gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
    environment:
      CONTAINER_CONFIG: "${CONTAINER_CONFIG}"
      PREVIEW_SERVER_URL: "https://sgtm-preview.example.com"
    ports:
      - "127.0.0.1:8081:8080"
  sgtm-preview:
    image: gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
    environment:
      CONTAINER_CONFIG: "${CONTAINER_CONFIG}"
      RUN_AS_PREVIEW_SERVER: "true"
    ports:
      - "127.0.0.1:8082:8080"

Each one sits behind the reverse proxy on its own subdomain with a certificate.

Why the internal hostname fails

The tagging server validates PREVIEW_SERVER_URL and accepts only https:// addresses. If you point it at the Docker service name over HTTP, the container stops with an invalid preview server URL error and restarts in a loop. The fix is a public subdomain for the preview server.

Three more things to check

  1. Docker is actually running. docker --version only proves the client exists. If you see dial unix /var/run/docker.sock: no such file or directory, run systemctl start docker && systemctl enable docker.
  2. The port is free. Check with ss -tlnp | grep 8081 before choosing ports. On cPanel servers, 8080 is often taken.
  3. The .env wasn't mangled. Write it with a quoted heredoc (cat << 'EOF' > .env) so the shell doesn't expand characters inside the container config.

Why it's worth fixing

The server Preview is the only place that shows what reached the server and which tag fired. Without it, you're validating the Conversions API blind.

This setup, including the reverse proxy for cPanel and nginx, is section 5 of the 4-Layer Tracking Kit. The free 13 Silent Tracking Failures field guide lists the other failures that break server-side tracking without an error.

FAQ

Why does the server container preview open blank?

A self-hosted server container needs a second container running as the preview server. Without it, or with a PREVIEW_SERVER_URL that isn't a public HTTPS address, the debug interface has nothing to talk to.

Can PREVIEW_SERVER_URL point to the Docker service name?

No. The value must be a public HTTPS URL. An internal hostname like http://sgtm-preview:8080 is rejected and the tagging container fails to start with an invalid preview server URL error.

Why does Preview refuse to open at all?

Check that the Server container URL is set in the container's Admin settings. Without it, Preview doesn't start.

Originally published at https://lp.bitencourtco.com/kit-tracking/en/guides/server-side-gtm-preview-blank/ by Bitencourt & Co. The full setup, from the ad click to HubSpot deal stages back to Meta, is in the 4-Layer Tracking Kit.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.