Stape

How to create data layer for server-side Google Tag Manager

Updated
Oct 24, 2022
Published
Oct 23, 2021
Also available in

Browser tracking protection mechanisms are getting more robust, 3rd party cookies are blocked by some browsers, Chrome plans to phase out 3rd party cookies by 2022, Apple implemented their tracking restrictions for iOS users. All these changes affected web analytics. 

We used to consider website tracking a front-end thing, but web tracking is getting more challenging with all the new restrictions. Some say that server-side tracking will become a new standard. 

One of the easiest and cheapest ways to implement ss tagging is using server Google Tag Manager. After you set up sGTM hosting, the next question would be how to deliver data to the server-side GTM. Do you need to create a data layer similar to the web container, or is there another way?  

In this blog post, I want to discuss creating a data layer for the server-side Google Tag Manager.

Data layer and data sources for the web Google Tag ManagerCopy link to this section

In the web Google Tag Manager data is collected from the client-side. You use the DOM elements or scrape data from the site using CSS selectors. But in some cases, these methods can be unstable.

The golden rule of web GTM tracking is building a reliable data layer. Creating a proper data layer structure and implementing it on the website takes some time, not only for marketers but also for developers. But it’s worth the time. With the data layer, you get more data, and this data is reliable.

How can you send data to server-side Google Tag Manager?Copy link to this section

There is a new object added to the server-side GTM; it’s called Client. The Client’s primary purpose is to transform request data into the event data inside the server GTM. 

How does the Client understand what request to claim and process? It checks the request’s path. For example, Universal analytics sends requests that contain /collect. The Client reviews the incoming HTTP requests path, and if the request path has its “key”, the Client transforms request data to the event data in the sGTM.

Another essential purpose of sGTM Clients is to handle outgoing HTTP requests. Once the tag is triggered in the sGTM, the Client sends an outgoing HTTP request to summarize all requests sent by each tag. If there was an error with the tag, you would see the reason for the error if you click on the outgoing HTTP request and scroll down to the response body. 

Let me show an example. I will use Data Tag/Data Client for it. In the web GTM container, I configured a Data Tag that sends requests to the server container. 

add transport URL Data Tag

Data Tag requests path contains /data.

request path data tag

In the sGTM, I have a Data Client that listens to all requests that have /data in the Incoming HTTP request. 

set up data client accepted path

There are two tags (GA4 and Klaviyo active on-site) in the server GTM that triggers whenever Data Client is claimed, and the event name is page_vew. Let’s see what happens in the server GTM when it receives an incoming request with /data and event name page_view. Both tags are triggered, and the Data Client sends an outgoing HTTP request. 

tag triggered in the sGTM container
outgoing http request

If you click on the Incoming HTTP requests, you will see what data was sent to the server container. If you click on the Outgoing HTTP request, you will see what information Data Client sent about the execution of the triggered tags. 

When you click on the event data, you will see what information from the incoming HTTP requests Data Client mapped to the event data. 

event data server google tag manager

Data layer for server-side Google Tag ManagerCopy link to this section

Data Layer does not exist in the server Google Tag Manager in a way we used to have it in the web Google Tag Manager. You will usually build tags in the sGTM based on the event data and the requested data. 

Most likely, we won’t be able to switch to server-side tracking only for the next couple of years. In the meantime, a hybrid approach will be used – combining web and server tracking. Some tags will still run on the client-side (either because platforms do not support ss tracking yet, or simply because it can’t be moved to the ss, it relates to tools like HotJar), and other tags will be set up on the server-side. There will be one Tag/Client responsible for sending specific data or the whole data layer from the web to the server GTM container. 

The scheme below shows how the process of delivering data to the sGTM works. Web GTM has a data layer, UA, and FB pixel use web tracking. Then we have a GA4 server-side tag that is responsible for delivering data from web to server GTM. Based on the data GA4 tag provided to sGTM, we can set up ss Adwords and FB CAPI tags in the server GTM. 

combining web and server google tag manage tagging

How to create data layer for server-side Google Tag ManagerCopy link to this section

For me, the two most frequently used methods of sending data from web to server GTM are:

  • Using Google Analytics 4
  • Using Data Tag/Data Client

1. Send data layer to server GTM using Google Analytics 4.

You can send User Properties and Event Parameters from the web to server GTM using GA4. Inside the web GA4 tag, you will see predefined fields for this data, and you can add data layer variables to each parameter individually. 

send data to Server GTM using GA4

Google Analytics 4 and UA have different eCommerce data layer standards (UA data layerGA4 data layer). So if you have an ee data layer on the site built for UA, make sure you modify it for GA4. The good thing is that you can use variables in the GTM template gallery that convert UA events and variables to the GA4 standards. 

This option works best if you plan to set up server-side tracking for Google Ads or Floodlight since these two work only based on GA4 tags.

2. Use Data Tag/Data Client to send data layer from web to server GTM.

The most significant benefit of using Data Tag/Data Client is that DT automatically sends data layer and other common data from web to server GTM. If you enable two checkboxes, Send common data and Send all from DataLayer, it will parse data in the web GTM and send all information it could find to the server GTM. No need to configure each parameter manually.

send data to Server GTM using Data Tag Data Client

This is how you will see eCommerce data in the sGTM. You can use the event data variable to extract it and use it for server tags, and I have a more detailed post that describes Data Tag/Data Client.  

data tag event data in the server container 

Conclusion:Copy link to this section

Server GTM container does not have something similar to the data layer we used in the web container. But there are several ways of passing event and user parameters or event the whole data layer from the web to server Google Tag Manager.

Something's not clear? We're here for you!

All it takes is a few simple questions. Click Get A Quote, fill up the form, and we will send you a quote.

Get A Quote
Tagged with:gtm server

Host your GTM server at Stape