How to setup GA4 server side tracking

Published by
Oct 17, 2022

The standard, default Google Tag Manager implementation of GA4 is client side tracking. It means that client, in this situation: users browser like Google Chrome or Mozzila, is responsible for launching GTM/GA4 scripts and sending them to Google.

In this article we will introduce another approach and we will implement server side tracking where tracking scripts are processed by server not client. This solution has some advantages:

  • Reduced load on a page
  • Reduce the impact of ad blockers
  • Include user-provided data from your website
  • Control what kind of data is sent to vendors

And also some disadvantages:

  • it is a paid solution – you have to pay for the server. The cost depends on volume of your traffic and number of tags. The cost start from about 100$ monthly. Good that Google will offer you $300 credit for free to test the service until you will decide to pay for it.
  • you need to additional effort to setup your account in Google Cloud Console. You will need also to make some adjustments in your domain settings in order to setup custom domain for your Ap p engine in Google Cloud Server if you want to use full potential of server side tracking.

Server side tracking is for you if you have large traffic volume on your website and you relay on data. If you have just started you ecommerce please use standard client side tracking and come back here when your business will be more developed.

Step by step guide how to implement server side tracking for GA4.

  1. Go to the Google Tag Manager starting page(list of your accounts) and click “Create ContainerCreation of the container in the Google Tag manager

  2. Then name it, chose “Server” and click “Create”
    Name of the container

  3. In the next step you will have to setup you server side tracking server. Please go with “Automatically provision tagging server”.

    Automatically provision tagging server

  4. Then please set up you billing account using your credit card number in Google Cloud Platform. Google will give you $300 credit for free to test this service until you decide if want to pay for it.

    Set up of billing server

  5. After you setup you billing account in the next step you will be able to create you server. Chose your billing account and click “Select billing account and create server”.

    Select billing account and create server

  6. You have just created server for server side tracking. In the next screen you will get you server details. You can check also this details in the future by clicking your GTM number in you server side tracking container. The most important here is to copy your default url which you will need in the next step.
    (If you have access to your domain setting you can setup your custom domain which is recommended if you want to use full potential of server side tracking, here is instruction how setup custom domain for server side tracking, to go directly to your GTM server side project please use the link which is available just next to the Google Cloud Platform Project ID – on the screen).

    Server sider server url
  7. Now you need to create GA4 client tag in you Google Tag Manger server side container. Go to your Google Tag Manager server side container and create new tag. You have there fill your GA4 Measurment ID (you will find this number in Google Analytics in your GA4 property). Create new trigger using flowing setup: Client tag server side GTM
  8. Go to your standard client side container where you have all GA4 tags and update your GA4 configuration tag with your google cloud server url (or custom domain if you were able to setup it).Server side configuration

  9. Update the gtm.js source domain. When you install gtm.js on your website, the default configuration loads the Google Tag Manager libraries from www.googletagmanager.com. To load the GTM code via your server container, change this domain name to the domain of your server container for both the gtm.js script and ns.html file, and add new client type to your server side tracking container (Google tag manager: web container).

    Update the gtm.js source domain

  10. Update your data layer with clients details variables. To do that you need to your website data layer code customer details variables and values. 
  11. Create new data layer variables in Google Tag Manager. To do that go to variables in GTM, create new and name it like: “customer_email”, choose variable type as Data Layer Variable and fill data layer variable name like “customer_email” and save it. Repeat this process for all your customer details variables.Create new clien details variable

  12. Create new User-Provided Data variable using your variables from the previous point. 

    User-Provided Data variable GTM
  13. Upgrade GA4 Configuration tag with user provided dataGo to your GTM GA4 Configuration tag settings and mark: “include user-provided data from your website (Server only)” and chose your user provided variable that you have created in previous step.

    include user-provided data

  14. One more thing you can do to unlock even more potential of server-side tagging is to load supported gtm scripts via your server container using custom domain instead of default one which is: googletagmanager.com. This reduces your reliance on a third-party domain and impact of adblockers.
    To do that please follow instruction published here: https://developers.google.com/tag-platform/tag-manager/server-side/send-data#update_the_gtmjs_source_domain.
Published Oct 17, 2022 by Piotr Ulacha

If you enjoyed the content please share it:

If you have any question about this topic feel free to comment or react below.

Other articles about GA4
Implementation of various environments in GA4
# GA4

Environment - is a set of necessary elements of technical / software infrastructure, which is the basis for the operation of a given website/application. Google Tag Manager environments are simply multiple versions of the same container. When we have a website with a different version for development, testing, production and QA, instead of creating separate GTM containers for each version, we can set up separate environments in the same container that will work independently in each version.

Published by Anna Bacciarelli
Jan 17, 2023
How to measure the impact of email campaigns?

If you plan email marketing campaigns you are interested in the same as with other campaigns, to measure their impact on your business. When you are starting with this topic it is good to know that without additional effort you will not be able to access this impact. You will see no results because Google Analytics will treat traffic from the email campaigns as direct traffic (when users are using your own app) or as referrals (when users are using web email clients). 

Nov 28, 2022
How ready we are to send Google Universal Analytics into retirement?
# GA4

Why now is the time to migrate to Google Analytics 4? Moving to Google Analytics 4 as soon as possible is essential in order to generate the necessary historical data before Universal Analytics stops processing new activities. 

Nov 14, 2022
How to track more data in GA4 in the world of data privacy and adblockers.

If you have implemented cookie policy on your website to be compliant with GDPR you have probably notice that you started automatically to see less data reported in your Google Analytics reports. Luckily Google consent mode and server side tracking can increase the amount of data you measure by up to 100% compared to the standard implementation of GA4. 

Published by Piotr Ulacha
Oct 31, 2022

Conversion path analysis in GA4
# GA4

Conversion is the most important and interesting event for you. It is extremely interesting to know how this happened. What steps did customers take before downloading the file or purchasing the item? When a customer conversion occurs, it is rarely the customer's first interaction with your website or brand. To understand the steps, you need to look at the conversion paths that will illustrate the overall sequence of platforms and touchpoints involved.

Published by Anna Bacciarelli
Oct 27, 2022
Popular recently
Implementation of various environments in GA4
# GA4

Environment - is a set of necessary elements of technical / software infrastructure, which is the basis for the operation of a given website/application. Google Tag Manager environments are simply multiple versions of the same container. When we have a website with a different version for development, testing, production and QA, instead of creating separate GTM containers for each version, we can set up separate environments in the same container that will work independently in each version.

Published by Anna Bacciarelli
Jan 17, 2023
Server-Side GTM like a nuclear technology

Some time ago I listened to a podcast from the Technical Marketing Handbook series from Simo Ahava, whose guest was Adam Halbardier from the Google Tag Manager product team. During the conversation, the topic of transparency of data handled by the Server-Side container appeared.

Published by Mariusz Michalczuk
Dec 04, 2022
How to measure the impact of email campaigns?

If you plan email marketing campaigns you are interested in the same as with other campaigns, to measure their impact on your business. When you are starting with this topic it is good to know that without additional effort you will not be able to access this impact. You will see no results because Google Analytics will treat traffic from the email campaigns as direct traffic (when users are using your own app) or as referrals (when users are using web email clients). 

Nov 28, 2022