Web analytics. Server-Side GTM and its capabilities

Friends, I greet you all!
I continue to talk about collecting data from “your Internet”, I want to tell you a little about Server-Side GTM and how it can be useful. To be fair, I want to say that this article is more suitable for those who know a little how to use Google Tag Manager (Web) and set up events in it. To begin with, I propose to divide my story into a number of questions:

  1. What is Server-Side GTM and what is it for?

  2. How to raise Server-Side GTM?

  3. How to work with tags on the server side?

What is Server-Side GTM and what is it for?

Let's assume that you are currently using the Google Tag Manager Web container on your web resources; this is quite enough for most tasks. But why do we also need a server container? There are a number of answers to this question:

  • When tracking events on the client side, we create a load on user devices, and if there are too many tags and their logic is quite complex, then this can create a number of inconveniences on the user device (delays in loading, for example). With server-side tracking, we pass HTTP requests to the server, where they are processed and distributed to advertising and/or analytics service providers. Or you can directly throw data into the database, but we won’t talk about that here.

  • Cookies. Yes, this is the same file that is stored by the user and helps us understand that he visited us yesterday and is not a new user. In GA4 you can specify how long this file will be stored. And if the server is associated with your domain, then the file will be processed on the server, which will increase the accuracy of the analytics and we comply with the first-party context. Perhaps savvy web analysts have already seen that various analytical scripts use each other’s records. On the one hand, this will help increase accuracy, but users’ desires for anonymity must also be taken into account, so the necessary information can be transmitted through the server to various scripts.

  • Blocking script tracking on the site. Yes, yes, are there many users among us who use various blockers? This also affects the statistics, but there is a solution. We send data to a server associated with our domain, so cheap or even free extensions will not help users.

  • When sending data from a server container to advertising accounts, you can increase the accuracy of conversions of advertising campaigns by providing additional information to advertising accounts, and this can improve the learning curve of advertising campaigns and reduce the cost of a conversion action on your resource. Sounds very tempting.

Let's assume that our eyes light up and we want to start using this functionality. The easiest way to start working with it is to simply raise a server container (more on this below) and add a parameter to the Google tag inside the web container server_container_url and a link to the container.

Create Server-Side Google Tag Manager using this link https://tagmanager.google.com/ .
When creating, you will be asked to paste the URL of your main container (not for preview) and specify the token that you received when creating the container in the cloud.

On the Server-Side side of Google Tag Manager, use the GA4 client. Congratulations, now all events from web resources are sent to your server.
I would like to separately say that the server and web containers do not replace each other, but complement each other. Next, you may understand the mechanics of interaction between these containers.

How to raise Server-Side GTM?

There are several popular ways to raise a server container:

  1. Use the services of third party providers such as stage.io

  2. Upgrade an App Engine instance to Google Cloud

  3. Raise a container to Google Cloud via Cloud Run (the easiest way)

  4. Raise a Docker container on your virtual machine

I propose to consider the simplest and cheapest way to lift the container (via Cloud Run). Setup instructions here. But I still want to highlight certain points:

  • After installation, you won’t have to deal with the administration of this container (sometimes updating the container and looking at problematic events in the logs).

  • Everything works well and is autoscaling. Those. When preconfigured, you can specify the minimum and maximum number of instances. It works quite simply: when the peak load on one instance is reached, a second instance of the container is automatically raised, and then the load is redistributed among the containers. After reducing the load on the container, the system will automatically stop the previously raised second instance. For information, when experimenting with a container where more than 10 million requests are made per month, the second instance of the container was launched only a few times.

  • Set the container launch region near you (Finland, Poland, etc.), this will help reduce the delay in the speed of request transmission.

  • Create a container for preview (through it you will debug events on the server side). Note that server-side preview is different from web containers. On web containers, when you preview, you can tell the system which page you want to see, and the system will then direct you to that page. When using server-side preview, this is not possible, so you need to open a new tab and enter the required URL that you will view. At the same time, do not close the preview window; it will show HTTP requests that arrive on the server.

  • I recommend connecting the Logging service inside Google Cloud Platform to study system errors and warnings in detail. Use the free plan, which allows you to save a certain number of GB of logs.

Once the server is created, you will see something similar to this:

Server-Side GTM in Google Cloud

Server-Side GTM in Google Cloud

We also recommend setting up a custom domain for your server. How this can be done is indicated here. This is of course not necessary, but it may be relevant for you. A rather interesting implementation would be to work in your own context, when you run Google scripts not from its servers, but from your own. To do this, you need to configure all of the above, as well as set up a custom domain. Then on the web in the container code change the link www.googletagmanager.com to a link of a domain or subdomain, where there is a binding of the server GTM to the resource domain. You can read more about this implementation here.

How to work with tags on the server side?

Great, we have reached a fairly important section, for the sake of which we did such work. To work with GA4, create a Google Analytics tag on the server container and use the GA4 client as a special trigger variable, after which you will begin receiving data from the web to the server. But I want to focus on the advertising tags inside the server container. You can create the same tags on the web, but we want to move from more to the server and reduce the load on our resource, so let’s look at advertising tags inside the server.

  • Google Ads conversion tags are not very different from the web, you just check the boxes in this tag and in GA4 about providing user data. Don't forget to create a conversion linking tag.

  • The Facebook Conversion API and TikTok Events API tags already have differences. To work with these tags, I suggest working with the tag provider from stape-io. Using the TikTok Events API tag as an example:

TikTok Events API Tag

TikTok Events API Tag

Using the TikTok advertising account as an example, we can see how to set up an event. Go to the advertising account -> Tools -> Events -> Select our pixel. In the pixel settings, generate an Access Token and insert it along with the pixel ID into the tag. To check the functionality of the tag, you can generate a Test ID in the Test Events section. Run the tag (perform an event on the resource) and in the Test Events section you will see that a test event has occurred. If everything works, you can remove the value from Test ID and start the tag to work.

We previously said that these tags will help you better optimize your campaigns and increase the accuracy of your analytics. That's right, inside such tags there is a User Data section. There you can put phone numbers, user email, click identifier like ttclid, fbclid, etc. Similar manipulations can be done for VK and Yandex Direct, but here you may need to create your own tags, but you can always run this from a web container. This data will help advertising platforms find the right quality audience for you, because you have enriched the original data. For example, you want to send a user’s phone number to an advertising platform, but there are certain pitfalls here, too. they need to be brought into the format required by the platform. Let's try to convert it to a normal format for platforms. As a rule, all platforms require sending numbers in the form of a SHA256 hash, but before hashing it, the phone number must be in the format E.164, i.e. The number must not contain spaces or parentheses. hyphens, etc. Only the “+” sign at the very beginning of the number. Example number +71901111111. You can collect phone number data from form fields on the resource, then convert it into E.164 format using a simple JS script inside a web container and can hash it there. You can come up with hashing methods yourself, but as an example I’ll show one of them. First, create a custom HTML tag and paste the code into it:

<script>
  (function() {
    var script = document.createElement('script');
    script.type="text/javascript";
    script.src = "https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js";
    script.integrity = "sha256-6rXZCnFzbyZ685/fMsqoxxZz/QZwMnmwHg+SsNe+C/w=";
    script.crossOrigin = "anonymous";
    document.getElementsByTagName('head')[0].appendChild(script);
  })();
</script>

Next, create a variable of your own JS code and paste this:

function() {
  var name = {{Номер телефона}}; 
  var hash = CryptoJS.SHA256(name).toString();
  return hash;
}

At the output we get a hash, which we can transmit along with the event to the server and further to advertising platforms. You can also pass click ID tags like ttclid, fbclid, etc. You can take them directly from the link when you go to the resource; figure out how to store it inside the session yourself, there are a lot of solutions (you can put it in Session Storage). Then you can transfer the click ID to the server and then to the advertising platform. Great, you sent the data to advertising platforms and enriched them with other entities.

Of course, Server-Side GTM has quite a lot of functionality, but I didn’t want to rewrite articles by various authors, so my article rather shows how it can be picked up and used.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *