Thanks for previewing Google's new tag platform documentation! This site is in public beta. (Feedback)

Set up server-side tagging with Cloud Run

Stay organized with collections Save and categorize content based on your preferences.

This guide explains how to:

  • Provision a preview server to enable the preview feature for the container.
  • Provision a tagging server to handle live traffic.
  • Increase or decrease the number of servers that are running your Google Tag Manager container.

Prerequisites

  1. You need a GCP account. If you don't have one, create a new GCP account.
  2. You need a GCP billing account. If you don't have one, create a GCP billing account (requires the Billing Account Creator role).
  3. You need the Project Creator and the Billing Account User role. Learn more about adding roles.

1. Provision a preview and tagging server

Create a Google Tag Manager server container

  1. Open Google Tag Manager.

  2. In the account row, click on the overflow menu > Create Container.

  3. Create a new server container.

  4. Click the "Manually provision tagging server" radio button. Note the container config. You'll need it to provision your server.

Create a new GCP project

To create a new GCP project for your tagging server:

  1. Open Google Cloud Console.

  2. Create a new GCP project.

  3. Name your project. We recommend using your container ID for convenience. This name is used only within GCP.

  4. Note the GCP project ID, because you will need it to create your tagging server.

Provision a new preview and tagging server

You can provision a Cloud Run service either via the command line (CLI) or in the user interface. Both steps involve provisioning both a tagging and a preview server. The tagging server runs your container and handles live traffic while the preview server enables you to preview the server container.

To create your preview and tagging servers:

Cloud Run cost

In this Cloud Run configuration, each server costs approximately $45 /month (USD). Each server is a Cloud Run instance with 1 vCPU and 0.5GB memory using the CPU always allocated pricing model.

We recommend running a minimum of 2 instances to reduce the risk of data loss in case of a server outage. However, you may choose to run fewer (or more) servers. We expect that autoscaling 2-10 servers will handle 35-350 requests per second, though the performance will vary with the number of tags, and what those tags do.

Cloud Run will dynamically scale with load. The max-instances setting is the worst case scenario for how much you will need to pay for resources. Cloud Run won't provision that many instances unless necessary.

Cloud Run calculator

Optional: Migrating from App Engine

If you previously created an App Engine deployment and have verified that it is no longer receiving any traffic, disable the App Engine application to prevent unexpected billing charges.

Optional: Disable request logging

By default, information about every single request (e.g. request path, query parameters, etc) is logged. If your tagging server handles a lot of requests per month (e.g. greater than 1 million), those log messages may incur significant logging charges. To reduce or eliminate the logging charges, we recommend disabling the request logging.

To disable request logging:

  1. In Google Cloud platform, open the Logs Router. Make sure you're in the project that matches your container ID:
    screenshot of GCP project selector, showing a sample Tag Manager container
ID.
  2. For the Type: Cloud Logging bucket, Name: _Default line, select the overflow menu, then click Edit Sink.
  3. Under Sink destination, select logs bucket _Default.
  4. Under Choose logs to include in sink, add a new line. Enter the following rule to the existing inclusion filter:

    NOT LOG_ID("run.googleapis.com/requests")
    
  5. To also disable logging from the load balancer, add a new line and enter the following rule to the existing inclusion filter:

    NOT LOG_ID("requests")
    
  6. Click Update Sink button at the bottom

Now the requests will be excluded from logging. Check the Logs Explorer to ensure that new requests are not appearing in the logs.

2. Map the deployment to your custom domain

We recommend that you modify the deployment to use a subdomain of your website.

Map your website subdomain to your tagging server.

3. Add the server URL to Google Tag Manager

Now that you have a server, you need to make sure that Google Tag Manager knows it should use your server.

  1. Open Google Tag Manager.

  2. Click on the server container you want to point to your tagging server.

  3. Open your server container settings in the Admin tab > Container Settings.

  4. Click Add URL and paste your server URL.

  5. Save and go back to your workspace.

4. Validation

Now that you've set up your tagging server, make sure that it works as intended. In your Tag Manager workspace, click the Preview button. If the preview page loads, then everything is set up correctly.

Previewing multiple URLs

If you have mapped multiple domains to a single tagging server, make sure each URL is added to the container settings.

If you provided multiple URLs, all paths (the string after the domain name) must match.

Works Does not work
URL 1: example.com/abc
URL 2: example2.com/abc
URL 1: example.com/abc
URL 2: example2.com/def

If multiple URLs are added, you will see an icon next to the Preview button that allows you to select the URL to preview.