Google Tag Manager - Server-side Tagging

Gain full control over analytics data with server-side tagging for enhanced privacy and faster performance. Learn more

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

Google Tag Manager also supports a deployment method that enables data oversight, management, and distribution through server-side tagging, in addition to the standard (client) installation.

Until now, our approach in web analytics has primarily focused on client (client) side activities occurring on a website or application. However, as data privacy and performance optimization processes related to websites and applications have emerged—driven by evolving requirements such as data pre-processing—the need for significant innovations and changes in user activity monitoring and tag management has become evident1 2 3. Among these, the most significant development was the introduction of server-side tagging by Google Tag Manager. Fundamentally, server-side tagging is treated as a container (container) type4.

What is Server-Side Tagging?

Server-side tagging refers to the process of transferring measurement (measurement) tags from a website or application to another platform where they are processed. This platform can be pre-defined as Google Cloud Platform (GCP), or alternatively, a customized service provider may be used5. Server-side tagging offers several advantages over client-side tagging:

  • Fewer measurement tags are present on the website or application. This translates to less code being executed on the client side.
  • Visitor data is better protected since it is collected and distributed within a server-side environment managed by the customer (customer-managed). The data is then managed in the cloud, with controls in place to ensure it is processed and made available to other service providers as needed.

Most of the operations will still be carried out via the Google Tag Manager dashboard. Additionally, I will be using GCP for server-side operations.

Server-side Tagging / Server-side Tagging
Server-side Tagging / Server-side Tagging

First, we’ll need to create a new container (container). The fields defined for the container will be the same as those for the client (account and container name, country, etc.). However, the container type must be set to Server (server)6.

Server-side Tagging / Server-side Tagging
Server-side Tagging / Server-side Tagging

After confirming the relevant details, you will be presented with an option to proceed either automatically or through a manual, step-by-step process5 7. The Automatic option will direct you to a window where you select your payment method associated with GCP.

Server-side Tagging / Server-side Tagging
Server-side Tagging / Server-side Tagging

If a payment method is defined, you can select the relevant payment method or define a new one8. This process may take several minutes, or up to several hours, as it may require verification of your personal information9.

GTM - Tagging Server
GTM - Tagging Server

The server-side container retrieves data via the transport_url10.

Directly, if operations are to be carried out via the GTAG, the URL and GA4 ID (see <DOMAIN NAME> and G-XXXXXX) must be updated within the code snippet. Subsequently, I will discuss how data is passed between containers via the GTM. However, this is certainly not the only method. On the server side, a container can be configured with the following basic GTAG code snippet, in addition to the measurement protocol, using customized methods 3.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://<DOMAIN NAME>/gtag/js?id=<G-XXXXXX>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-XXXXXX', {
  transport_url: '<DOMAIN NAME>'
});
</script>

Of course, the same applies to the GTM code snippet.

<head>
    <!-- Google Tag Manager -->
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://<DOMAIN NAME>/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
    <!-- End Google Tag Manager -->
</head>
<body>
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="<DOMAIN NAME>/ns.html?id=GTM-XXXXXX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->
</body>
note

After the server-side container setup, instead of the domain name sent as the Default URL (*.appspot.com), it is more appropriate for you to select a subdomain of your own by configuring the DNS settings for the domain name.

Tag Installations

The following steps involve configurations performed via the GTM client and server sides. The specified steps may exhibit minor variations depending on updates and enhancements made by the GTM side 3.

Let’s start with the GA4 installation.

Google Analytics: GA4

First, open the client-side container in one tab and the server-side container in another.

Within the client-side container, if you’ve previously installed it, select the GA4 configuration tag from the Tags section; if not, you can select it via the Tags section. Simply enable the Send to server container option and enter the URL of the server-side container in the URL field. After this, data will begin to be sent to the server-side container via GA4. Now, we proceed to set up the tag that will receive these data.

GTM - GA4 Tag
GTM - GA4 Tag

Open the server-side container and enable the GA4 client under the Clients section. Now, we can process data coming from the client-side container to the server-side container via GA4.

Therefore, we can create our GA4 tag under the Tags section.

GTM - Tagging Server
GTM - Tagging Server

For the trigger, we can assign the value GA4 to the Client Name field to respond to requests received via the GA4 client.

GTM - Tagging Server
GTM - Tagging Server

After this, we will be able to process data received via GA4 on the client side through the corresponding tag on the server side.

Google Analytics: UA

For the Universal Analytics (UA) installation, we will follow similar steps, albeit with a few additional steps.

First, we’ll carry out our initial step on the web container running on the client side. We’ll open the configuration settings for the UA tag and paste the transport_url value we obtained for the server-side container into the Transport URL field under Advanced Configuration.

UA - Client-side Tagging
UA - Client-side Tagging

After this, we’ll be able to access all data associated with UA through the server-side container. Now, we can set up a tag linked to UA data within the server-side container.

As before, we’ll need to activate the relevant client; Google Analytics: Universal Analytics.

UA - Client-side Tagging
UA - Client-side Tagging

After defining the client, we can create our UA tag under the Tags section.

UA - Client-side Tagging
UA - Client-side Tagging

Our operations for UA are now complete. We can verify that the relevant events and page views are being properly transmitted by testing in preview mode (for both web and server containers)11.

UA - Client-side Tagging
UA - Client-side Tagging

Everything appears to be functioning properly.

Google Analytics: Ads

For the setup of Google Ads tags, all page views and interactions originating from the server-side web container can be used as a basis. For example, a remarketing tag can be set up as follows.

Remarketing Tag

Select the Google Ads Remarketing tag under the tags section for the server-side container and paste the conversion ID (ID) you created in your Ads panel into the Conversion ID field.

Ads Remarketing - Server-side Tagging
Ads Remarketing - Server-side Tagging
Ads Remarketing - Server-side Tagging
Ads Remarketing - Server-side Tagging

After this, setting the All Pages selection as the trigger is sufficient12.

Conversion Tag

The conversion tag can be associated with page view and/or an event. In both cases, the process is performed within the server-side container, just as it is done with the retargeting tag. If the conversion definition is associated with a page view, the All Pages selection can be used as a trigger, similar to the retargeting tag13.

However, if the conversion is to be associated with an event, we must consider events coming from the web container. To view the events passed to the server-side container, you can simply preview the relevant container in Preview mode. If you wish to base the conversion process on a purchase event, but this event is not being passed to the server side, the conversion tag within the server-side container will not trigger. In this case, we must first create a GA4 Event tag for the relevant event in the web container.

GA4 Purchase Event
GA4 Purchase Event

You can also include parameters (such as user, product, etc.) within this event if needed. However, parameter definition is not mandatory.

Ads Conversion
Ads Conversion

After this setup, the purchase event will now be assigned to the server-side container. We can now create a conversion tag associated with this tag. Just as we did with the web container, we select the Google Ads Conversion Tracking tag under the tags and populate the correct ID and tag snippet fields in the conversion tag created via the Ads panel.

Server-side Ads Conversion
Server-side Ads Conversion

For the trigger, we can select the purchase event that we previously completed the configuration for.

*[GCP]: Google Cloud Platform
*[GTM]: Google Tag Manager
*[UA]: Universal Analytics

Footnotes

  1. What Is Server Side Tagging. Elevar
  2. GTM Server Side Tagging Tutorial. Optimize Smart
  3. Server-side Google Tag Manager (sGTM). DNOMIA 2 3
  4. Server-side Tagging in Google Tag Manager
  5. Documentation on “App Engine Setup Guide”. Google Tag Manager and Manual setup guide. Google Tag Manager can be reviewed for different server-side operations. I will also publish a separate article on this topic in the future. 2
  6. How To Create Server Side Container For GTM
  7. [How To Configure DNS For Server Side Container.
  8. A GCP project with default settings is usually free. Pricing for customized configurations may vary. See “How much does the default deployment cost?”. Google Tag Manager
  9. Stand by while your server is created. This may take a few minutes. As a result, your server will be created on GCP, and you will be provided with the relevant project information.
  10. Send data to server-side Google Tag Manager
  11. Common event data. Google Tag Manager
  12. Google Ads remarketing. Google Tag Manager
  13. Google Ads conversions. Google Tag Manager