# Track Shopify Refunds in Google Analytics

5 min setup

No coding required

Runs automatically

Gain valuable insights into product returns by tracking Shopify refunds in Google Analytics. This MESA workflow template triggers when a refund is issued, automatically calculating the total refund amount and logging it in GA4. By monitoring refund trends, you can identify frequently returned products, make improvements, or adjust your inventory, helping you optimize your product offerings and reduce future returns.

## How it works

4 steps to start tracking your Shopify refunds in Google Analytics automatically

### Refund Created

App connector: [Shopify](/content/apps/shopify/integrate "View Shopify integration page"/index.html)• Time to complete: 0 minutes (Auto-configured)

**Why this matters:** This trigger monitors your Shopify store for new refunds and kicks off the entire tracking process whenever a customer return is processed.

When a refund gets created in your Shopify admin, this trigger captures all the refund details including the original order ID, refunded line items, quantities, and transaction amounts. The trigger runs automatically in the background - no configuration needed from you. All refund data gets passed to the next step so the workflow can retrieve the complete order information needed for Google Analytics tracking.

### Retrieve Order

App connector: [Shopify](/content/apps/shopify/integrate "View Shopify integration page"/index.html)• Time to complete: 0 minutes (Auto-configured)

**Why this matters:** Google Analytics needs complete order details (customer info, currency, original line items) that aren’t included in the basic refund data from Shopify.

This step automatically fetches the full order record using the order ID from the refund trigger. It retrieves essential details like customer information, original line items, product IDs, pricing, and currency that Google Analytics requires for proper refund tracking. The retrieved order data gets combined with the refund information and passed to the calculation step. No configuration is needed since it uses the order ID from the previous trigger.

### Calculate Total Refund Amount

App connector: [Code](/content/apps/custom/integrate "View Code  integration page"/index.html)• Time to complete: 0 minutes (Auto-configured)

**Why this matters:** Google Analytics needs the exact refund amount calculated correctly from multiple transactions, which requires custom logic to process negative transaction values properly.

This custom JavaScript step loops through all refund transactions and calculates the total amount being refunded back to the customer. The script processes each transaction amount (which comes as negative values from Shopify) and converts them to the proper format for Google Analytics tracking. Here’s the complete code that handles this calculation:

```
const Mesa = require('vendor/Mesa.js');

/**
 * A Mesa Script exports a class with a script() method.
 */
module.exports = new class {

/**
   * Mesa Script
   *
   * @param {object} payload The payload data
   * @param {object} context Additional context about this task
   */
  script = (payload, context) => {
    const vars = context.steps;

// Add your custom code here
    // Line items from a Shopify Order Created trigger would be available as something like `vars.shopify.line_items`
    // Loop through transactions on the refund, and total up the refund amount
    const refundPayload = context.steps['shopify'];
    let refundAmount = 0;
    refundPayload.transactions.forEach(transaction => {
      refundAmount -= transaction.amount;
    });

// Add to payload
    payload.total_refund_amount = refundAmount;

// We're done, call the next step!
    Mesa.output.next(payload);
  }
}
```

The calculated total gets stored and passed to Google Analytics for accurate refund event tracking.

### Send Refund to Google Analytics

App connector: [Google Analytics](/content/apps/googleanalytics/integrate "View Google Analytics integration page"/index.html)• Time to complete: 2 minutes

**Why this matters:** This step sends the properly formatted refund data to Google Analytics so you can track return patterns and analyze which products are being refunded most frequently.

You’ll need to configure your Google Analytics connection by providing your Measurement ID (found in your GA4 property settings under “Data Streams”). The step automatically formats all the refund data including transaction ID, customer ID, currency, refund amount, and individual line item details into the proper GA4 refund event structure. Once connected, every refund will appear in your Google Analytics dashboard under Events > refund, allowing you to create custom reports and segments to analyze your return patterns. The workflow sends each refunded line item as a separate item in the refund event for detailed product-level tracking.

## Frequently asked questions

### What happens if a refund includes multiple items from the same order?

Each refunded line item gets tracked separately in Google Analytics with its own quantity and amount, giving you item-level visibility into what products are being returned most frequently.

### Can I track refunds for specific product variants separately?

Absolutely. The workflow sends individual line item details including variant IDs to Google Analytics, so you can analyze refund patterns down to specific sizes, colors, or product variations.

### Will partial refunds show the correct amount in Google Analytics?

Yes, the Calculate Total Refund Amount step processes all refund transactions and sends the exact partial refund amount to Google Analytics, not the original order total.

## Make this template your own!

Customize this workflow even further:

Add Slack notifications for high-value refunds

Set up conditions to notify your team via Slack when refunds exceed a certain dollar amount, helping you quickly address potential product quality issues.

Sync refund data to Google Sheets for detailed reporting

Connect a Google Sheets action to log every refund with additional details like refund reason, processing time, and customer history for deeper analysis.

Trigger email surveys for refunded customers

Add an email step that automatically sends customer feedback surveys to understand why products were returned and improve your offerings.

Create custom refund categories with data transformation

Use MESA’s transform features to categorize refunds by product type, price range, or return reason before sending to Google Analytics for more granular reporting.
