Stape
Search
Try for free

How to set up Google Tag Manager server container

Updated
Jul 24, 2024
Published
Oct 4, 2020
Also available in

Collecting data about your website visitors is critical for analyzing and improving the online business presence, reaching users, and converting them into customers. There are two ways to collect data: client-side and server-side, both with their benefits and restrictions.

With client-side tracking, the browser sends a request directly to a third-party tracking service like Google Analytics. The interaction takes place between the browser and the third-party service. With server-side tracking, an intermediate point is added. In this case, it is the Google Tag Manager cloud server. The request first goes to the cloud server, which processes it and sends it to a third-party system (Google Analytics). This means the cloud server processes the request instead of the client's browser.

Google Tag Manager (GTM) server-side tagging allows website owners to move third-party tracking pixels from their website into the Cloud server. It means that the client browser will no longer process tracking pixels. It will be loaded directly from the server. This approach provides the following benefits:

  • More accurate data
  • Faster website load time
  • Extra control over privacy

Your digital marketing analytic tools (like Google Analytics) can run without executing third-party cookies on the client side. With appropriate server containers set up, you will forget about heavy JavaScript, blocked third-party cookies, and incomplete data in analytics tools.

All requests will be considered first-party if server-side tracking is hosted in your website’s subdomain. Google has a detailed description of GTM server tracking and how it can benefit your website.

Step 1: Create a Google Tag Manager server container

There are many common elements between web and server containers, like tags, triggers, variables, preview mode, etc. However, the setup of the GTM server-side container is more complex than that of the standard web container.

The main complexity of setting up a server-side GTM container is configuring the cloud environment to run the sGTM container. With the help of Stape, configuring cloud servers for sGTM will take only 5 minutes, and there is no need to hire developers. Besides that, Stape offers additional features on top of the Google Tag Manager server, like bypassing adblockers, increasing cookie lifetime, sending offline data, etc.

👇 This video shows how to set up server Google Tag Manager container

Below is the step-by-step guide on how to set up GTM server-side container.

1. Open your WEB Google Tag Manager container https://tagmanager.google.com/.

Click Admin. Under the container column, click +

set up server gm

2. Type the container name, choose Server, and click Create.

set up server gm

3. Choose Manually provision tagging server, copy your container config and paste it in any text editor. We will need it for the next steps.

set up server gtm

Step 2: Create a Stape account to host your server GTM container

1. Go to stape.io and create an account or log in.

log in or sign up to access Stape

2. Click Create container on the top right. 

3. Enter your container details:

  • Container name. The name does not necessarily have to be the same as the container name in your server GTM.
  • Container configuration - paste Container Config that you copied from your Google Tag Manager Server Container.
  • Server location - select your server location based on the location of most of your clients. Location can not be changed later.
  • Click Create Container.
create container on stape

4. Choose a plan for your container. You can start with a Free plan. Click Continue with a Free plan.

stape pricing plans

5. You will see the status of your container, container config, and plan name. It takes around 5 minutes to deploy a server container. Please reload the page to update the status. If the Google Tag Manager server-side setup was done correctly, you should see the status “Running”. 

running container on stape

Step 3: Configure a custom tagging server URL

You can use a custom tagging server URL to set up first-party cookies. Custom tagging server URL or custom domain should share the same domain as your website. For example, if your website domain is example.com, then the tagging server URL should look like ss.example.com. 

  • Same origin
  • Subdomain
  • Default domain
three ways to set up a custom domain

There is a detailed blog post where you can find a description of mapping a custom domain for the server Google Tag Manager container: using the same origin (Cloudflare and nginx).

But here, we will cover custom subdomain setup:

1. Open your sGTM container on Stape, scroll down to “Domains” and click Add custom domain

2. Write a custom domain.

3. You will see DNS records that you should add.

The DNS record depends on the server location and CDN option you choose.

  • Disable CDN - choose not to use any type of CDN.
  • Stape Global CDN - loads scripts from a server closer to a user visiting your website.
  • Own CDN - helps to tag server URLs from the same IP as your website. It gives the ability to set cookies that Safari can not shorten.
cdn settings on stape
cdn settings on stape

The DNS records you should configure vary depending on the server location and your selected CDN settings. You will see DNS records that you should add inside your stape.io container.

dns records on stape

4. Log in to your DNS account and add records you see in your stape.io account. Below is an example of DNS setup for CloudFlare. Open the DNS setting of the required domain and click Add record.

dns records

 Then, write the records you see in your stape.io account. Ensure that the proxy is turned off.

ensure the proxy is turned off

Usually, it takes 2-3 hours to verify the custom domain. For some DNS providers, verifying records might take up to 72 hours. We will email you once the custom domain is verified or any error is detected. If there is an error with the verification, please follow this instruction on how to verify custom domain verification.

5. Once the custom domain is verified, go back to the Google Tag Manager Server container → Choose your server container → Admin → container settings → paste tagging server URL.

paste tagging server url

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

Step 4: Create a Google Tag inside the Web GTM container

Open your Web container, create a new tag - 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

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

add trigger ga4 tag

Optional: 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.

create a Google tag: Configuration settings variable

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.

Step 5: Create Google Analytics: GA4 Event tag

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.

Step 6: Create GA4 client inside Server GTM container

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 pageviews but also some other events.

Inside Event Name, choose variable {{Event Name}} → add trigger Client Name equals GA4.

Step 7: Check and debug your setup

Open the Web and Server container preview modes and check that you see GA4 requests. Then, publish the update inside the server and web Google Tag Manager containers.

Step 8: Set up a custom GA4 loader

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.

How to set up a custom loader:

1. Log in to your stape.io account.

2. Open the sGTM container → Click Power Up.

3. Click Config Custom loader power-up → add your WEB GTM ID → You will see updated web GTM code → Copy this web GTM script and add or replace existing web GTM script on your site.

4. Once you've updated the web GTM code and set up server-side GA4, you can check modified GTM and GA4 requests in the network.

Google Tag Manager request URL should look like this:

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

GA4 request URL should look like this:

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

In our case, it's https://load.gtm.stape.dog/gtcovxbvwx.js?id=G-0SME9XLYER

Conclusion

That’s it. Now, you’ve set up a server container, and Google Analytics runs via your server container. If you want to load GA within your domain and make GA request 1st party follow these steps to use a custom subdomain. And our team of experts can help!

Tagged with:gtm server

Host your GTM server at Staperight now!