Server-side Google Analytics 4 for WordPress

Published
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 https://tagmanager.google.com/ 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 (stape.io)
 tagging URL
  • 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.
use a custom domain

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 stape.io 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. 

Global CDN

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. Go to your Google Tag Manager Web container and either edit an existing GA4 configuration tag or create a new one. Enable the "Send to server container" option and add the Server Container URL. Set the triggering to trigger on all pages. Save the tag. Then, publish the container.

Google Tag Manager Web container 

2. In your Google Tag Manager Server container, go to the "Client" tab and create a new GA4 client. Save the client and then go to the "Tags" section to set up the GA4 tag. Inside GA4 tag choose the GA4 configuration you just created as the "Configuration Tag", add your Measurement ID and set the Event Name to {{Event Name}} using a variable. Add a trigger with the condition "Client Name equals GA4".

Google Tag Manager Server container

3. If you have an eCommerce website, create a new GA4 Event tag in your Web container. Choose the GA4 configuration you just created as the "Configuration Tag" and set the Event Name to {{Event}} using a built-in variable. Under "More Settings” and "Ecommerce" enable  "Send Ecommerce Data". Set the "Data Source" to "Data Layer". Create a trigger with the trigger type "Custom Event" that fires on all custom events and the Event Name set to "add_to_cart|view_item|begin_checkout|purchase", with regex matching enabled.

create a new GA4 Event tag

Test your setup to ensure that dataLayer events are being properly sent to the Google Tag Manager Web container.

event add to cart

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

Web and Server container preview mode

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