How to Set Up GA4 Tracking Using Google Tag Manager Server-Side Container

May 14, 2024
Nov 12, 2020
Also available in

In 2023, website owners were forced to move from Universal Analytics to Google Analytics 4. Most were unhappy about that move since GA4 has a different concept, feature, and UI than UA. Besides that, GA4 had many bugs in the beginning. It started improving over time, but some analytics users were not used to GA4 yet and missed the old UA.

The following significant change in tracking is the ability to set up server-side tagging in Google Tag Manager for Google Analytics 4. In this blog post, we will discuss some critical features of GA4 and its difference from Universal Analytics, show how to configure server-side GA4 using Google Tag Manager and make it resistant to adblockers and tracking restrictions by using the Stape custom loader power-up.

What is Google Analytics 4, and why should you consider adding GA4 to your website?Copy link to this section

The first question you might ask is why Google Analytics 4? Were there versions from 1 to 3? And is it the 4th version of Google Analytics? The answer is yes. It is the 4th version of Google Analytics. Everything started with Urching in 2005, then transitioned to Google Analytics (ga.js) in 2009 and Universal Analytics (analytics.js) in 2013. And now we have GA4.

google analytics history

GA4 was available for everyone since July 2019, but it had a different name — APP + WEB. Then, Google decided to rename it and make a big press release. That is how it got a new name — GA4.

If you want to register a new Google Analytics account, GA4 would be the default option. Google will ask you if you wish to create Universal Analytics property as well. But bear in mind that the GA4 interface is a far cry from the well-known Universal Analytics.

It looks like Google is telling users that it’s time to get used to GA4 and move their tracking from UA to GA4. After all, numerous changes were made to data collection and reporting.

universal analytics stops working

How does GA4 differ from Universal Analytics?Copy link to this section

1. Event-driven data model. 

The most significant change that was introduced is switching from the page view/sessions concept to the event-driven data model. This data model has been used for mobile apps analytics for several years now. The pageview model, however, does not fit mobile apps and SPA. It has to do with users having a completely different behavior when using apps and websites.  

The event-driven data model allows you to create an event for any website activity you would like to record inside GA4. Besides, you can use parameters that add more value and description to each event. Google prepared the list of recommended event names to use inside GA4, but you can also create custom events and custom parameters.

2. Cross-device reporting

When it comes to traffic and sales analysis, cross-device user/conversion tracking is the main point. Let’s say a user saw your Adwords ad on the mobile and clicked on it. But for some reason decided to proceed with the checkout on the desktop. The user, however, did not log into any of the Google services. So, Google cannot recognize him and give credit to that particular Adwords click. As a result, the conversion source is lost, and the information for Adwords optimization is incomplete.

To solve this problem, Google released Signals a few years ago. Google integrated Signals functionality into GA4 and added machine learning. It is designed to identify users who are not logged into any of the Google services. If a user is not logged into the Google services or his device cannot be identified via fingerprinting, machine learning fills all the gaps.  

By the way, Google signals data collection is not enabled by default inside GA4. You need to enable it manually by going into settings -> clicking data settings -> data collection.

Another essential setting (and a new one) that you should consider checking is how GA4 identifies users.

They have two options: 

  • by device only (what we used to have in Universal Analytics standard property)
  • by user-id, Google Signals, then device (new option)
google analytics 4 reporting identity

3. Predefined events

Google managed to identify the most commonly used events that marketers and business owners track inside Google Analytics and GTM and added them to the enhanced measurement functionality. Now page view, scrolls, outbound link click, site searches, video engagement, and file download are tracked by default. This feature is typically enabled for all GA4 properties. But you need to make sure that it’s turned on for your account. To do that, go to Data Streams -> choose Webstream details and check if all events are enabled.

google analytics 4 standard events

4. Analysis Hub and integration with BigQuery. 

Google completely redesigned the analytics/reporting hub inside GA4. It allows users to create pivots, tables, and filters easily. There is also a template gallery, similar to what they have in DataStudio. So you will be able to analyze data more efficiently and spend less time on creating custom reports.

The next perk was a big surprise for me. Before, it was impossible to export raw data from the free version of UA to BigQuery. And today, BigQuery export is available to all GA4 users. In a nutshell, you can export GA4 data to BigQuery, which can be integrated with other sources like your CRM. Integration and sampling are the most popular reasons for upgrading to GA360 from my experience.

5. Limit of Custom dimension and Custom metric.

In GA4, the limit of custom dimensions and metrics increased. Google Analytics 4 allows to have 25 user scoped, and 50 events scoped custom dimensions. Custom metrics increased to 50. In UA, you can have only 20 custom metrics and 20 custom dimensions. Increased number of custom metrics and dimensions gives more flexibility for customization of GA4.

6. GA4 debug view.

GA4 debugger is extremely helpful for people setting up Google Analytics 4. With the enabled preview, you can see what events, event properties, and user data GA4 processes. It makes the process of configuring GA4 much faster and easier. Love this feature.

google analytics 4 debug view

7. Other advantages

You might be already tired of reading about why GA4 is so cool. So I will list other benefits: audience evaluation based on their probability of buying in the next several days, a combination of web and app analytics, and lots more.

What is Google Tag Manager server-side tagging?Copy link to this section

Let me quickly remind you what GTM server-side tagging is. And in the next section, we will start with the most exciting part – tracking setup. 

GTM server container moves tracking from the user’s browser to the server. It has many benefits: prolong cookie lifetime, increase tracking accuracy, improved page speed, better data security, ability to bypass AdBlockers and ITPs, and many more. 

This article will give you more details about what GTM server-side tagging is. 

Here we will guide you on how to set up a GTM server container using our service.

How to set up Google Analytics 4 server side?Copy link to this section

1. Create a Google Tag Manager server container. Inside Google Tag Manager click Admin -> Under container table click + -> Add container name and choose Server under target platform -> on the pop up choose manually provision tagging server URL (if you use our service to set up tagging server) -> copy container config.

set up server google tag manager container 
container config server google tag manager 

2. Create an account in our service -> create container -> paste container config that you’ve copied on the previous step. If the setup was successful, you’ll see the status of the container running. It will take up to 10 minutes to set up your container. Please refresh the page in 10 minutes to check the status of the container.

container configuration

3. The key feature of server-side tagging is setting first-party cookies. You need to use a custom tagging server URL to enable this feature. Custom tagging server URL or custom domain should share the same domain as your website. For example, if your website domain is, then the tagging server URL should look like

If you want to add a custom domain, open the sGTM container on Stape, scroll to the domains section, type the domain name, and click Add domain. Once done, you will see DNS records that you should add.

set up custom domain server side tagging 

 Below is an example of DNS setup for CloudFlare.

add DNS records server-side tagging
add DNS records ss tagging

 4. Go back to the Google Tag Manager Server container -> Choose your server container -> Admin -> container settings -> paste tagging server URL.

set tagging server url in gtm

Updating the Web GTM script on your website is highly recommended if you use a custom domain. This tweak will make gtm.js load from your domain. To do so, replace the default domain with the custom domain you set up in the previous step. 

update google tag manager script stape

5. Inside the Web container, create a new tag of the tag Type Google Tag. Add your Google Tag ID.

In the section Configuration settings add the following parameters:

  • Name: server_container_url
  • Value: Enter the URL you've created in step 3

Add trigger to GA4 tag. Normally it should trigger on all page views. 

set up Google Analytics 4 server-side 

You can also create a Google tag: Configuration settings variable that will predefine Google Tag settings if you need to use multiple Google Tags on your website and do not want to add settings for each of the tags manually.

These parameters can be, for example, a setting that defines whether you want to send a page view event every time a Google Tag triggers, set UTM parameters, client ID, etc. There is a list of standard Google Tags configuration parameters.    

6. To set up the GA4 event, go to the tags section and create a new tag with the tag type Google Analytics: GA4 Event. Add your GA4 ID and the event name; there is a list of standard event names

You can create a Google Tag: Event Settings variable that will help to share event parameters across several GA4 event tags or Google Tags. It can be, for example, user or product properties, and there is also a list of standard parameters for event settings. 

Google analytics 4 events settings 
google tag event settings variable

7. Open Google Tag Manager Server container -> click Client -> create GA4 client and save it -> go to Tags and set up GA4 tag. Remember that GA4 automatically sends not only pageview but some other events. Inside Event Name choose variable {{Event Name}}. -> add trigger Client Name equals GA4.

set up ga4 tag in the server container 
set up ga4 client in the server container 

8. Open the Server container preview mode and check that you see GA4 requests. Publish updated inside server and web Google Tag Manager containers. 

test ga4 trigger in the server container 

Custom GA4 loaderCopy link to this section

You can make Google Analytics 4 server-side tracking even more accurate by using a custom GA4 loader. This will allow GA4 to work around any blocking tools, such as ad blockers and other privacy-related technologies that aim to prevent trackers from gathering data about visitors' activities. As a result, you'll see the complete picture of users visiting your site and have more data for ad optimization and custom audiences.

To enable the GA4 custom loader, login to the account, select the sGTM container, head over to the power-ups section, and click config Custom Loader. You should add a Web container ID and select your sGTM domain. Once done, copy the web GTM code that you see in Stape admin, add or replace the web GTM script on your site, and click save changes.

custom loader to make gtm and ga4 scripts resistent to ad blockers
custom loader to make gtm and ga4 scripts resistent to ad blockers

Once you've updated web GTM code and set up ss GA4, you can check modified GTM and GA4 requests in network.

Google Tag Manager request URL should look like this:

Tagging server URL/stape container identifier.js?st=web GTM ID without letters GTM

In my case, it's

custom GTM loader

GA4 request URL should look like this:

Tagging server URL/gt+stape container identifier.js?id=GA4 identifier....

In my case, it's

custom GA4 loader

ConclusionCopy link to this section

GA4 and GTM server tagging were created to fit current world tracking rules, web technologies, restrictions, and data security. You’ll need time to get used to the new interface and features and understand how it can better fit your website and business needs.

If you find migrating to the GA4 and GTM server container difficult for you or realize that you need assistance, feel free to contact us. We can answer your questions or do the setup for you.

Want to start using server-side tags?

Stape has lots of options! Click on Try for free to register and check all the benefits.

Try for free
Tagged with:Google Analytics

Relevant posts

Updated Apr 11, 2024

How much does server GTM cost and why Stape is cheaper than Google Cloud’s App Engine

What cost can you expect for server Google Tag Manager hosted on Google Cloud? Is it a good idea to use a test environment on the productions site. Why stape’s hosting for server GTM is cheaper and how we secure our user’s data.

Updated Oct 24, 2022

3 Easy Steps to Test Server-Side Universal Analytics/GA4 and Facebook Conversion API

Google released a Server-Side version of Google Tag Manager in 2020. Server-side tracking is more complicated than the web container set up, at least for now, since the idea and technology behind server tagging are entirely different from what we used to have on the web. But server-side tagging will give your site huge benefits. Server-side tagging is getting more popular due to its ability to track people using AdBlockers, browsers with ITPs, and other tracking restrictions. The purpose of this article is not to convince you to start using server-side tagging (there is another blog post that describes the main benefits of server-side tracking). I assume that you’ve already decided to implement server-side tagging on your site. This blog post will show you how to check whether Server-Side tracking for Universal Analytics, GA4, and Facebook conversion API was set up correctly.

Updated Feb 23, 2024

Google tag manager server-side: How to set up server Tag Manager, Universal Analytics, GA4, and Facebook conversion API

Server-side tagging has been one of the main trends in web analytics for the last couple of years. Ad blockers, Intelligent Tracking Protection, 3rd party cookie restrictions, regulations like GDPR made analytics and advertising companies start worrying about how and what information they collect about site visitors. Server-side tagging allows moving third-party tags off your site and into a cloud server. In this case, third-party pixels are loaded directly from the could server rather than your site. In this article, I will explain and demonstrate the basics of setting up Google Tag Manager server container, server Universal Analytics, GA4, and Facebook Conversion API.

Host your GTM server at Stape