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

Author:

Setting up server-side tagging with Google Tag Manager (GTM) is an advanced feature that allows you to run your tags from a server rather than the client-side (i.e., the user’s browser). Server-side tagging improves website performance, enhances security, and provides more control over how data is sent to third-party services. It also reduces the reliance on client-side cookies, which is helpful in light of increasing privacy regulations like GDPR and CCPA.

Here’s a step-by-step guide to setting up server-side tagging using Google Tag Manager:

Step 1: Set Up Google Tag Manager Server Container

To implement server-side tagging, you need to create a Server container in GTM, as opposed to the default Web container used for client-side tagging.

  1. Log in to Google Tag Manager: Go to Google Tag Manager and sign in with your Google account.
  2. Create a New GTM Account or Container:
    • If you don’t have a GTM account, create one by clicking on Create Account.
    • If you already have an account, click Admin on the GTM dashboard and then click Create Container.
  3. Choose Server as the Container Type: When creating a new container, select Server from the options. This sets up the container for server-side tagging.
  4. Configure Your Server Environment:
    • Once the container is created, GTM will prompt you to set up the server environment.
    • You can choose to use Google Cloud (via App Engine) or set up your own server (e.g., using Google Cloud Compute Engine, AWS EC2, or any server provider you prefer).
  5. Set Up Server Environment in Google Cloud:
    • Google Cloud is the easiest option, as GTM offers a one-click deployment for this option. Follow the instructions provided by GTM to deploy the container to Google Cloud App Engine.
    • Click Deploy on the GTM interface to automatically set up the App Engine instance.
    • After deployment, you’ll be given a URL for your server container (e.g., your-container-id.server.com).
  6. Configure DNS (Optional): You can configure a custom domain for your server-side GTM instance (e.g., tagmanager.yourdomain.com). This step requires setting up DNS records and may involve more advanced configurations depending on your domain provider.

Step 2: Set Up Client-Side GTM Container for Data Collection

Now that the server container is set up, you’ll need to configure the client-side GTM container to send data to your server container.

  1. Install GTM on Your Website: If you haven’t already, set up the GTM web container on your website. This involves adding the GTM container code to your website’s <head> and <body> sections.
  2. Create Tags in the Web Container: In the web container, create tags that send data to the server container. For example, you can set up Google Analytics or other tracking tags in your web container, but instead of sending data directly to Google Analytics, you’ll send the data to your server-side container.

Step 3: Set Up Server-Side Tags in the Server Container

Once the server container is deployed and the client-side container is sending data to it, you can begin setting up server-side tags to process that data.

  1. Go to Your Server Container: In GTM, go to the Server container that you deployed to Google Cloud (or your preferred server environment).
  2. Create Tags: You can now create tags in your server container, similar to how you would create them in a client-side container. Some popular tags to configure in a server-side container include:
    • Google Analytics 4 (GA4): For sending data to GA4 via the server.
    • Google Ads: To send conversion tracking data to Google Ads from the server.
    • Facebook Pixel: For sending data to Facebook Ads from the server.
  3. Set Up Client-Side Tag Forwarding: For most services (like Google Analytics), you need to set up forwarding of data from the client-side GTM container to your server container. In the client-side container, set the URL endpoint of your server container as the tag destination.
  4. Configure Server-Side Tags to Process Data: Each tag you create in the server container can have a custom set of parameters for processing. For example:
    • Google Analytics: Configure your server container to forward data to Google Analytics servers.
    • Facebook Pixel: Set up the server to pass data in a format that Facebook accepts.

Step 4: Configure the Server-Side GTM Client

In server-side GTM, you can use a client to capture incoming requests from your website or other sources (such as app events). The client receives data and forwards it to the appropriate tags for processing.

  1. Create a Client: In the server container, go to the Clients section and add a new client. For example:
    • Google Analytics Client: This client listens for events from the client-side container and formats them to be sent to Google Analytics servers.
    • Custom Clients: You can create custom clients to handle specialized data formats or API integrations.
  2. Set Up Client Triggers: Configure triggers in the server container that determine when the server should process data. For example, you might set triggers based on the URL path or event type sent from the client container.

Step 5: Test the Configuration

Before going live with server-side tagging, it’s crucial to thoroughly test the setup:

  1. Preview Mode in GTM: Just like with client-side tagging, GTM allows you to use Preview Mode to test your server-side container.
    • Enable Preview Mode in the server container and use the Server Preview Link to monitor the tags in action.
  2. Use the Network Tab: Use your browser’s developer tools (network tab) to monitor the requests and verify that data is sent to the correct endpoints (server-side container).
  3. Validate Tag Firing: In the GTM interface, validate whether tags are firing correctly in the server container. Check for any errors in tag configurations or missing data.

Step 6: Go Live

Once testing is complete and you are satisfied with the performance and functionality, you can publish your server-side container to make it live.

  1. Publish the Container: After thorough testing, click Submit in the GTM interface to publish your server-side container to production.
  2. Monitor Performance: After going live, continue to monitor performance using GTM’s built-in debugging tools and your browser’s developer tools. Ensure that tags are firing correctly and data is being sent to the correct destinations.

Benefits of Server-Side Tagging

  • Improved Website Performance: Reduces the amount of JavaScript running on the client side, leading to faster page loads.
  • Better Data Privacy: Data processing happens server-side, reducing exposure to malicious browser extensions or ad blockers.
  • Enhanced Security: Protects sensitive data and ensures that it is passed securely between services.
  • More Control: You have full control over which data is sent to third-party platforms, improving data accuracy and reducing tracking issues.
  • Reduced Risk of Ad Blockers: Since tracking happens server-side, ad blockers cannot interfere with tracking.

Conclusion

Server-side tagging with Google Tag Manager provides significant advantages for website performance, privacy, and control over data. Setting it up involves configuring both the server-side and client-side containers in GTM, deploying the server to a hosting platform (such as Google Cloud), and configuring tags and clients to process incoming data. With careful configuration and testing, server-side tagging can greatly enhance the efficiency of your tag management system.