Complete guide how to setup GA4 on Shopify
Step 12. How to implement GA4 view_cart event in Shopify
To be able to analyze in Google Analytics 4(GA4) traffic on your pages and report for example when a user views the cart you have to implement GA4 view_cart event.
Below, you will find instructions on how to do it using Google Tag Manager and data layer variables in Shopify.
- Implement data layer variables in Shopify.
In this step we implement products data layer variables into Shopify template. These variables we use later in GTM to sent them to Google Analytics every time when user visit Shopify product page. Let’s go to your Shopify Admin to edit your theme.liquid template. (Online Store>Themes>Edit your template code>theme.liquid).
Inside your section, before the part about GTM, paste the following data layer code:
{% if template contains 'cart' %}
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'view_cart',
'value': {{cart.total_price| times: 0.01}},
'items': [
{% for item in cart.items %}
{
'item_id': '{{item.id}}',
'item_name': '{{item.title}}',
'quantity': '{{item.quantity}}',
'price': '{{ item.price | times: 0.01 }}'
},
{% endfor %}
]
});
{% endif %} - Create trigger that we use to fire view_cart tag. Go to trigger section and create new trigger:
- Create new “CE – view_cart” trigger as follow:
- Create GA4 – view_cart tag in Google Tag Manger. Go to “Tags” and click “New” button to add new tag.
Name it "GA4 – view_cart", then choose tag type and select "Google Analytics: GA4 Event", and your configuration tag that you have already created here: How to implement GA4 Configuration tag in Google Tag Manager? and set "Event Name" to "GA4 – view_cart.
Next step is to setup "Event Parameters" and then choose your trigger, that you have already created a while before (CE – view_cart) and click "Save" button on the top right corner, and click "Submit" to published.
Lets go now to the next step of our guide which is: How to implement GA4 remove_from_cart event in Shopify
If you enjoyed the content please share it:
If you have any question about this topic feel free to comment or react below.
This guide is all about how to implement Google Analytics(GA4) on Shopify. To setup GA4 on Shopify website we use Google Tag Manger(GTM) and Shopify data layer.

If you want to measure traffic on your Shopify website, the first thing is to create Google Analytics account for your website


If you have Google Account but you don't have GA4 property yet, because for example you are still using Universal Analytics property (former version of GA4) you have to create new GA4 property.


Because we will use Google Tag Manger as a method to implement Google Analytics 4 you have to create GTM account.


If you want to get the best out of Google Analytics 4 apply the following recommended GA4 settings and best practices.


Environment - is a set of necessary elements of technical / software infrastructure, which is the basis for the operation of a given website/application. Google Tag Manager environments are simply multiple versions of the same container. When we have a website with a different version for development, testing, production and QA, instead of creating separate GTM containers for each version, we can set up separate environments in the same container that will work independently in each version.


Some time ago I listened to a podcast from the Technical Marketing Handbook series from Simo Ahava, whose guest was Adam Halbardier from the Google Tag Manager product team. During the conversation, the topic of transparency of data handled by the Server-Side container appeared.


If you plan email marketing campaigns you are interested in the same as with other campaigns, to measure their impact on your business. When you are starting with this topic it is good to know that without additional effort you will not be able to access this impact. You will see no results because Google Analytics will treat traffic from the email campaigns as direct traffic (when users are using your own app) or as referrals (when users are using web email clients).
