Stape
Search
Try for free

Sending data from the Google Tag Manager web container to the server container

Updated
Nov 27, 2024
Published
Apr 1, 2021
Also available in

Having reliable data in the server Google Tag Manager is a key to accurate server-side tagging. One of the most popular ways to send data from web to server GTM is Google Analytics 4. GA4 has its limitations. That is why we created Data Tag and Data Client that should work together to deliver event and user data from web to server GTM.

In this article, I want to show you how to use Data Tag. This custom tag sends parameters from the Google Tag Manager Web Container to the Server Container. When used together with the Data Client for the Google Tag Manager server container, it allows sending data layer variables, custom parameters, and other data from the web to the server container. As a result, Data Client retrieves information from the Data Tag into the Google Tag Manager Server Events.

How to send data from the Google Tag Manager web to the server container

1. Open your Web Google Tag Manager container Templates section and add Data Tag from the template gallery.

2. Open Tags section and click New and configure the Data Tag.

configure the Data Tag

3. Configure Data tag for the pageview event:

a. Select the event name. You can either select a standard event name, add a custom event name, or add a dynamic event name using {{Event}} variable. 

b. Add GTM Server Side URL and click Save. You can find your GTM server-side URL inside the stape.io account by opening the sGTM container and checking the Domain section.

c. Send all from the DataLayer will send all the information you have in the web GTM data layer to server GTM events data. 

d. Send common data. Adds to request page_location, page_path, page_hostname, page_referrer, page_title, page_encoding, screen_resolution, viewport_size

e. Add consent state. Adds consent_state object to the request. Including following properties: ad_storage, analytics_storage, functionality_storage, personalization_storage, security_storage.

f. Event Data. Allows adding any manual data to the request. You can also apply transformation (like hashing, trimming, etc) or store data.

g. User data. Allows sending user parameters and apply transformation or store data.

data tag configuration - stape

4. Configure Data tag for other events. The example below shows how to configure e-commerce events when Data Layer is available. 

data tag configuration - stape

This tag triggers each e-commerce event in the Data Layer. Since all my e-commerce events end with _stape, I’m using a regex that includes all events that contain _stape. 

triggers each e-commerce event in the Data Layer

Example of the variable that extracts user data from the Data Layer. 

Example of the variable that extracts user data from the Data Layer. 
Download Data Client from the GitHub

6. Open your Server Google Tag Manager container.

Go to Templates tab →  Click New under the Clients section. 

Go to Templates tab →  Click New under the Clients section. 

7. Click three dots on the top right corner Import Data Client (downloaded from GitHub) → Click Save. 

three dots on the top right corner → Import Data Client

8. Go to the Clients tab and click New. Choose Data Client. Click Save

Import Data Client

9. Open web and server GTM debuggers and test the set up. You should see Data Tag triggered in the web GTM container and Data Client parsed Data Tag requests in the sGTM. 

web and server GTM debuggers
web and server GTM debuggers

Data Tag use cases

1. Data layer from the web to the server container.

The first use case that comes to mind is sending a data layer from the web container to the server. With the help of this data, you can feed additional parameters to your server-side tags.

On the screenshot below, I used these settings to send the data layer to the server container: 

  • Custom event: {{event}}
  • Enabled send all from data layer
  • Enabled send common data

This data tag fires on all enhanced e-commerce events.

send data from web gtm to Server GTM 

In the server container preview mode, you will see that Data Tag sent requests on all e-commerce events, and Data Client received and processed these requests inside the server container. If I click on the event name and check event_data, you should see all the parameters from the web data layer.

2. Sending User Data to Facebook Conversion API.

Let’s say that you want to send user data like the first name, last name, or email to Facebook Conversion API to increase your event match quality. You can use Data Tag for that. And if you are using our tag to set up a Facebook conversion API tag, the FB tag will automatically capture user data from the Data Tag. 

I wanted to send the user email, first name, and last name together with the checkout events in the examples below. I added the user data to the Data Tag on the Web Google Tag Manager container. I’m using static parameters for the test, but you can pass these parameters dynamically using variables. Our Facebook tag automatically captures user parameters from the Data Client and sends hashed information to Facebook.

send user data from web to Server GTM

To double-check if Facebook received these parameters, you can add Facebook test ID to the Facebook server tag and check which parameters Facebook sees in the events manager testing tool.

3. Send custom data from the Web container to any other servers.

You can send data from the Google Tag Manager web container to your CRM, Slack, webhooks, etc. This example shows you how to send information about a new purchase on your site to the Slack channel. 

    1. Make sure that you send the correct information from the Google Tag Manager web container using Data Tag. 

    3. Inside the server container, create a new tag and choose a tag type HTTP Request. 

    4. In the destination URL, add the URL that you’ve generated on Slack. 

    5. HTTP method POST.

    6. In the Request body, add text and parameters that you want to send to Slack. 

{“text”: “New Purchase \n email: {{email}}  \n transation_id: {{transaction ID}} \n purchase_value: {{transaction ID}}”}

4. Store data.

If you work with Google Tag Manager quite often, then there has been a time when the data layer (or any other variable) had to be passed on from one page of your site to another.

Unfortunately, Google Tag Manager doesn’t have an option to store data and pass it between site pages. For example, it’s possible to send a user email only when it exists on the page. But what if user data is not available on the thank you page, and it can be captured only from the page before the thank you page?

Using a data tag, you can store any variables you want to pass to other pages.

As an example, I will use an assessment built with Instapage. We needed to set up a lead event for the Facebook conversion API. While submitting the assessment, the user had to enter details like email, phone number, first name, etc. This user information was available on the assessment pages but not on the thank you page.

To have a high event match quality score on Facebook, you should send user parameters together with the CAPI event. That is why I used Data Tag to store user data in the local storage. I created a Submit application Data tag that takes user parameters from the data layer and stores them in the Local Storage. This tag triggers when a user clicks on the submit assessment button.

To enable data storing in the Data Tag, select the storing option next to the data you want to store.

store user data in cookies web google tag manager

Then, I added a new variable type in the web container (you can download it using this link.) Create new variables for all data that you stored.

And finally, I created a Lead Data Tag that sends stored data to the server container.

5. Retrieve any incoming request.

You can use Data Client to retrieve any incoming requests. To do that, you need to modify Path Settings. It can be used, for example, to retrieve data from Webhooks. We have this article that describes how to use incoming webhooks.

prices incoming requests in the server container

If you can’t see Data Tag requests inside the server container, it might be because of the following reason: Data Client is not published. Open Server container and publish Data Client.

Conclusion

Data Tag and Data Client will give a solid source of information to feed into the tags you use inside the server container. With the help of this tag, you can move faster in the deployment of new server-side tracking and technologies. This tag will save time and cost for both IT and marketing – a clear win-win!

Tagged with:gtm server

Try Stape for all things server-sideright now!