How to set up server-side tagging with Google Tag Manager

Author:

Setting up server-side tagging with Google Tag Manager (GTM) allows for more secure and efficient data management by processing tags on a server rather than directly in the user’s browser. This setup reduces client-side load, enhances data privacy, and improves tracking accuracy. Here’s a step-by-step guide on how to set up server-side tagging with Google Tag Manager.

Step 1: Understand the Server-Side Tagging Architecture

Before diving into the setup, it’s crucial to understand the components involved in server-side tagging:

  1. Client-Side GTM: The standard version of Google Tag Manager that runs in the user’s browser.
  2. Server-Side GTM: A new container type that runs on a server, processing tags and sending data to various endpoints (like Google Analytics) securely.
  3. Tagging Server: A Google Cloud Platform (GCP) server or another hosting option that hosts your GTM server container.

Step 2: Set Up a Google Cloud Platform Account

  1. Create a Google Cloud Account:
  2. Create a New Project:
    • Click on the Select a Project dropdown at the top.
    • Click on New Project, give it a name, and click Create.

Step 3: Deploy a Server Container

  1. Enable the Cloud Run API:
    • In the Google Cloud Console, navigate to the API & Services dashboard.
    • Click on Enable APIs and Services.
    • Search for Cloud Run and enable it.
  2. Deploy GTM Server Container:
    • Go to the Google Tag Manager interface.
    • Create a new server container by selecting Create Container.
    • Choose Server as the container type and follow the prompts to set it up.
    • After creating the container, click on Web and select Get Started under Server-side tagging.
  3. Copy the Deployment Command:
    • GTM will provide a command to deploy the container. This command can be executed in the Google Cloud Shell or your local terminal with the Cloud SDK installed.
  4. Deploy the Container:
    • Run the provided command in the Google Cloud Shell or terminal. This command sets up a new Cloud Run service that hosts your GTM server container.
    • Wait for the deployment to complete. Once finished, you’ll receive a URL for your server.

Step 4: Configure the Server-Side GTM Container

  1. Access Your Server Container:
    • Go back to the GTM interface and select the newly created server container.
    • Click on Admin and then Container Settings.
  2. Configure Your Server URL:
    • In the Server URL section, input the URL you received after deploying the Cloud Run service. This URL will be used to send requests to your server.
  3. Set Up Server-Side Tags:
    • Create tags as you normally would in GTM, but now you will create server-side tags that can send data to various endpoints.

Step 5: Set Up Client-Side GTM to Forward Data

  1. Add a New Client:
    • In your client-side GTM container, create a new tag that will send data to your server container.
    • Go to your existing client-side container and create a new Tag.
  2. Configure the Tag:
    • Select the type of tag you want to create (e.g., Google Analytics, Custom HTML, etc.).
    • In the tag configuration, specify the server URL that you set up earlier (the URL of your server container).
    • Ensure that the tag is set to fire on the appropriate trigger (e.g., Page View, Click).
  3. Set Up Client:
    • Create a client in the server container to accept data from the client-side GTM.
    • Click on Clients in the server container, then New.
    • Select a client type (like Google Analytics) and configure it as needed.

Step 6: Configure Data Layer and Events

  1. Set Up Data Layer:
    • Ensure your website is using a data layer to pass data to GTM. This will enable you to send specific data points to your server-side tagging setup.
  2. Define Events:
    • Set up the events you want to track and ensure they are sent from the client-side GTM to the server-side GTM.

Step 7: Test Your Implementation

  1. Preview Mode:
    • Use GTM’s preview mode to test your setup. Open the GTM preview mode for both client and server containers to see if events are firing correctly.
  2. Check Network Requests:
    • In the browser’s developer tools, monitor the network requests to ensure data is being sent to your server container URL and that the server is responding correctly.
  3. Debugging:
    • Use the GTM Debug Console to view logs and see how data is processed through your server-side container.

Step 8: Monitor and Optimize

  1. Review Data in Google Analytics:
    • Ensure that the data sent from the server-side container is accurately reflected in Google Analytics or any other analytics platforms you are using.
  2. Adjust Tags and Triggers:
    • Based on your testing and monitoring, adjust the tags, triggers, and configurations as needed to optimize performance.
  3. Keep Security in Mind:
    • Regularly review permissions and access to your Google Cloud project to ensure that only authorized users can make changes.

Conclusion

Setting up server-side tagging with Google Tag Manager enhances the performance and security of your tracking setup. By following these steps, you can effectively deploy and manage a server-side GTM container, allowing you to collect and process data more securely and efficiently. This approach not only improves the speed and accuracy of your analytics but also helps you better comply with privacy regulations and standards. Regular monitoring and optimization will ensure that your server-side tagging setup continues to meet your tracking needs effectively.