How to set up GA4 for an eCommerce platform

Care to share?

Google Analytics 4 (GA4) is the gold standard of website analytics solutions, and its vast capabilities need little introduction. However, GA4’s eCommerce module tends to be underused. Perhaps because of the fact that the recent migration from GA3 to GA4 was quite painful, some businesses decided to forego this extra feature.

This is a mistake. By giving up on those features, businesses let go of invaluable data that can play a big part in refining the customer experience they offer. There’s a lot to gain, and, as we’ll discover, the setup process doesn’t have to be difficult either.

Here’s a complete step-by-step guide on how to set up the solution for your eCommerce business and why it will be worth your time. 

Why should you implement GA4 eCommerce features for your business?

It’s difficult to imagine a modern eCommerce ecosystem that wouldn’t feature some sort of analytics capabilities. Monolithic systems come with such functionality built-in, while in the case of composable infrastructures, it’s one of the first modules that solutions engineers tend to implement. So, why the need to, in a way, double up on this by implementing another layer of analytics by Google?

The major problem with back-end eCommerce analytics is that they only kick in after some sort of conversion happens. They can help you track the total sales value, the most popular and profitable items, fluctuations in demand, cart abandonment statistics, and so on. However, as far as the default solutions are concerned, all this data exists in a vacuum. What was the journey that led your customer to conversion? Where did they come from? How did they behave while browsing your store? The system is blind to all of these nuances.

This is where GA4 with eCommerce features can become a game changer. When you tie eCommerce-specific statistics with user behavior that GA4 excels in tracking and analyzing, you get a much more complete picture of your business. This allows you to notice that, for instance, buying certain products correlates with a traffic source or that customers often buy product B but only after they first consider item A. Nuanced data like this can be an invaluable asset in fine-tuning your business strategy and marketing efforts.

GA4 eCommerce setup tutorial

Without further ado, let’s get to the meat of the article. Here’s everything you need to know to properly set up Google Analytics 4 with eCommerce features.

Step 1: Learn the basics of GA4

Learn how to create a Google Analytics account, a GA property, and a Google Tag Manager (GTM) container. This is a detailed and up-to-date video that describes the basic setup process. 

If you’re setting up the analytics for a store that’s a web app and the URL remains consistent across view changes, this process is a little more complex. You’ll need to implement some form of URL fragment, such as #suffix, that will change for each view to imitate the page_view event. You’ll also need to add another trigger called HistoryChange to the page view tag and configure it adequately to pass the changed URL to GA4. Here’s a complete guide for this corner case.

Step 2: Create GA4 properties

Create two GA4 properties. One will be for testing and one is for production. To ensure clarity, you can name them, for instance, “My Store [test]” and “My Store [production].”

Step 3: Expand the RegEx table

Add a RegEx Table variable in your GTM container and set it up like in the screenshot below. In our example, we’re naming it “Debug Mode.” The purpose of this setup is to detect a test server from the URL of the page using RegEx.

Google Analytics 4 RegEx table configuration

Step 3: RegEx table configuration

Step 4: Add a lookup table variable

Add a lookup table variable and name it, for instance, “Choose GA4 ID,” and set it up like in the screenshot below.

Google Analytics 4 Lookup table configuration

Step 4: Lookup table configuration

Step 5: Modify tags

Now, modify all tags that require the G-XXXXXX ID like on the screenshot below. The purpose of this step is to change the ID into a variable.

Google Analytics 4 Tag configuration

Step 5: Tag configuration

Step 6: Set up GTM

Set up your GTM for standard eCommerce tracking. Here’s a video tutorial that you can follow. 

For American readers, the process ends here. You’re all set up and ready to go. However, if the store owner is a European entity and subject to GDPR regulations, you’ll also need to go through the steps below to ensure compliance.

Step 7: Create a proxy server 

You need to set up a proxy server that is a paid “by traffic scale” solution hosted on the owner’s Google Cloud Platform (GCP). The purpose of this is to purge the user-related data from the GTM-to-GA4 payload. This can be done by setting up a second “server-side” tagging GTM container that will be running in parallel. Here’s a video tutorial on how to do it. 

It’s necessary for the GCP hosting to be done from the client’s account because, legally speaking, it becomes an extension of the client’s premises. This is what you agree to when you accept the terms of service for Google Ireland. If you’re thinking about providing this as a service on behalf of your client, you’ll need to sign the required agreements for storing and processing data with the client. This is a strictly technical tutorial, so I suggest consulting your legal department on this matter.

Step 8: Configure the GA4 tag

Configure the GA4 tag on the server-side container as shown in the screenshot below.

Google Analytics 4 Server-side container tag configuration

Step 8: Server-side container GA4 tag configuration

Step 9: Establish geolocation tracking

We have one last problem to solve: because we aren’t tracking IPs, we’re unable to track the user’s geolocation. In order to overcome this, we need to set up a workaround to fetch the location from the HTTP request headers. On the server-side container, create a variable, name it, for instance, “Visitor Region,” and configure it like in the screenshot below.

Google Analytics 4 Geolocation tracking variable 

Step 9: Geolocation tracking variable 

Step 10: Configure the server-side container

Lastly, configure the GA4 client on the server-side container as shown in the screenshot below.

 Configuration of the GA4 client on a server-side container

Step 10: Configuration of the GA4 client on a server-side container

That’s it. Your GA4 for eCommerce is fully set up, and you can start collecting and analyzing invaluable data related to your store’s performance and user behavior. 

What’s next?

Completing the technical setup is, in a way, just the beginning. Now comes the more difficult part: figuring out what kind of data you want to collect and how to use it. Each business is different, so these decisions will have to be individualized and, correspondingly, can’t be packaged into a neat step-by-step guide. 

That said, brainstorming those questions can pay off in a big way. Data-driven decisions will play a pivotal role in refining the experience that you offer to your customers, which, in turn, leads to increased engagement and conversions. When used to its full potential, data collected through GA4 can become the foundation for a major revolution in your eCommerce strategy, so don’t hesitate to make implementing the solution a priority for your business. If you’re looking for inspiration on what you can accomplish in terms of strategy, make sure to follow our newsletter for the latest insights on the eCommerce industry.

Sign up for Innovative eCommerce Newsletter



Published January 30, 2024