Skip to content
Home » Blog » How Do I Track Shopify ‘Add To Cart’ Clicks with Google Analytics 4?

How Do I Track Shopify ‘Add To Cart’ Clicks with Google Analytics 4?

To track Shopify “Add to Cart” clicks with Google Analytics 4 (GA4), you can use the following steps:

  1. Set up a Custom Event in GA4:
  • Log in to your GA4 account and go to the “Events” page.
  • Click on “New Event” and enter a name for your event, such as “Add to Cart”.
  • Under “Parameters”, add the following parameters: “value”, “currency”, “items”, “item_name”, “item_id”, “quantity”, and “price”.
  • Save the event.
  1. Set up a Tag in Google Tag Manager (GTM):
  • Create a new tag in GTM and select “Google Analytics: GA4 Event” as the tag type.
  • Enter your GA4 Measurement ID in the “Measurement ID” field.
  • Under “Event Parameters”, enter the following values:
    • “Event Name”: Enter the name of your custom event, such as “Add to Cart”.
    • “Items”: Enter “{{Click Element}}.dataset.product-id” (without quotes).
    • “Item Name”: Enter “{{Click Element}}.dataset.product-title” (without quotes).
    • “Item Price”: Enter “{{Click Element}}.dataset.product-price” (without quotes).
    • “Currency”: Enter “{{Click Element}}.dataset.currency” (without quotes).
    • “Value”: Enter “{{Click Element}}.dataset.product-price” (without quotes).
    • “Quantity”: Enter “1” (without quotes).
  • Set the trigger for the tag to fire on “Click – All Elements”.
  • Save the tag.
  1. Update the Shopify Code:
  • In your Shopify store, go to the “Online Store” section and click on “Themes”.
  • Click on “Actions” and then “Edit Code”.
  • In the “Snippets” folder, find “product-form.liquid” and open it.
  • Add the following code before the closing </form> tag:
<input type="hidden" name="product-id" value="{{ }}" data-product-id="{{ }}" data-product-title="{{ product.title }}" data-product-price="{{ product.price | money_without_currency }}" data-currency="{{ shop.currency }}" data-product-url="{{ product.url }}" data-event="add_to_cart">
  • This code adds a hidden input field with the relevant product data and triggers the “Add to Cart” event.
  • Save the changes.

Once you have completed these steps, GA4 will begin tracking “Add to Cart” clicks on your Shopify store. You can then use this data to analyze your ecommerce funnel and optimize your website for better conversion rates.