by ShahzadaAliHassan - 6th November 2023
This blog will walk you through the process of configuring the purchase event for Google Analytics 4 (GA4) on a Shopify store usin Google Tag Manager. We'll look into how to set up the necessary tools and tags to ensure that you can track Shopify purchases and gather valuable insights about your traffic acquisition and user behavior.
Before we dive into the setup, make sure you have the following accounts and configurations ready:
If you haven't set these up yet, you can refer to this page.
Tip: Ensure you have your prerequisites in place for a smooth setup process.
The first step is to set up the GA4 Configuration Tag. This tag is essential for tracking general events such as user engagement, session start, etc. These events are automatically configured by Google Analytics.
Head over to your Google Analytics account.
On the bottom left corner, click 'Admin'.
In the properties column, click on 'Data Stream'.
Copy the 'Measurement ID' from your web data stream. If you don't have a data stream set up, click on the blue 'Add Stream' button to create one.
Go to Google Tag Manager and create a variable for your Measurement ID. This makes it easier to refer to it later without having to copy and paste the value repeatedly.
Create a new tag in Google Tag Manager, set it to fire on all pages of your Shopify store, and send the 'page_view' event.
After configuring the tag, use the 'Preview' mode in Google Tag Manager to test if the 'page_view' event is firing correctly on all pages of your Shopify store. You should be able to see the events in the debug window as well as in your Google Analytics account.
The provided guidelines detail the integration process of the dataLayer
object from Google Tag Manager (GTM) into a Shopify storefront. This integration's primary objective is to trigger a custom_purchase
event each time a user lands on the /thank-you/ page of Shopify following a transaction.
first_time_accessed
), the script identifies if the visitor is an existing customer and, if so, retrieves their total number of orders and expenditure.dataLayer
object, if not already in place, and fills it with transactional information such as transaction ID, total amount, shipping costs, taxes, currency, and details of the purchased items.Sign in to Shopify Admin:
/admin
.Navigate to Checkout Configurations:
Settings
from the menu on the left.Checkout
from the ensuing options.Find the Additional Scripts Area:
Order processing
section and scroll to it.Insert Your Script:
Additional Scripts
input box.Confirm Your Changes:
Save
.Verify Script Functionality (Crucial):
dataLayer
as per your script.Note: The 'Additional Scripts' section in the Checkout settings is specifically designed for post-purchase script implementations like conversion tracking, analytical scripts, or other triggers activated after a sale is confirmed.
To accurately track these events, we need to set up appropriate triggers and tags in Google Tag Manager.
For additional tracking details, such as items, revenue, etc., Google Tag Manager's latest version introduces Ga4 event parameters, similar to setting variables in Universal Analytics.
Search for "Google tag event settings".
You'll encounter dataLayer parameters: items, and value.
For items, currency and value, refer to the Data Layer and create dataLayer varibale for each.
Name it DLV items
and DLV value
.
Name this
event setting as GTES GA4 EEC Event parameters
.
For currency, navigate to the GTM debug window. Within the ecommerce
section, you'll find the currency
parameter. Click on the "+" icon to create a new data layer variable. This should be named ecommerce.currency
.
Similarly, establish variables for tax
and shipping
. By setting these up in GTM, it ensures that these values get tracked without needing additional processing in G4. Other crucial details include items
, value
, currency
, tax
, shipping
, and transaction_id
.
Tip: Ensure all necessary parameters are sent correctly to Ga4. When done right, GA4 will handle report generation and conversions automatically.
CE custom_purchase
and set the value to "custom_purchase".Tip: Using a 'custom_' prefix ensures that the 'purchase' does not mix with any other events on your website.
CE custom_purchase
.Google Analytics 4 Event Tag
.GA4 Measurement ID
matches the one created at the beginning of this blog.GTES GA4 EEC Event parameters
.By default, with GTM and a basic Shopify account, the /checkout
route isn't accessible. This means tracking events such as 'Add Shipping Info', 'Add Payment Info', or the 'Begin Checkout' event can be challenging.
However, as discussed in a previous blog, you can workaround this limitation by hijacking button click events on your site. For those who missed that insightful blog, read it here.
To verify the functionality of your tags:
While on the /checkout
page, note that this isn't tracked by default in Ga4. On completion of the purchase, redirect to the 'Thank You' page. In the debug window, you should see the custom purchase event trigger alongside the G4 e-commerce purchase tag.
In Google Analytics, under Admin > Debug View
, you can check recent events. The purchase event should show with a flag, signifying its role as a default conversion.
Tip: The purchase event is a default conversion in G4. There's no need for additional configurations.
Real-time reports in Google Analytics provide instant insights, but they won't show the items array. However, other valuable details like path
, currency
, and tax
are available.
Lastly, ensure you publish all changes on GTM to move them out of draft mode and onto your live site. While Ga4 processes the data, e-commerce reports will become available, generally within 24 hours.