Stape
Search

Server-to-server tracking in server Google Tag Manager

Updated
May 14, 2024
Published
Jan 11, 2024

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

The most common tool to integrate server-side tracking is the server Google Tag Manager container. There are two ways of integrating server-side tracking using sGTM: 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

Hybrid method or web+server

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. 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.
  • Ss GA4 is required if you want to set up ss Google Ads.

Disadvantages of using ss 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, bypassing the client or user's browser. 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 deliver data to sGTM is through webhooks, which can be sent from CRM or CMS. 

The benefits of a pure server-to-server tracking

  1. Reliability: This method is more reliable and secure, as it is 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 a higher amount of even data than web events, which gives the advertising network more parameters for conversion attrition.
  4. Improved 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.

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 with the help of the sGTM preview header powered up 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 allows sending events from apps to stape Data Client

How to process server data in sGTM

In this example, I will use the WordPress Stape plugin to send server data to sGTM. The debugging and retrieving of 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. Install Wordpress Plugin.

2. 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.
disable web GTM script insertion in wordpress app from 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. 
webhooks tab in wordpress app from 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 Google Tag Manager container and enable the preview
  • Copy X-Gtm-Server-Preview HTTP header.
Copy X-Gtm-Server-Preview HTTP header

5. Go to your stape.io account and open the container for configuring server events.

  • Click Power-Ups tab
  • Click Use HTTP header config
Use HTTP header config from stape
  • Paste X-Gtm-Server-Preview HTTP header you’ve copied from sGTM preview. 
X-Gtm-Server-Preview HTTP header

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.
add Data Client to sGTM container
  • Click three dots in the top right corner. 
  • Select Import and choose the data client template you’ve recently downloaded from GitHub.
choose the data client template you’ve recently downloaded from GitHub

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 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.
Configure Data Client in sGTM

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 that was parsed by the data client from the webhook. 

sGTM preview mode and test that the webhook

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

Conclusion:

Server-to-server tracking has unbeatable advantages over web+server tracking, such as better accuracy and higher security standards. But in some cases, like server Google Ads tracking, setting up pure s2s integration is impossible because 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 webhook data and retrieving webhook data in sGTM. Using the HTTP Preview header and Stape’s Data Client are helpful for these. 

As we move towards a more privacy-conscious world, the methods and tools we use for tracking and analytics must evolve. Server-to-server tracking with sGTM 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, webmaster, 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 in the digital game ensuring your analytics are insightful, compliant, and future-proof.

Tagged with:gtm server

Host your GTM server at Stape