Knowing exactly what your clients or website visitors are doing is a key aspect of marketing and web project management.
If you want to understand how they navigate your site, where they click, and which advertisements generate the most engagement, you need a powerful analytics tool. Google Tag Manager (GTM) makes tag management flexible and convenient. Its server-side version (Server-Side GTM) offers even greater control over data, enhancing performance, bypassing browser limitations, and improving user data security.
In this guide, we will walk you through the process of installing and configuring Server-Side GTM on your VPS. We'll cover everything from selecting the appropriate domain and creating a container to setting up encryption and integrating the system with your website.
Google Tag Manager is a tool that allows you to manage tags without modifying your website’s code. Tags are small pieces of code embedded in website pages or within a Google Tag Manager container. Their primary function is to track user actions and transmit collected data to web analytics systems, marketing platforms, and advertising services.
→ Page views
→ Clicks on buttons, links, or banners
→ Form submissions (registration, subscription, orders)
→ Adding items to a shopping cart and completing a purchase
→ Video playback and other user interactions
Simplified Tag Management
No need to manually add code to your site, reducing errors and making the process more structured.
Flexibility and Convenience
You can quickly modify tag settings, add new analytics tools, and adjust scripts without involving developers—especially useful for marketers and advertisers.
Support for Multiple Platforms
GTM integrates with analytics tools, ad platforms, A/B testing services, CRMs, and more, making it a versatile solution.
Improved Performance
Since tags load asynchronously, they don’t affect page speed. GTM also allows you to load only the necessary tags at the right time, reducing browser load.
Benefits of Server-Side GTM
Regular GTM operates on the client side, meaning data is sent directly from the user's browser. However, modern browsers increasingly block third-party scripts, leading to data loss. Server-side GTM allows data to be transmitted through your own server, which:
→ Bypasses browser restrictions such as third-party cookie blocking
→ Enhances security by processing data through your server before sending it to analytics tools
→ Enables filtering and processing of data before transmitting it to other services
Before installation, you need to set up subdomains for server-side GTM:
→ Main domain: sgtm.example.com (used for data transmission to analytics)
→ Preview domain: preview-sgtm.example.com (used for testing configurations before deployment)
How to Create Subdomains
1. Log in to your hosting control panel.
2. Find the "Domains & Subdomains" section.
3. Add two new subdomains.
4. Assign their IP addresses to your VPS in the A-records.
5. Verify the changes using the nslookup or dig command.
Before installation, create a container in Google Tag Manager.
Steps:
1. Open Google Tag Manager.
2. Click "Create Container".
3. Enter a name for the container, select "Server", and click "Create".
4. Copy the container key—you'll need it in the next step.
Preparing Files
1. Connect to your server via SSH.
2. Create a folder for the GTM configuration and navigate to it:
mkdir -p ~/sgtm && cd ~/sgtm
3. Download the setup files.
After extraction, you should have the following files:
→ docker-compose.yml
→ gtm.env
→ gtm-preview.env
→ nginx.conf
Configuring GTM
1. Open the gtm.env file and enter the container key:
vim gtm.env
2. Add the key under CONTAINER_CONFIG= and set the preview server domain in PREVIEW_SERVER_URL=.
3. Similarly, modify gtm-preview.env by adding the same key and setting:
RUN_AS_PREVIEW_SERVER=true
4. Open nginx.conf and replace sgtm.example.com and sgtm-preview.example.com with your actual subdomains.
Starting GTM Containers
Run the server-side GTM using Docker:
docker-compose up -d
Congratulations! You have successfully installed and configured Server-Side GTM. Your website now transmits data through your own server, giving you greater control, reducing browser data blocking, and improving analytics accuracy.
Whenever needed, you can update settings or add new tags through Google Tag Manager—without modifying your website’s code! If you have any questions, refer to Google's official documentation.
Apply the discount by inserting the promo code in the special field at checkout: