Complete guide how to setup GA4 on Shopify

Step 11. How to implement add_to_cart event on Shopify

Published by
Oct 23, 2022

When you analyze traffic on your Shopify ecommerce is good to know how often users add to cart your products.

To be able to track it you have to implement add_to_cart event using Google Tag Manager and data layer variables.

  1. Implement data layer variables in Shopify.
    Actually if you have implemented properly variables as was described here: How to implement GA4 view_item event in Shopify. you already have all needed data in data layer that have to be sent to GA4.
    However you need to implement event variable to be able to create add_to_cart trigger. To do that you have to add to your "add to cart" button additional java script code. You have to find in your Shopify admin > Online store > Themes code snippet responsible for presenting add to cart button. Good place to start finding it, is to go to the product.liquid template and look for add to cart button section. It can be included in additional section template like: "product-form.liquid" or "product-info.liquid".
    When you find this button you need to add in this button code following code:
    dataLayer.push({'event': 'add_to_cart'});
  2. Create "CE – add_to_cart and Dom ready" trigger.
    We will use it to fire add_to_cart tag. Go to trigger section and create new trigger, clicking "New" button

    Create “CE – add_to_cart and Dom ready

    and create new CE – add_to_cart trigger as follow:
    new add_to_cart trigger

  3. Create GA4 – add_to_cart tag in Google Tag Manger.
    Go to “Tags” and click “New” button to add new tag and name like “GA4 – add_to_cart”

    Create GA4 – add_to_cart tag in Google Tag Manger.

    then choose tag type and select “Google Analytics: GA4 Event"

    Google Analytics: GA4 Event

    then choose your configuration tag that you have already created here: 
    How to implement GA4 Configuration tag in Google Tag Manager?

    GTM view item configuration.

    and set "Event Name" to "add_to_cart"
    then setup "Event Parameters" as followAdd_cart event parameters.then choose your trigger that you have already created a while before (CE – add_to_cart).
    trigger add to cart shopif gtm tag.and click "Save" button on the top right corner.

  4. After this implementation you will be able to see in GA4 statistics about add to cart action.

    GA4 add_to_cart event.

    Lets go now to the next step of our guide which is: How to implement GA4 view_cart event in Shopify
Published Oct 23, 2022 by Piotr Ulacha

Information About the Authors

Piotr Ulacha

Piotr Ulacha is a web analyst. He has 15 years of experience in the digital marketing area. He specializes in implementation of analytical and marketing tracking codes, creating dashboards and data privacy topic. He works currently as a Web Analyst at EverStores.com where he implement tracking solutions for eCommerce brands. Previusly he worked at SellerX with eCommerce brands and at Artegence where he analyses the impact of marketing campaigns for Volkswagen Poland.


If you enjoyed the article please share it:

Other articles about Shopify
Complete guide how to setup GA4 on Shopify.

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.

Oct 12, 2022
1. How to create Google Analytics account for Shopify website

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

Published by Piotr Ulacha
Oct 13, 2022
2. How to create Google Analytics (GA4) property for Shopify 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.

Published by Piotr Ulacha
Oct 14, 2022
3. How to create Google Tag Manager account for Shopify website

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

Published by Piotr Ulacha
Oct 15, 2022

4. Recommended GA4 property settings for Shopify

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

Published by Piotr Ulacha
Oct 16, 2022