Stape
Search
Try for free

Server-to-server tracking in server Google Tag Manager

Updated
Sep 30, 2024
Published
Jan 11, 2024

Server-to-server tracking is a method that more and more businesses use to understand better what users do on different websites or improve their advertising. It's different from older ways of tracking because it allows you to collect data more accurately, follows privacy rules better, and doesn't depend as much on third-party cookies and web scripts that web browsers can block.

The Google Tag Manager server container is the most common tool for integrating server-side tracking. sGTM has two ways of integrating server-side tracking: web+server (the most popular one) and server-to-server.

This blog post delves into server-to-server tracking using Google Tag Manager's server container capabilities. We'll explore how it works, its benefits, and how you can implement it to gain deeper insights into your analytics while maintaining user privacy and data integrity.

Types of server-side tracking via GTM

Hybrid method or web + server GTM container

This method is the most popular one. With the hybrid method, you use a web GTM container to deliver data to the server GTM container. Configuring Google Tag Manager server-side involves setting up the server using Google Cloud Run, sending data to the SGTM container, and establishing a custom domain for better tracking in a first-party context. The two most popular ways to deliver data from the web to server GTM are server-side GA4 or Data Tag/Data Client.

Benefits of using server-side GA4 for sending data from web to server GTM: 

  • There is no additional configuration. If you are migrating to server-side tagging, you already have or will implement ss GA4.
  • Server-side GA4 is required if you want to set up server-side Google Ads.

Disadvantages of using server-side GA4: 

  • Ad Blockers block GA4 requests (/collect) requests. But this is not an issue if you use Stape’s Custom loader power-up that makes GTM and GA4 scripts invisible to ad blockers.
  • GA4 constantly changes and adds new parameters to its requests, so it will take a lot of work to control which data GA4 collects. 

Pure server-to-server tracking

Server-to-server tracking is a data collection method that sends information directly from one server to another. Data collected in this way bypasses the client-side or user’s browser. 

Implementing a server-side tagging setup in Google Tag Manager (GTM) can improve data accuracy and website performance by reducing the client load and minimizing third-party JavaScript execution in the user's browser. However, S2S tracking is more challenging to set up than web+server. 

The fundamental difficulty of s2s tracking in sGTM lies in delivering and debugging data to sGTM. The most popular way to provide data to sGTM is through webhooks, which can be sent from CRM or CMS.

The benefits of a pure server-to-server tagging setup

  1. Reliability. This method is more reliable and secure and less susceptible to issues like browser restrictions, ad blockers, or cookie consent requirements. It can also handle larger volumes of data more efficiently and provides a more accurate tracking mechanism, especially for complex user journeys or offline events.
  2. Track offline events. Webhooks enable the capture of offline interactions like store sales or phone orders, integrating this data with online platforms.
  3. Accurate conversion attribution. Webhooks include more even data than web events, giving the advertising network more parameters for conversion attrition.
  4. Improves data security. Server-side tagging with webhooks offers a more secure way to handle data, which is particularly important for customer privacy and compliance with data regulations.

How to set up server-to-server tracking

Create a server container in Google Tag Manager

  1. Select your GTM account → Click Admin → Click + next to the Container name.
Server-to-server tracking in server Google Tag Manager - Stape

2. Add Container Name → Under Target platform, choose Server. Click Create.

Server-to-server tracking in server Google Tag Manager - Stape

3. Choose Manually provision tagging server. Copy your container config. We will need it in the following steps.

Server-to-server tracking in server Google Tag Manager - Stape

Create a Stape account to host your server GTM container

1. Go to stape.io and create an account or log in. You can try our service for free and explore the benefits of Stape hosting for the GTM server.

Server-to-server tracking in server Google Tag Manager - Stape

2. Press the button Create container in the top right corner.

3. Enter your container details:

  • Container name. The name does not necessarily have to be the same as the container name in your server GTM.
  • Container configuration. Paste the Container Config you copied from your Google Tag Manager Server Container.
  • Server location. Select your server location based on the location of most of your clients. The location can not be changed later.
Server-to-server tracking in server Google Tag Manager - Stape

4. Choose a plan for your container. You can start with a Free plan. Click Continue with a Free plan.

Server-to-server tracking in server Google Tag Manager - Stape

You will see the status of your container, container config, and plan name. It takes around five minutes to deploy a server container. Please reload the page to update the status. If the setup was done correctly, you should see the status “Running.”

Server-to-server tracking in server Google Tag Manager - Stape

Configure tags, triggers, and variables

Once your server container is ready, you configure tags to send data, triggers to determine when those tags should fire, and variables to store the dynamic information your tags and triggers rely on. For example, tags might send purchase data to Google Analytics, triggers would control when that happens, and variables could capture user session details from requests. This setup allows you to manage data collection with precision and flexibility.

Note: Setting up a server container requires technical expertise and familiarity with Google Cloud Platform and Google Tag Manager. If uncomfortable with these tools, consider seeking professional assistance to ensure a smooth server-side setup process.

By following these steps, you can successfully set up a server container in Google Tag Manager, enabling you to leverage the full benefits of server-side tagging.

This server-side setup will help you collect accurate data, improve website performance, and enhance user privacy, ensuring your analytics strategy is effective and compliant with modern standards.

Ways of sending server data to sGTM

CRM

Using webhooks from CRM to sGTM can provide valuable insights about offline sales. Configuring webhooks is easy in sGTM, thanks to the sGTM preview header powered by Stape.

Payment processors (Stripe, Paypal, etc.)

Using webhooks from payment processors is another popular way of delivering data to sGTM. It can be beneficial if you want to track recurring orders, upsells, or refunds in sGTM.

CMS (Shopify, WordPress, Magento)

With the help of Stape’s Shopify App, Magento extension, and WordPress plugin, sending server data from these CMS to sGTM is easy. I will show you how to set it up later in this blog post.

Stape SDK

Stape iOS, Android, PHP, and Node.js SDK allow sending events from apps to the Stape Data Client.

How to process server data in the Google Tag Manager server

In this example, I will use the WordPress Stape plugin to send server data to sGTM. The debugging and retrieving data in sGTM will be identical for all ways of delivering data to sGTM. So, it does not matter how you send data. The steps of debugging and retrieving data will be the same for you.

  1. Open the General tab of the plugin settings and check that the following:
  • You chose to disable web GTM script insertion since, for pure s2s tracking, you do not need web GTM. 
  • Other settings on the General tab should not have any configurations.
Server-to-server tracking in server Google Tag Manager - Stape

3. Go to the Webhooks tab:

  • Enable the checkbox Send webhooks to server GTM container.
  • Add Server GTM container URL. You can find it in the Stape account following this guide.
  • Enable the checkbox in front of the webhooks you want to send.
Server-to-server tracking in server Google Tag Manager - Stape

4. Open the server Google Tag Manager container and enable the preview.

  • Click on the three dots in the top right corner. 
  • Select Send requests manually.
Server-to-server tracking in server Google Tag Manager - Stape
  • Copy X-Gtm-Server-Preview HTTP header.
Server-to-server tracking in server Google Tag Manager - Stape

5. Go to your Stape.io account and open the container to configure server events.

  • Click Power-Ups tab
  • Click Use sGTM Preview header config
Server-to-server tracking in server Google Tag Manager - Stape
  • Paste the X-Gtm-Server-Preview HTTP header you’ve copied from the sGTM preview.
Server-to-server tracking in server Google Tag Manager - Stape

6. Add Data Client to sGTM container.

  • Download the Data Client template from GitHub. We will use Data Client to process webhooks in sGTM.
  • Go to the templates section in sGTM.
  • In sGTM, click the new client.
Server-to-server tracking in server Google Tag Manager - Stape
  • Click three dots in the top right corner. 
  • Select Import and choose the data client template you’ve recently downloaded from GitHub.
Server-to-server tracking in server Google Tag Manager - Stape

7. Configure Data Client in sGTM.

  • Go to the Clients section.
  • Click New.
  • Select client type Data Client.
  • Click Accepted Path Settings.
  • Add /order if you want to send order webhooks from the WP plugin and /refund if you want to send refund webhooks. If you use any other tool for sending webhooks to sGTM, this tool should have the option to configure a webhook URL. This URL should consist of your tagging server URL (in my case, https://ss.wp-demo.stape.dev/) and the path of the webhook (in my case,/order). In the data client setting, you only need to add a path; do not add the whole URL.
Server-to-server tracking in server Google Tag Manager - Stape

8. Open sGTM preview mode and test that the webhook was processed successfully. I’ve made a test purchase on the site, and in the sGTM debugger, I can see /order requests that the Data client claims. If you go to the Event Data in the sGTM debugger, you should see all the information from the webhook that the data client parsed.

Server-to-server tracking in server Google Tag Manager - Stape

9. Now, when you’ve successfully processed webhook data in sGTM, the setup is similar to any other setup in sGTM. You can use this data to transfer to whatever server tag you want.

Conclusion: ensuring data quality

Server-to-server tracking has unbeatable advantages over web+server tracking, such as better accuracy and higher security standards. However, in some cases, like Google Ads tracking, setting up pure s2s integration is impossible because the native server Google Ads requires using Google Analytics 4 requests, which works in a hybrid method. However, you can combine web+server and s2s tracking by implementing Google Ads offline conversions

In this guide, I’ve outlined several ways of sending server data to sGTM and showed an example of configuring s2s tracking in sGTM with the help of the GTM server-side plugin by Stape. When setting up pure s2s tracking inside sGTM, the most tricky part is debugging and retrieving webhook data in sGTM. Using the HTTP Preview header and Stape’s Data Client is helpful. 

As we move towards a more privacy-conscious world, the methods and tools we use for tracking and analytics must evolve. sGTM server-side tagging (GTM server container) is at the forefront of this evolution, providing businesses with the tools to make informed decisions based on comprehensive, reliable data.

Whether you're a marketer, web admin, or developer, the insights provided in this post should guide you in making an informed decision about integrating server-to-server tracking into your analytics strategy. Embracing this technology means staying ahead with your Google Analytics data quality, insightful, compliant, and future-proof.

Tagged with:gtm server

Host your GTM server at Staperight now!