Google Tag Manager (GTM) server-side tagging is a powerful tool that enables you to manage and forward data from your website or application to various analytics and marketing platforms through an intermediary server. It enhances data collection reliability, particularly in the face of increasing browser restrictions on third-party cookies. Let’s go through all the steps you need to take to implement server-side GTM for the best results.
Step 1: Create a GTM Server Container
To begin, you need to create a new server-side container in your Google Tag Manager account. This is where you will configure and manage your server-side tags.
- Log in to your GTM account and navigate to the Admin section.
- Click on the ellipsis (three dots) or the + sign under the Container tab.
- Select Create Container and choose Server as the container type.
- Provide a name for your container and click Create.
Step 2: Provision Your Tagging Server
You have two options to provision your tagging server: automatic or manual. Let’s look at both of them.
Automatic Provisioning
Automatic provisioning is the simplest way to set up your server. There are a few downsides to this setup though, namely that it cannot handle large traffic volumes and its automatically located in the US. This last point can be a downside when your users are located elsewhere.
Still for smaller organisations and testing it can be usefull. You can set it up as follows:
- Select Automatically provision tagging server when creating your container. This will set up your server on the Google Cloud Platform (GCP).
- Choose or create a billing account. If you don’t have one, you can create a new billing account from this menu. Note that you will need to enter your credit card details, but you may be eligible for a free tier if you are just testing.
- Follow the prompts to complete the setup. Google Cloud will handle the server configuration, which may take a few minutes.
Manual Provisioning
If you prefer more control over your server setup or need to host it on a different platform like Stape or Taggrs, you can opt for manual provisioning:
- Select Manually provision tagging server when creating your container.
- This option requires you to set up and configure your own server environment, which could be on Google Cloud, AWS, Azure, or any other cloud provider.
- You will need to ensure that your server meets the necessary requirements for running GTM server-side tagging, including the correct runtime environment and network configurations.
If you would like to learn more about alternatives to Cloud Run like Stape or Taggrs you can read our comparison article.
Step 3: Connect Billing Account and Set Up Server
If you chose automatic provisioning, you will need to connect a billing account to cover any costs associated with running your server.
- Select your billing account from the list or create a new one if you don’t have an existing one.
- Follow the prompts to add your billing information, including a credit card.
- Once the billing account is set up, click Select Billing Account and Create Server. Google Cloud will then set up your server, which may take a few minutes.
Step 4: Configure Your Server
After the server is provisioned, you will see a window with your server details, including the container configuration, Google Cloud Platform project ID, and the default URL.
Viewing Server Details
- Click on the Google Cloud Platform project ID to go to the project dashboard in GCP.
- In the GCP project, navigate to Cloud Run to view your primary and preview servers. Here, you can manage the scaling, security, and other settings of your server.
Custom Domain Setup
Mapping a custom domain to your server is crucial for ensuring that cookies are considered first-party and not blocked by browsers. Here’s how you can set it up:
- Go to your Google Cloud project and search for Cloud Run.
- Enable the necessary APIs and set up the A records with your hosting provider.
- Add the custom domain in your GTM server container settings. This will replace the default URL provided by Google.
Step 5: Set Up Data Forwarding
Data forwarding is the core function of GTM server-side tagging. You need to configure your setup to send data from your website or application to the GTM server container and then to the desired analytics or marketing platforms.
From Your Website or App to the GTM Server Container
To send data from your website or app to the GTM server container, you typically need to set up a client in your GTM server container that processes requests from your web container. Here’s a general approach:
- In your web container, create a tag that sends data to your GTM server container using the sendBeacon method or an HTTP request.
- In your GTM server container, create a client that listens for these requests and processes the data accordingly.
From GTM Server to Vendor’s Platform
Once the data is received by the GTM server container, you need to forward it to the desired platforms. Here’s how you can do it:
- Go to Tags in your GTM server container and create a new tag.
- Select the appropriate platform (e.g., Google Analytics 4) and configure the tag settings.
- Set up triggers and variables as necessary. For example, you might set up a trigger based on a custom event or a built-in variable.
- Ensure that the tag is configured to send data to the correct endpoint for the vendor’s platform.
Step 6: Test and Publish
Testing is a critical step to ensure that your setup is working correctly. Do not publish any changes before doing this as it can cause downtime for all your current tracking and mess up advertising campaigns.
Using Preview Mode
Use the GTM preview mode to test your setup. Open the preview mode in both the server and web containers to ensure data is being sent correctly.
Verify that the data is being received by the GTM server container and forwarded to the intended platforms.
Health Check
Test the health of your tagging server by appending /healthy to your tagging server URL. You should see an “OK” response if everything is working correctly.
Step 7: Scale Your Server (Optional)
If you anticipate high traffic, you may need to scale your server to handle the load.
- Go to the Cloud Run section in your GCP project.
- Edit the revision settings to enable autoscaling. Set the minimum and maximum number of instances according to your needs.
- You can also configure other scaling settings, such as CPU and memory limits, to ensure optimal performance.
Conclusion
Setting up GTM server-side tagging involves several key steps, but it offers significant benefits in terms of data reliability and compliance with browser restrictions. Here’s a quick summary:
- Create a GTM server container
- Provision your tagging server (automatic or manual)
- Connect your billing account and set up the server
- Configure your server and set up a custom domain
- Set up data forwarding from your website/app to the GTM server and to the vendor’s platform
- Test and publish your setup
- Scale your server if necessary
By following these steps, you can ensure a smooth transition to server-side tagging and maintain accurate and reliable data collection for your analytics and marketing needs.
If you have further questions about the process or what to learn more about advanced topics, feel free to contact us.