How to Create GTM Triggers to Monitor Abandoned Shopping Carts on Your Shopify Site

Hello everyone, Deviate Tracking here, and today we’re going to walk you through the process of creating GTM (Google Tag Manager) triggers to monitor abandoned shopping cart recovery on your Shopify site. Abandoned shopping carts are a nuisance for online sellers, but fortunately, you can use GTM triggers to keep track of them and improve your shop’s performance. So, let’s dive in!

Step 1: Create a Custom Event in GTM
First, you need to create a custom event in Google Tag Manager that will send data when a user abandons their shopping cart.

1. Log in to your GTM account and navigate to your desired container.
2. Click on “Tags” -> “New.”
3. In the “Tag Configuration” section, select “Custom HTML” as the tag type.
4. Paste the following JavaScript code:

(function() {
if (window.location.href.indexOf('/cart') > -1) {
window.addEventListener('beforeunload', function() {
'event': 'abandoned_cart',
'cart_url': window.location.href

This code listens for when the user leaves the cart page and pushes an event called “abandoned_cart” to the Data Layer.

5. Set the trigger for this tag to “All Pages” so it is always loaded regardless of the page the user is on.
6. Save and publish your changes.

Step 2: Configure a GTM Trigger for the Event
Now, let’s create a GTM trigger that will fire when the “abandoned_cart” event occurs.

1. Click on “Triggers” -> “New.”
2. In the “Trigger Configuration” section, select “Custom Event.”
3. In the “Event Name” field, enter “abandoned_cart” (this should match the event name pushed in the JavaScript code from Step 1).
4. Set the trigger to fire on “Some Custom Events.”
5. Add a condition that checks if the URL of the abandoned cart page contains “/cart.”
6. Save and publish your changes.

Step 3: Create and Configure a Tag to Track Abandoned Carts
Once the trigger is set up, you will need a tag to collect information about the abandoned carts.

1. Go to “Tags” -> “New”.
2. In the “Tag Configuration” section, select “Google Analytics: Universal Analytics” (if you’re using Google Analytics 4, choose “GA4 Configuration” instead).
3. Set the track type to “Event,” and fill in the event category, action, and label. For example:
– Category: “Shopping Cart”
– Action: “Abandoned Cart”
– Label: “” (to capture the URL of the abandoned cart page)
4. In the “Google Analytics Settings” field, select your Google Analytics variable or enter your tracking ID.
5. In the “Triggering” section, choose the trigger you created in Step 2.
6. Save and publish your changes.

By following these steps, you’ve successfully installed JavaScript code within a GTM tag to monitor abandoned shopping carts on your Shopify site. GTM will now trigger an event and collect data when a user abandons their cart, which you can analyze in Google Analytics to adjust your marketing strategies accordingly.

And that’s a wrap! If you have any questions or need further assistance, please feel free to drop a comment or reach out. Good luck and happy tracking!