SiteHost

Google Tag Manager

Working with the Server-Side GTM Web Container

SiteHost provides a standard GTM Web Image, built and maintained by SiteHost from Google's official server-side Google Tag Manager (sGTM) image. This means you can deploy a working sGTM server directly from the Control Panel, without creating or maintaining a custom image yourself.

This article covers provisioning two containers from this image, a preview server and a tagging server, which together make up a working sGTM deployment.

The overall process is:

  1. Create a server container in Google Tag Manager
  2. Create the preview container using the GTM Web Image
  3. Create the tagging container using the same image
  4. Configure environment variables for each container
  5. Enable SSL certificates for both containers
  6. Test both containers
  7. Connect the tagging server to Google Tag Manager

NOTE: SiteHost maintains the image itself. The only configuration required on your side is environment variables. A MySQL/database container is not required.


Step 1: Create a server container in Google Tag Manager

Before provisioning anything in SiteHost, you need a Server container in Google Tag Manager. This is what generates the Container Config string used in Step 3, and it's the destination the tagging server reports back to.

  1. Open Google Tag Manager.
  2. In your account's overflow menu, click Create Container.
  3. In Container Settings, name the container and select Server as the target platform, then click Create.
  4. A setup screen will offer Automatically provision tagging server, this is Google's own Cloud Run auto-deployment path and can be skipped, since you are deploying via SiteHost's GTM Web Image instead. For background on how server containers work and how the data flow between the browser, the tagging server, and Google Analytics fits together, Google's own walkthroughs are a useful reference:

NOTE: These articles use Google's own Cloud Run automatic provisioning as their example deployment. Only the server container creation and GA4 client/tag/web-container configuration portions apply to this deployment. the actual server hosting is done through SiteHost, as described below, not Cloud Run.


Step 2: Create the containers

You will repeat this process twice, once for the preview server, once for the tagging server. Both are created the same way; only the environment variables differ (see Step 3).

Getting the Container Config string

Before creating the containers, get your Container Config string ready, since it's needed for both:

  1. Go to tagmanager.google.com and open the Server container you created in Step 1.
  2. Click the Container ID in the top-right.
  3. Click Manually provision tagging server.
  4. Copy the full Container Config value shown there.

Per-container creation steps

Page 1:

  1. In the Control Panel, go to Containers → Create Container.
  2. Select the Google Tag Manager container option in the web images tab.
  3. Enter the domain or subdomain this container will use (e.g. sgtm-preview.example.com for the preview container, sgtm.example.com for the tagging container). A domain or subdomain is required at this step.
  4. Select the server this container will be deployed on.
  5. Click Next Step.

Page 2:

  1. Leave the SSH section empty, this deployment does not use an SSH user.
  2. Leave the Database section empty, this deployment does not use a database.
  3. Fill in the Environment Variables section, see Step 3 below for the exact values. This step cannot be skipped or left with placeholder values; the container will not start without valid environment variables.
  4. Click Deploy.

Repeat both pages for the second container.

You'll now have two containers, for example:

  • sgtm-preview.example.com, the preview server
  • sgtm.example.com, the tagging server

Step 3: Environment variables

Use the Container Config string retrieved in Step 2 for both containers below.

Preview container:

Variable Value
CONTAINER_CONFIG Your Container Config string
RUN_AS_PREVIEW_SERVER true

Tagging container:

Variable Value
CONTAINER_CONFIG Same Container Config string
PREVIEW_SERVER_URL The preview container's URL, e.g. https://sgtm-preview.example.com

If any of these are left blank or incorrect, the container will fail to start, this is not optional configuration, unlike a typical web container where environment variables might just customize behavior.

If you need to change environment variables after deployment, this can be done from the container's page in the Control Panel, restart the container afterward for the change to take effect.

Optionally, if you are using BiqQuery or Firestore, you can define the GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_CLOUD_PROJECT environmental variables.
The GOOGLE_APPLICATION_CREDENTIALS environment variable is expected to be a JSON file like: /container/config/service_account_key.json. Google has an article with more information here: (Optional) Include Google Cloud credentials
This would require adding an SSH user linked to both the preview and tagging containers, and adding the /container/config/service_account_key.json file over SSH/SFTP.


Step 4: Enable SSL certificates

Both containers need a valid SSL certificate before they can be used, since Google Tag Manager's preview flow and the tagging server both expect HTTPS.

  1. Before requesting a certificate, make sure a DNS record for the domain or subdomain (e.g. sgtm.example.com) points to the Cloud Container's server IP address. The certificate request will fail if the DNS record isn't in place yet.
  2. In the Control Panel, open the container and go to the SSL section of the Cloud Container menu.
  3. Click Enable to request and apply the certificate.
  4. Repeat for the second container.

This can be done any time after the containers are deployed, it doesn't need to happen before Step 2 or 3, but both containers must have SSL enabled before testing (Step 5) or connecting to Google Tag Manager (Step 6), since both of those steps require HTTPS URLs.


Step 5: Test both containers

Since environment variables are already set during creation (Step 3), both containers should start correctly on first deploy. Confirm this:

Each container exposes a health check endpoint. Visit or curl:

https://sgtm-preview.example.com/healthy
https://sgtm.example.com/healthy

Both should return ok.


Step 6: Connect to Google Tag Manager

  1. In GTM, open your Server container.
  2. Go to Admin → Container Settings.
  3. Set Server container URL to your tagging container's URL, e.g. https://sgtm.example.com.
  4. Save.
  5. Click Preview in the GTM workspace to start a debug session.
  6. Load your website (the one with the corresponding web GTM container installed) in another tab and confirm events appear in the Preview/debug view.

If events show up correctly in Preview, the deployment is complete and working end to end.