Quick overview
This workflow runs weekly to fetch customers from the Shopify Admin GraphQL API, calculate churn risk based on each customer’s median reorder interval, and then sync at-risk customers to Klaviyo while sending a CSV report and summary to Slack and/or Gmail.
How it works
- Runs weekly on a schedule and loads your Shopify domain, thresholds, and toggles for Klaviyo, Slack, and Gmail alerts.
- Queries the Shopify Admin GraphQL API in pages of 100 customers filtered by minimum order count and an order-date window that excludes very recent purchasers.
- Calculates each customer’s median days between recent orders, computes days since last order, and labels customers as MEDIUM or HIGH risk based on the days-since-last vs. median interval ratio.
- Stores at-risk customers across pagination and continues fetching until Shopify reports there are no more pages.
- Retrieves the full at-risk customer list, clears stored data for the next run, and stops if no at-risk customers are found.
- If enabled, updates each at-risk customer profile in Klaviyo by writing
churn_risk and days_since_last_order via the Klaviyo API.
- Generates a dated CSV of at-risk customers, aggregates counts and revenue-at-risk totals, and sends the summary with the CSV attached to Slack and/or Gmail.
Setup
- Add Shopify Admin API credentials (Header Auth) and set your
shopifyDomain value in the workflow configuration.
- Add a Klaviyo Private API key (HTTP Header Auth) if you want to sync profile properties to Klaviyo.
- Connect your Gmail OAuth2 credential and set the recipient email address if you want email alerts.
- Connect your Slack credential and set the target Slack channel ID if you want Slack alerts and error notifications.
- In the workflow configuration, enable or disable
emailAlert, slackAlert, and klaviyoEvent, and adjust minimumOrderRequired, customerActiveDays, and safeDays to match your store’s buying cycles.
Requirements
- Shopify store with Admin API access (GraphQL endpoint).
- Klaviyo account for profile updates.
- Slack workspace and Gmail account for reporting.