Shopify Flow/Catalog & Merchandising/Track 30-Day Customer Revenue with an Automated Metafield
Operational EfficiencyMedium Difficulty

Track 30-Day Customer Revenue with an Automated Metafield

This Flow automatically calculates and stores a customer's total spending from the past 30 days in a dedicated metafield each time they place a new order.

The Problem

Without a clear, real-time view of recent customer spending, merchants often miss critical opportunities to engage high-value buyers or intervene with at-risk customers. Manually extracting and calculating this data is time-consuming and prone to errors, hindering agile marketing and personalized customer experiences.

What This Automation Solves

This Shopify Flow triggers on every `Order created`, removing manual data extraction. It leverages an `advanced query` to efficiently gather all recent orders for that specific customer, then accurately `sums` their `currentTotalPriceSet.shopMoney.amount`. The result is automatically stored in a `customer metafield` (`custom.revenue_last_30_days`), providing an always-current data point for segmentation and personalization.

When to Use This Automation

  • Identify customers who have recently spent significant amounts for targeted upsell or VIP offers.
  • Segment customers whose 30-day spending has dropped, indicating potential churn, for re-engagement campaigns.
  • Create dynamic content in email or SMS marketing that acknowledges a customer's recent value.
  • Empower customer service to quickly see a customer's recent purchase history at a glance.

Workflow

  1. Trigger

    Step 1

    This workflow starts when a new order is created

  2. Action

    Step 2

    Get orders using an advanced query

  3. Count

    Step 3

    Calculate the sum of getOrderData.currentTotalPriceSet.shopMoney.amount

  4. Action

    Step 4

    Add metafield to the customer: custom.revenue_last_30_days

Step-by-Step Setup

  1. 1

    Start with the 'Order created' trigger.

  2. 2

    Add a 'Get order data' action. Configure the advanced query for `customer.id = {{customer.id}} AND created_at > -30d`.

  3. 3

    Add a 'Sum' action, applying it to `getOrderData.currentTotalPriceSet.shopMoney.amount`.

  4. 4

    Add an 'Update customer metafield' action, setting the key `custom.revenue_last_30_days` to the result of your sum.

  5. 5

    Save and activate your workflow.

Related Questions

Can I track revenue for a different period, like 60 or 90 days?
Yes, simply adjust the advanced query in the 'Get order data' action (e.g., `created_at > -60d`) and update the metafield key to reflect the new period (e.g., `custom.revenue_last_60_days`).
How can I use this metafield for customer segmentation?
Once the `custom.revenue_last_30_days` metafield is populated, you can use it directly within Shopify's customer segments to filter by recent spending, or export it for use in email platforms like Klaviyo or Omnisend.
Will this calculation include refunded orders?
The 'currentTotalPriceSet' typically reflects the order's value at the time of creation. For more precise net revenue considering refunds, you would need additional logic or a different field, which is not directly supported by this basic sum.
Does this workflow run for all past orders?
No, this workflow is triggered only when a *new* order is created. To populate this metafield for your existing customer base, you would need to run a one-time backfill script or a separate Flow that iterates through all customers.

Recommended Tools & Apps

Launch this automation

Open Shopify Flow and use this page as your setup blueprint.

Open Shopify Flow

Merchant Insight

Use this `custom.revenue_last_30_days` metafield to create 'VIP in the making' customer segments. Anyone with recent high spend who hasn't yet crossed your overall VIP threshold can receive a targeted nurture campaign to encourage that next

Related Automations