Hey there, I'm Benjamin from Loves Data.
In this video, I'm going to show you how to set up ecommerce tracking
in GA4, Google Analytics . The way you configure ecommerce tracking
will depend on how Google Analytics is implemented on your website.
If you're using Google Tag Manager, then you can use the data layer.
Or if you're using the Google Tag, gtag.js, you can modify the tracking code.
Before we get started, I want to briefly mention other options you
can use for ecommerce tracking.
For example, if you're using a hosted platform, like Squarespace,
then you can use their built-in Google Analytics integration to
send transaction details to GA4.
If you're using WordPress, then you can use a plugin.
Or if you're using Shopify, then you can implement Google Tag Manager,
the Google Tag, or wait until they provide built-in support for GA4.
Okay, to start, we're going to look at a custom implementation,
so let's head to my demo site...
My demo store is using Google Tag Manager to track transactions,
page views, and other actions.
So let's start by purchasing a product on my demo store.
I'm going to select a product...
Add it to my cart...
I'm going to view the cart...
Click 'Check Out'...
Enter my contact information...
Enter my shopping address...
Click 'Continue To Shipping'...
And click 'Continue To Payment'...
Now I'm going to enter payment details...
And click 'Pay Now'...
Our purchase is processed and we're now on the confirmation page...
Let's view the source code...
And let's search for 'datalayer'...
We can see the data layer that includes details for our transaction.
This is using the ecommerce schema for GA4 properties.
If you want to send information to Universal Analytics, then the
schema is slightly different.
If you're using Universal Analytics, then I've included
details in the extra resources in the description below this video.
The next thing we need to do is configure Google Tag Manager
to send these details to GA4.
So let's head to Google Tag Manager...
And let's select 'Tags'...
We can see there is already a GA4 Configuration tag in Google Tag Manager...
This tag automatically sends page views and other events to GA4.
If you're just getting started and haven't created a GA4 configuration
tag yet, then check out my GA4 and Google Tag Manager tutorials.
I've included links to these in the description below this video.
To send purchase details to GA4 we will need to add another tag.
So let's click 'New'...
Let's name the tag 'Google Analytics', 'GA4', 'Ecommerce'...
Let's select 'Tag Configuration'...
And let's choose 'GA4 Event' as the tag type...
We need to select our existing GA4 configuration tag using the drop-down...
Now there are a couple of ways you can approach ecommerce tracking.
The first option is to create each event separately in Google Tag Manager.
For example, we could name this event 'purchase'...
And this would then be used to send the final transaction details to GA4.
However, another option is to use a variable that will automatically pass the
type of ecommerce action to our event tag.
This means we can use a single tag to send 'add to cart', 'purchase',
and other ecommerce events to GA4.
We're going to use this approach, so let's click the variable
icon under 'Event Name'...
And let's choose 'Event'...
This will pass the name of the data layer event to our tag.
Now let's select 'More Settings'...
And let's enable the 'Send Ecommerce Data' option...
And let's leave 'Data Layer' selected...
This setting will automatically capture the ecommerce details from the data layer
and send them with our event to GA4.
Now we need to add a trigger to our tag.
Let's select 'Triggering'...
We need to create a trigger that will only fire our tag for ecommerce
actions, so let's click the blue plus sign on the top right corner...
Let's name the trigger 'GA4 Ecommerce Events'...
And let's select 'Trigger Configuration'...
Scroll down...
And choose 'Custom Event' as the trigger type...
Now we need to enter the data layer event names that we want to use to fire our tag.
Google has a list of recommended ecommerce events, so we can enter them all here...
You will notice each one is separated by a 'pipe'.
So let's enable the 'User Regex Matching' option...
This means that the pipes will be recognized as regular expressions.
And as a regular expression a pipe is use to create an 'Or' statement.
So this means we will be matching any of these ecommerce events.
If you only want to trigger your GA4 event tag for some of these events, then feel
free to adjust the regular expression.
Okay, now let's save the trigger...
And let's save the tag...
Now
let's preview our new GA4 tag.
Let's click 'Preview'...
And enter the URL of our store...
We
can see Tag Assistant has loaded, so now we can add another item to our
cart...
Enter our details...
Click 'Continue To Shipping'...
Click 'Continue To Payment'...
Enter our payment details...
And
click 'Pay Now'...
Our purchase is processed and we're on the confirmation page...
Now we can check to see that the tag has fired, so let's
select the Tag Assistant tab...
We can select the purchase event...
And select the tag...
We can also select the GA4 measurement ID at the top to see the purchase event...
And we can also head to Google Analytics...
And open the DebugView...
This lets us check that the details are being correctly
passed to Google Analytics...
Again, we can see our purchase event has come through to GA4.
So that's how we can use a data layer to capture ecommerce
details and send them to GA4.
But what if we're not using Google Tag Manager and we're using the
Google Tag, gtag.js, instead?
Well, in this case, we need to modify the Google Tag when a transaction takes place.
Let's head to the back-end of the platform I use to host my online
courses to see how this works...
Now we could of course use Google Tag Manager and a custom data layer
as we've already covered, but I also want to show you how to modify the
Google Tag to track transactions.
So here we can add code to the page people see after they've made a purchase.
I've already added the standard gtag.js code...
Now we can head to Google Developers...
And grab the example ecommerce tracking code...
Now I can adjust the code...
And enter the liquid markup variables that will populate the
transaction details into our code...
The
way you do this will depend on the platform you're using, so I recommend
checking out the documentation for your platform and even contact
support for your platform to get help setting up Google Analytics correctly.
Remember, the method you use to track purchases will depend on how Google
Analytics is implemented on your store.
You can use Google Tag Manager with a data layer, modify the Google Tag, use
a built-in integration, or use a plugin.
I've also includes links to my dedicated tutorials covering Shopify,
Woocommerce, Squarespace, and Thinkific in the description below this video.
Are you tracking purchases into GA4?
I'd love to know!
Let me know in the comments below.
And if you found this video helpful, please like it so I know
to make more videos like this one.
Thanks for watching and I'll see you in the next video.