
Browsers continue to restrick more user's data which results in big data gaps and makes it hard to track customers' journeys. Besides, it's not a secret a lot of users use ad blockers or simply don't accept cookies while in your store.
So, even if you set up Google Analytics 4 for your Magento website, it doesn't mean you will be collecting all the data. But we have a solution.
Today you'll learn about the future of data tracking — server-side tracking — and find out how to set up server-side tracking in Magento. Spoiler alert: we'll use the Magento 2 Google Tag Manager Extension for that.
Post Contents [hide]
It's not an entirely new concept, but still, before we jump to the configuration steps, let's define what is server-side tracking.
What is Server-Side Tracking?
Server-side tracking or server-to-server tracking is a tracking that runs in the server-side environment. It enables you to fire tracking pixels and codes from your server instead of the users' browser.
Thus, your server fires tracking pixels and communicates directly with Google Analytics through solutions like GTM.
Important: when you use server-side tracking you DO NOT fire third-party JS code on your website and set up the third-party cookies in the users' browsers.
Correspondingly, you don't run GA4 in users' browsers — you run GA from your server.
Confused already?
Let's also talk about the client-side tracking to help you understand the server-side tracking better.
What is Client-Side Tracking?
Currently, you use client-side tracking or browser-based tracking. In this case, the browser fires tracking pixels and codes and communicates with Google Analytics 4 through GTM. This way, once the GTM JS is executed, it stores third-party cookies in the users' web browser. Then these cookies send the collected data to GA4.
It is the most common way of tracking data, But there is a downside. When users don't consent to cookies or use ad blockers, there is a high chance their data won't be collected and sent to GA.
The Benefits of the Server-Side Tracking?
Now that you understand why some data might be missing from your GA reports, you must be more eager to set up server-side tracking for your Magento. So, let's sum up all the benefits it offers.
- Web browsers and ad blockers can't block server-side tracking which means all data will be collected properly.
- You get more control over what data is sent to Google with the server-side tracking.
- Server-side tracking helps to fill the data gaps created by browser-based tracking.
- Website speed is improved since no tracking codes need to be fired from users' browsers.
- You can implement API-based conversion tracking to track conversion more accurately.
How to Enable Server-Side Tracking in Magento?
We agree, that server-side tracking seems like a complex concept hard to wrap one's head around. However, you don't have to worry about how it is processed as long as you can collect all the data you need in Google Analytics. Agree?
Thus, we come to the main section of our guide. You can set up server-side tracking in Magento 2 using custom GTM loaders or GA4 Measurement Protocol. Let's cover both in more detail.
GA4 Measurement Protocol
One of the easier and cost-free ways to enable server-side tracking for Magento is GA4 Measurement Protocol (MP). It is a set of rules you must follow to send raw event data from your server to your GA4 properly.
In short, GA4 Measurement Protocol allows you to send events directly from your server to Google Analytics servers through HTTP requests. That's exactly how server-side tracking works. And it's really easy to set up without any technical knowledge.
To set up server-side tracking in Magento using GA4 MP:
1. Create Measurement API Secret
Go to your Google Analytics account > Admin > Data Streams, choose a data stream and find the Measurement Protocol API secrets.
Click on the Create button while on the Measurement Protocol API secrets panel.
Give your API Secret a Nickname. and click on the Create button.
Once you create your API Secret it will appear in the grid. Copy the Secret Value and move to the next step.
2. Set up Google Analytics 4 in Magento
First, navigate to your Magento admin panel. Then go to Stores > Configuration> Google Tag Manager and Analytics > Google Analytics 4.
Here you need to enable Google Analytics 4 and set your Measurement ID.
Then move down to the Measurement Protocol (GA4 Server Side Tracking) option, enable it and paste your API Secret in a corresponding field.
Don't forget to Save the settings, and it's basically it. You've enabled the server-side tracking. No other steps are required.
Note: GA4 Measurement Protocol can be used parallel to the GTM tracking integration. So you can still set up GTM for Magento and track some data through it.
Custom GTM Loaders
In case you use some custom GTM loaders you can still enable server-side tracking in Magento 2. For that jump to the Web Container section of the GTM extension settings and enable the Head Script and Body Noscript as the Installation Method for GTM.
Then paste your custom Head Script and Body Noscript in the corresponding fields.
Besides, you also need to specify your Account ID and Container ID from the GTM account.
Finally, enable Google Analytics 4 and paste the Measurement ID for it, just like we did in the previous paragraph.
Save the settings and give Google Analytics some time to collect data through this new way.
Note that depending on the way you set up server-side tracking for Magento, you can use different ways to debug Google Analytics 4. If usually you can just enable the DebugView in GA4, testing the server-side tracking a slightly different.
When you use the Measurement Protocol, you can test the events fired on your website in the Reports > Realtime section. However, if you use custom GTM loaders, they might provide some other solution.