Stape
Search
Try for free

How to set up server-side tracking

Updated
Jul 26, 2024
Published
Feb 26, 2022
Also available in

This blog post is for beginners making their first steps in the server-side world. Here, you will find the definition and benefits of server-side tracking and a brief overview of the most popular platforms that support server-side tagging. We will also present different use cases and the advantages of server-side tracking with Stape services and show you how to set up server-side tracking with Stape.

With server-side tracking, your website first sends data to the cloud server. Next, the cloud server distributes data between third-party vendors and tracking platforms. The most popular server-side tracking platform is Google Tag Manager. They released their server-side tagging type of tracking in 2020. It is trendy at the onset of the cookieless era because it is one of the most reliable and privacy-friendly methods of tracking user behavior without relying on cookies.

Compared to client-side tracking, it provides more accurate data collection and conversion tracking, extended cookie lifetime, reduced impact of ad blockers, control over data, improved website page load time, hiding tracking IDs and secret API keys, and more.  

Step 1. Set up Server Google Tag Manager container with Stape account

There are several tools you can use for setting up server-side tagging. Our choice is the server Google Tag Manager container. The main advantages of using sGTM, in our opinion, are:

  • Easy to use.
  • Transparency and convenience.
  • No additional costs. You should pay only for servers, no fees to using sGTM interface.
  • Version control system.
  • Any changes can be easily undone and returned to an earlier state, as well as keep track of who made the changes, where, and when.
  • Multi-user mode.

The first step when starting with server-side tagging is configuring the sGTM container. Using Stape, you can set up a tagging server for your sGTM container in one click. All you need to do is:

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

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

log in to stape

5. Click Create container on the top right. 

6. 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

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

stape io pricing

8. 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

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

There are three ways to set up a custom domain:

  • Same origin
  • Subdomain
  • Default domain
types of custom domain configurration

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

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 options - stape
cdn configuration - 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.

stape global cdn settings

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

Then, write the records you see in your stape.io account. Ensure that 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.

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.

And all is done!

From our point of view, configuring a custom domain with the same origin domain is the best option because it helps to prolong cookie lifetime in all browsers. However, this method is technically advanced and requires CDN or a load balancer. To configure the same origin domain, follow this guide.

If you can't configure the same origin domain, we have solutions for prolonging cookie lifetime in Safari: Own CDN and Cookie Keeper.

Why Stape is the easiest and cheapest way to start with server-side tracking

Using Stape, you can set up server GTM in less than 1 minute, and we are the cheapest solution on the market. Stape is affordable because we buy servers in bulk and for an extended period. Plus, we optimize our servers to work only with Google Tag Manager.

Besides that, we have other advantages:

1. Custom gtm.js and gtag.js loader. It helps you make Google Tag Manager and/or Analytics 4 scripts more resistant to adblockers.

2. Global CDN. Allows for faster js files serving by using a server that resides closer to your site visitor. It results in an improved page speed that might positively affect organic ranking.

3. Logs. A handy feature when setting up or troubleshooting server-side tagging. It helps to figure out what data was sent to the server and how it got processed. For example, you can check if all purchase events had 200 status (meaning they were correctly handled) or check all requests with a 500 response code.

4. Preview header. It helps see all of your incoming requests in the sGTM debugger when the request was sent not from web GTM.

You can read about all of the advantages of server-side tracking with Stape in our blog as well.

Our team of experts is always happy to help new users get started with tracking and answer any questions.

For high-volume websites, we offer custom plans. Feel free to use the pricing calculator to estimate the best plan for your site.

Step 2. Set up Server Google Analytics 4

If you do not have GA4 configured, follow the below steps:

1. Inside the Web container, create a new tag of the tag type Google Tag.

Add your Google Tag ID.

Add trigger to GA4 tag. It usually should trigger on all page views.

set up google tag

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 tag manually.

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

2. To set up the GA4 event tracking, 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.

set up ga4
set up ga4

3. Go to your Google Tag Manager Server container. Click Clients and New.

set up ga4

4. Choose Google Analytics: GA4 (web) and click Save.

set up ga4

5. Go to Tags and click New.

set up ga4

6. Choose Google Analytics: GA4.

set up ga4

7. Add Measurement ID and Event Name.

Measurement ID - Follow this guide to find GA4 ID. You can add it as a variable or if the event came from a GA4 web tag, you can leave this field blank to inherit the measurement ID of the event.

Event Name - the event name to send to Google. See the recommended events for more information. If this field is blank, the value of the event_name parameter will be sent.

set up ga4

8. Click Triggering.

set up ga4

9. Create triggers for the tag. Client name should equal GA4. Example:

Click +

set up ga4

Choose Custom type → click Some events → choose Client Name in built-in variables → set Equals GA4 (the name of your GA4 client) → click Save

set up ga4

10. Open web and server GTM debuggers and test the setup.

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

set up ga4

Step 3. Set up Server Google Ads

If you want to have enough data to examine the performance of your ad campaign and provide Google's machine learning algorithms with additional knowledge about your company's objectives, Google Ads conversion tracking is a need. Moving Adwords tags onto a server will reduce the amount of code that needs to run on the webpages and aid with performance issues for slower internet connections as well!

Server-side Google Ads tracking can work only using server GA4 requests. It means that you must set up server-side Google Analytics 4 before proceeding to server-server Google Ads.

1. Ensure that server-side Google Analytics 4 is set up correctly.

2. In the Server container, set up the Conversion Linker tag. This tag should trigger on all pageviews.

3. Set up Google Ads remarketing tag in server GTM. It looks similar to setting up a web remarketing tag. All you need to do is add a Conversion ID and choose a trigger that must use GA4 requests. You might also decide to send dynamic remarketing event data and Provide custom parameters.

4. Create a new Google Ads Conversion Tracking tag in the Server container→ add Conversion ID and Conversion Label similarly to the web Google Ads tag setup.

Then you have an option to add Product and User Data. (It looks very similar to how Facebook conversion API works). If you send user and product data from the web to the server, you can enable these checkboxes and select event data as a data source.

Step 4. Set up Facebook conversion API

Unlikely Google platforms, Facebook recommends using both web and server tracking. The main advantage of the web+server method is that it still utilizes 3rd party cookies (when possible). The main benefit of the server only approach is that it reduces the number of 3rd party java scripts on your site and allows you to strictly control what data was sent to FB. So it’s up to you to decide whether to use web+server FB tracking or server only.

Setting up FB CAPI is more complicated since it requires event deduplication (when using the web+server method), sending user parameters, such as email, phone number, first/last name, etc.

Step 5. Connect other needed platforms

We hope that by this time, you can agree with us that server-side tracking is a must for your marketing campaign. But it’s still relatively new technology, and not all platforms have provided it, e.g., Twitter. So we created a list of all vendors that support server GTM and consolidated their requirements, instructions, and documentation.

Popular platform integrations:

Custom Solutions and more:

Advanced server-side tracking setup

Besides the direct implementation of server-side tracking described earlier in this blog post, server-side tracking gives some advanced opportunities previously unavailable in web tracking. Here we will cover some of the most popular ones.

1. Connect CRM to sGTM

It’s possible to serve webhooks from the CRM to sGTM. Inside the sGTM, you can retrieve webhooks data and add it to any platform. You may use it, for example, to enrich Facebook Conversion API Data with the user parameter or offline events. Or maybe send in-store orders from your POS to Google Analytics or track refunds.

2. Enrich data using Firestore

Firestore is a database that stores collections of documents. sGTM allows you to read and write data to/from Firestore. sGTM and Firestore give unlimited opportunities in terms of data enrichment. We have a detailed guide on how to read/write data to Firestore.

3. Google Sheet integration

Stape created a custom tag that allows the integration of sGTM and Google Sheets. It’s an excellent opportunity for those who use tools similar to Zapier to track any data from the site into Google sheets. Tools like Zapier can be costly, while with sGTM, you can get the same integration at close to 0 prices. Check this article about the Google Sheet tag for sGTM.

While there are many non-standard sGTM implementations, these are the top three that stand out as being particularly popular. Check our blog for more information about server-side tagging.

Conclusion

Setting up server-side tracking is a great way to improve your website’s performance and get more accurate data. This blog post gathered general information needed to get started with server-side tracking. Here we covered all of the possible guides and use cases. Server-side tagging has many actual and potential use cases. We have a blog post covering server-side tracking use cases in detail.

Don’t hesitate to contact us to get assistance. We are experts in server-side tracking and can help you to dive into the world of tags.

Tagged with:gtm server

Host your GTM server at Staperight now!