Server-side Google Analytics 4 for WordPress

Nov 16, 2023
Mar 28, 2023
Also available in

With valuable insights into how customers interact with your site, you can track user trends, optimize responses to provide better customer experiences, and ultimately gain a competitive advantage in the ever-evolving digital landscape. With all of this in mind, using server-side Google Analytics 4 for WordPress has become increasingly popular due to its accuracy and ease-of-use. 

This blog post will explore the advantages and setup of server-side Google Analytics 4 for WordPress sites with a GTM server side plugin and help identify ways it can benefit your clients’ marketing efforts. Let's take a look at why you should seriously consider implementing server-side Google Analytics 4 into each WordPress site you manage!

Advantages to using server-side Google Analytics 4Copy link to this section

More Accurate Data CollectionCopy link to this section

The main benefit of server-side Google Analytics 4 implementation over the client-side is that ss GA4 configured using sGTM using a custom domain sets 1st party cookies. 

WebKit browsers (Safari, Firefox, etc.) limit 3rd party cookies lifetime to 1 or 7 days. Client-side GA4 implementation sets 3rd party cookies. It means that if a users view your website from any browser built on the WebKit, client-side GA4 cookies will live 7 days maximum. 

Conversely, with ssGA4 and sGTM using a custom domain, cookies will be set from the subdomain located within the main domain and considered 1st party. 1st party cookies are not affected by WebKit yet and will live up to two years. However, there are some plans to limit the life of 1st party cookies set from the third-party IPs

Increased Data Privacy and SecurityCopy link to this section

Server-side provides an additional layer of privacy and security for sensitive information. This can be particularly important for organizations that collect personally identifiable information (PII) or financial data. By processing data on the server, businesses can reduce the risk of exposing sensitive data to potential security threats, ensuring that data is collected and processed in a more secure and protected manner.

Compliance with RegulationsCopy link to this section

Сomply with data protection regulations, such as the General Data Protection Regulation (GDPR) and the California Consumer Privacy Act (CCPA). Ensure that you are collecting and processing data in compliance with applicable regulations.

In the summer of 2022, several European countries (France, Denmark, Italy, etc.) concluded that using Google Analytics 4 is illegal since it transfers the personal data of EU users to the US. One of the solutions for the legal use of GA4 in these countries is server-side GA4 which uses a European proxy server

How to set up server-side GA4Copy link to this section

Set up server Google Tag Manager container on Stape.Copy link to this section

1. Go to and log in to your Google Tag Manager account.

Google Tag Manager account

2. Click on the "Admin" button, and under the "Containers" column, click the "+ Create Container" button.

Create Container

3. Choose a name for your server container, select "Server" as the type of container, and click the "Create" button.

create server container in google tag manager

4. Select the option to "Manually provision tagging server," and copy the container configuration that appears. Save this configuration in a text editor as you will need it later.

Manually provision tagging server

5. Log in to your account on our service or create a new account if you haven't already.

6. Once you're logged in, click on the "Create Container" button. Give your container a name, paste the Container Configuration that you copied from your Google Tag Manager Server Container, and select the server location. Click "Create Container."

create container at stape

7. Wait for around 5 minutes for the server container to deploy. Refresh the page to update the status. If the setup was done correctly, you should see the status "Running." If you see "Error," double-check that you've copied the correct container configuration. Contact support if the error persists.

8. In this step, you need to set up a tagging URL.

You have two options:

  • You can choose to use the tagging URL that was created for you and is hosted on our domain (
  • Or use a custom domain. I highly recommend using this option because it will help to prevent tracking from being blocked and increase cookie lifetime.

If you choose to go with the first option, move to step 9.

If you want to configure a custom tagging URL, click "Add domain" under stape provided tagging URL -> log in to your domain name service and create a new DNS record for the subdomain you want to use. You can use any subdomain name you want. 

Add these settings:

    Type: A

    Name: ss (or any other subdomain name you want)

    IPv4 address: IP address depends on the location of the servers. You can find the custom domain IP address in your account.

    TTL: Auto

    Proxy status: disable

Your settings should look like this:

a custom tagging URL

9. You can enable the Global CDN feature for the server container, which uses Cloudflare technology to load js files from a server closer to your site visitors, resulting in faster js file serving and better page speed. Consider your country's privacy regulations before enabling this feature. Add a CNAME record to make Global CDN work.


Consider your country's privacy regulations before enabling Global CDN.

After you've enabled Global CDN you will need to add CNAME record to make Global CDN work. 

10. Add the tagging server URL to the Google Tag Manager Server container by going to "Admin," then "Settings," and selecting "Container Settings.”

Configure GTM server side plugin for WordPressCopy link to this section

1. Log into your WordPress Admin, and go to the plugins. Then, click “Add New,” type “GTM Server-Side,” choose this plugin, and click install now. Once established, click Activate. 

wordpress plugin by stape

2. Open the GTM Server-Side plugin you installed in the first step and paste tagging URL inside the plugin settings. Next, select if you want to add web GTM to all site pages or just add plugin functionality without adding GTM script (this option should be used in case you are using any other plugin that inserts GTM script on the site). Next, add WEB Google Tag Manager ID, tagging server URL, and stape container identifier if you want to use a custom loader

GTM Server-Side plugin

3. If you have an eCommerce website and want to push ecommerce events and user data to the Data Layer, click on the second tab of the plugin and enable two checkboxes. Note that it can work only with woocommerce shops. 

push ecommerce events and user data to the Data Layer

Set up server side GA4Copy link to this section

1. Inside the Web container, create a new tag of the tag Type Google Tag. Add your Google Tag ID.

In the section Configuration settings add the following parameters:

  • Name: server_container_url
  • Value: Enter the URL you've created

Add trigger to GA4 tag. Normally it should trigger on all page views. 

set up Google Analytics 4 server-side 

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 of the tags manually.

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

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

You can create a Google Tag: Event Settings variable that will help to share event parameters across several GA4 event tags or Google Tags. It can be, for example, user or product properties, and there is also a list of standard parameters for event settings. 

Google analytics 4 events settings 
google tag event settings variable

3. Open Google Tag Manager Server container -> click Client -> create GA4 client and save it -> go to Tags and set up GA4 tag. Remember that GA4 automatically sends not only pageview but some other events. Inside Event Name choose variable {{Event Name}}. -> add trigger Client Name equals GA4.

set up ga4 tag in the server container 
set up ga4 client in the server container 

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

test ga4 trigger in the server container 

ConclusionCopy link to this section

In conclusion, anyone can gain valuable insight into their customers' site interactions and use this to optimize the customer experience and gain a competitive advantage. GTM server side plugin for WordPress has made it much easier and more accurate than other methods of tracking user data. 

If you have any questions left or just want some help with the setup of Google Analytics 4 for WordPress, do not hesitate to contact the stape support team

Want help with setting up Google Analytics 4 for WordPress?

We've got you covered! Click Get assistance, fill-up the form, and we will send you a quote.

Get assistance

Host your GTM server at Stape