Google Tag Manager server side for WordPress moves your tracking logic from the visitor's browser to your own server. This setup protects your data from ad blockers, improves cookie lifetimes, and reduces page load times. You need a server to host the GTM container, a custom domain for that server, and a way to connect your WordPress site to it. This guide walks you through the exact steps to get it running.
Why your current client side tracking might be failing
You are likely already using Google Tag Manager on your site. If you are not, start there first. You can read our guide on what is Google Tag Manager and how it works to get the client side basics down.
Client side tracking has two major problems. First, ad blockers like uBlock Origin or Privacy Badger prevent the tracking script from loading. If the script does not load, you lose the data. Second, browser storage limits can cause cookies to expire quickly, which breaks user identification and attribution.
Server side tracking solves both issues. The heavy lifting happens on your server, not in the user's browser. The user's browser only sends a lightweight request to your server. Your server then talks to Google's servers directly. This means ad blockers cannot easily stop the data flow, and you control the cookie settings.
Before you start, check if your current setup is even working. Use this Google Tag Manager checker to see if your container is loading correctly on your live site. It tells you if the script is present, if it is blocked, and if the data layer is firing. If it is blocked, server side tracking is the fix.
What you need before you start
You cannot just install a plugin and be done. You need three things:
- A server to host the GTM container. This can be a small virtual private server (VPS) or a managed hosting service. It needs to run Node.js or PHP, depending on the implementation.
- A custom domain for your tracking server. You need a subdomain like
track.yourdomain.comor a separate domain entirely. This domain must point to your server via DNS. - Access to your WordPress site. You need administrator access to install plugins and edit headers if necessary.
If you do not have a server, you have two options. You can rent a cheap VPS from a provider like DigitalOcean or Hetzner. Or, you can use a managed service that hosts the GTM server side container for you. Many developers prefer the managed route because it handles updates and security for them.
Step 1: Set up your server side container
Log in to Google Tag Manager. Create a new workspace if you do not have one. Inside the workspace, click on the "Server" tab. You will see an option to create a new server container.
Name your server container something clear, like WordPress-Server-Side. Choose the region that is closest to your server location to minimize latency. Once created, you will get a server container ID that looks like GTM-XXXXXXX.
Now, you need to deploy this container to your server. The Google documentation for server side GTM explains the technical requirements. You need to download the container package from the GTM interface. This package is a .js file or a zip file containing the server logic.
Upload this package to your server. If you are using a VPS, you will likely use a web server like Nginx or Apache. You need to configure your web server to serve this container on the custom domain you set up. This part is technical. If you are not comfortable with server configuration, this is where you might want to hire help or use a managed service.
Step 2: Connect WordPress to the server
Once your server is live and the container is deployed, you need to tell your WordPress site to use it. You have two main ways to do this: a plugin or manual code.
Option A: Using a Plugin
The easiest way is to use a plugin. One popular option is the "Stape Conversion Tracking" plugin, which is available on the WordPress plugin directory. This plugin handles the complex parts for you.
Here is how to set it up:
- Go to
Plugins>Add Newin your WordPress dashboard. - Search for "GTM Server Side" or "Stape Conversion Tracking".
- Install and activate the plugin.
- Go to
Settings>GTM Server Side. - Enter your server container URL. This is the full URL of your custom domain, like
https://track.yourdomain.com/. - You can also enable the "Custom Loader" option. This makes the tracking invisible to ad blockers by changing how the script is loaded.
- Save the settings.
This plugin adds the necessary server side tags to your site. It also handles data layer events for e-commerce if you are using WooCommerce. It sends user data to the data layer automatically.
Option B: Manual Code Implementation
If you prefer not to use a plugin, you can add the code manually. You need to add a script to your site's header. This script tells the browser to load the server side container instead of the standard client side one.
You will need to edit your theme's header.php file or use a code snippet plugin. Add the following script, replacing GTM-XXXXXXX with your server container ID and track.yourdomain.com with your custom domain:
<script>
dataLayer = dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GTM-XXXXXXX', {
'server_url': 'track.yourdomain.com/'
});
</script>
This script configures the Google tag to send data to your server. Make sure you remove any old client side GTM scripts from your site. Having both can cause double tracking.
Step 3: Configure your server side container
Now that the connection is made, you need to configure the server side container itself. Go back to your Google Tag Manager workspace and open the server container.
The server container works differently from the client side one. You do not set up triggers in the same way. Instead, you configure how the server handles incoming data.
- Add Tags: You can add tags to the server container. These tags are executed on the server. For example, you can add a Google Analytics 4 Configuration tag here. This tag will send data to GA4 from your server, not the user's browser.
- Set up Triggers: Server side triggers are based on the data sent from the client. You can create triggers that fire when specific data layer variables are present. For example, a trigger that fires when
eventequalspurchase. - Configure Variables: You can define variables in the server container to capture data from the request. This is useful for extracting specific information from the data layer.
One key benefit of server side tracking is the ability to use a custom domain. When you use your own domain for the tracking server, cookies are set on your domain, not on google.com. This means users who block google.com will not block your tracking. This significantly increases the accuracy of your data.
Step 4: Test your setup
After you have configured everything, you need to test it. Do not rely on assumptions. Verify that the data is flowing correctly.
- Check Network Tab: Open your website in a browser. Open the developer tools and go to the Network tab. Look for requests to your custom domain. You should see requests to
track.yourdomain.com. If you see requests togoogletagmanager.comfor the container, your server side setup is not working. - Check Data Layer: Use the GTM Preview mode. Click the "Preview" button in GTM and enter your website URL. You should see the server side container loading. Check the data layer to ensure events are firing.
- Check GA4: Go to your Google Analytics 4 property. Look at the Realtime report. You should see active users. If you are tracking e-commerce, check if purchases are being recorded.
If you are using the Stape plugin, it has a built-in test mode. You can use this to verify that the data layer is being sent correctly. It shows you the exact data that is being sent to the server.
Common issues and fixes
Even with a solid setup, you might run into problems. Here are the most common ones.
Issue: No data in GA4 If you see requests in the network tab but no data in GA4, check your server container tags. Make sure the GA4 Configuration tag is set to fire on the correct trigger. Also, check if the tag is enabled. You can disable tags for testing, but remember to re-enable them.
Issue: Double counting If you see double the number of events, you likely have both client side and server side tracking active. Remove the client side GTM script from your site. Keep only the server side configuration.
Issue: Ad blockers still blocking Even with server side tracking, some advanced ad blockers can detect the pattern. Using a custom loader, as mentioned in the plugin setup, helps with this. It obfuscates the request so it does not look like a standard tracking request.
Issue: Server errors If your server is down, tracking stops. Make sure your server has good uptime. Monitor it with a service like UptimeRobot. If the server crashes, you lose data.
When to hire help
Setting up server side GTM is not hard, but it is technical. You need to manage a server, configure DNS, and understand data layer logic. If you are not comfortable with these tasks, it is worth hiring a specialist.
You can read more about server side tracking services if you want to leave the technical setup to someone else. A professional can handle the server configuration, ensure compliance with privacy laws, and optimize the setup for your specific business goals.
For small businesses, the cost of a server and a developer's time might be more than the value of the improved tracking. If you are just starting out, client side GTM might be enough. But if you are losing a significant amount of data to ad blockers, server side is the way to go.
Final thoughts
Google Tag Manager server side for WordPress is a powerful upgrade. It gives you more control over your data and improves the reliability of your tracking. The setup takes time, but the results are worth it.
Start by setting up your server and custom domain. Then, connect your WordPress site using a plugin or manual code. Configure your server container and test thoroughly. If you get stuck, seek help. Do not guess.
Your data is valuable. Protect it and make it work for you. If you want to learn more about tracking, check out our guide on how to check Google Consent Mode v2. Compliance is just as important as data collection.
If you have questions, you can contact us for a free consultation. We can help you decide if server side tracking is right for your business.