Stape

Server-side Google Analytics 4 for Magento

Updated
Nov 16, 2023
Published
Jun 21, 2023
Also available in

Google Analytics has long been a go-to tool for tracking and analyzing website data, providing valuable insights into user behavior and performance metrics. For Magento users, integrating GA4 into their server-side implementation can unlock a wealth of data and enable more precise tracking and reporting.

In this article, we will explore the benefits of server-side Google Analytics 4 for Magento and provide a step-by-step guide on setting up the Magento plugin, empowering you to harness the full potential of the e-commerce data.

stape server gtm plugin for magento

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

Here we would like to outline the benefits of implementing server-side GA4 for your Magento Store:

  • Enhanced Data Accuracy and Consistency. By capturing data directly from the server, it eliminates the reliance on client-side scripts, reducing the chances of data loss or discrepancies caused by ad blockers, browser settings, or user behavior. This ensures that your analytics reports provide a more reliable and comprehensive view of user interactions, allowing for more informed decision-making. 
  • Cross-Device and Cross-Platform Tracking. In today's multi-device and multi-channel world, customers interact with businesses through various touchpoints. Server-side tracking captures these interactions, allowing you to understand the entire customer journey, regardless of the device or platform used.
  • Increased Data Privacy and Compliance. Server-side GA4 implementation reduces the amount of personally identifiable information (PII) collected and transmitted to third-party platforms. This helps businesses adhere to data privacy regulations such as the General Data Protection Regulation (GDPR) and eases concerns about data security and user privacy. 
  • Flexibility and Customization. Now you have more control over the data you send to Google Analytics and can tailor the tracking to match your specific business requirements. This enables you to track custom events, attributes, and user interactions that are unique to your Magento store, allowing for deeper analysis and insights that align with your business objectives. 
  • Scalability and Performance. Server-side tracking offers scalability and improved performance, especially for high-traffic websites or complex e-commerce platforms like Magento. By offloading the tracking to the server, you reduce the burden on the client's browser, resulting in faster page load times and a smoother user experience. This is particularly beneficial for e-commerce sites where page speed directly impacts user engagement and conversion rates.

How to set up server-side Google Analytics 4 for MagentoCopy link to this section

3. The key feature of server-side tagging is setting first-party cookies. You need to use a custom tagging server URL to enable this feature. Custom tagging server URL or custom domain should share the same domain as your website. For example, if your website domain is example.com, then the tagging server URL should look like ss.example.com

If you want to add a custom domain, open the sGTM container on stape, scroll to the domains section, type the domain name, and click Add domain. Once done, you will see DNS records that you should add.

set up custom domain server side tagging 

 Below is an example of DNS setup for CloudFlare.

add DNS records server-side tagging
add DNS records ss tagging

 4. Go back to the Google Tag Manager Server container -> Choose your server container -> Admin -> container settings -> paste tagging server URL.

set tagging server url in gtm

Updating the Web GTM script on your website is highly recommended if you use a custom domain. This tweak will make gtm.js load from your domain. To do so, replace the default domain googletagmanager.com with the custom domain you set up in the previous step. 

update google tag manager script stape

5. 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.    

6. 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

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

8. 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

Implementing server-side Google Analytics 4 for Magento offers significant advantages and unlocks a new level of data-driven insights for e-commerce businesses. By shifting the tracking process to the server, businesses can achieve enhanced data accuracy, consistent tracking across devices and platforms, improved data privacy and compliance, customization options, and better scalability and performance. 

By following the step-by-step guide provided in this article, using Magento you can seamlessly set up server-side GA4 and harness the full potential of the e-commerce data.

Need help setting up server-side tracking?

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

Get help
Tagged with:gtm server

Host your GTM server at Stape