ANALYTICS INFRASTRUCTURE SELF-HOSTED CLOUD INFRASTRUCTURE (COOLIFY & DOCKER)

Self-Hosted Server-Side GTM Gateway on Coolify: path.dlayer.tech

A cost-effective, self-managed server-side tracking infrastructure on Coolify providing full ownership over telemetry routing, data hygiene, and first-party cookies.

CATEGORY ANALYTICS INFRASTRUCTURE
STACK & RUNTIME Coolify PaaS • Docker Compose • gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable • Server GTM (GTM-M3MVQHRR) • path.dlayer.tech & debug.dlayer.tech • Traefik / Let's Encrypt TLS

Core Code Architecture:

Coolify Docker Compose Specification (Tagging & Preview Servers)
Coolify Docker Compose Specification (Tagging & Preview Servers)
yaml
                version: '3.8'

services:
  tagging-server:
    image: gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
    container_name: sgtm-tagging-server
    restart: always
    environment:
      - CONTAINER_CONFIG=${CONTAINER_CONFIG} # GTM-M3MVQHRR base64 string
      - PREVIEW_SERVER_URL=https://debug.dlayer.tech
      - PORT=8080
    ports:
      - "8080:8080"
    networks:
      - coolify

  preview-server:
    image: gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable
    container_name: sgtm-preview-server
    restart: always
    environment:
      - CONTAINER_CONFIG=${CONTAINER_CONFIG}
      - RUN_AS_PREVIEW_SERVER=true
      - PORT=8080
    ports:
      - "8081:8080"
    networks:
      - coolify

networks:
  coolify:
    external: true
              

GTM Template & Configuration Screenshots:

Verified Sandbox Environment
Coolify Service Architecture: Tagging & Preview Server Containers GTM UI
Coolify Service Details showing Tagging Server and Preview Server Compose Resources
Coolify Compose service configuration running Google official sGTM Docker images with health-monitoring and automatic restart policies.
Coolify Environment Variables Configuration GTM UI
Coolify Environment Variables for sGTM Tagging and Preview Servers
Centralized environment variable management configuring CONTAINER_CONFIG, PREVIEW_SERVER_URL, RUN_AS_PREVIEW_SERVER, and internal port routing.
First-Party Domain & SSL Routing GTM UI
Coolify Domains mapping path.dlayer.tech and debug.dlayer.tech
Automated HTTPS domain mapping directing live traffic to path.dlayer.tech and real-time debugging sessions to debug.dlayer.tech.
Live Server GTM Debugger & Event Telemetry Verification GTM UI
Server GTM Preview Mode showing GA4 Claimed and outgoing POST 204 to Google Analytics
Live verification in Server GTM Debugger (GTM-M3MVQHRR on path.dlayer.tech) claiming incoming GA4 hits and dispatching authenticated POST 204 requests.
01

Dual-Container Architecture on Coolify

Server-Side GTM requires distinct environments for processing high-volume live production hits versus debugging interactive preview sessions. I engineered a decoupled Docker Compose architecture within Coolify:

  • Tagging Server (path.dlayer.tech): Optimized for high concurrency, receiving live tracking hits from client browsers and forwarding to analytics/ad platforms.
  • Preview Server (debug.dlayer.tech): Configured with RUN_AS_PREVIEW_SERVER=true to handle real-time GTM Preview Mode debugging without degrading production throughput.
  • Unified Docker Network: Both containers share the internal Coolify bridge network for seamless communication and zero public port exposure.
02

First-Party Domain & SSL Termination

To establish genuine first-party cookie context and bypass third-party browser restrictions, custom subdomains were mapped through Coolify with automated Traefik reverse proxy routing and Let's Encrypt SSL certificates.

Service Name Public Endpoint Role SSL / HTTP Redirect
Tagging Server https://path.dlayer.tech Production Event Ingestion & CAPI Dispatch HTTP -> HTTPS Enabled (Auto SSL)
Preview Server https://debug.dlayer.tech Interactive GTM Preview Mode Debugging HTTP -> HTTPS Enabled (Auto SSL)
03

Live Telemetry Verification in Server GTM

The deployment was validated using Server GTM Container GTM-M3MVQHRR. As shown in the live preview debugger, incoming client hits (/g/collect) are claimed by the GA4 Client, enriched with server-side metadata, and dispatched upstream (HTTP 204) to Google Analytics endpoints in sub-50ms latency.

Browser Client (GTM) →
POST /g/collect to path.dlayer.tech →
sGTM Container (GTM-M3MVQHRR) →
GA4 Web Client Claimed →
Upstream POST 204 (Google Analytics / Meta CAPI)
04

Cost & Operational Advantages over SaaS Vendors

Operating a self-hosted gateway on Coolify eliminates arbitrary vendor tier limits and ensures complete data governance.

Dimension Coolify Self-Hosted sGTM Commercial SaaS Hosting
Monthly Cost $5–$15 / month (fixed VPS compute) $100–$350+ / month (tiered by event volume)
Event Volume Limits Unlimited (governed only by server RAM/CPU) Hard caps or expensive overage charges
Data Privacy & GDPR 100% self-hosted on your own infrastructure Data transits 3rd-party vendor infrastructure
Maintenance Overhead Automated restarts & 1-click Docker upgrades via Coolify Managed by vendor