Autonomous Email Marketing Engine
A Shopify merchant with a large customer base was spending hours every week on manual email marketing — segmenting lists, writing copy, choosing products to feature, and deciding who should get discounts.
The Challenge
Email marketing platforms like Klaviyo and Mailchimp give merchants tools — but they still require significant manual effort. Someone has to define customer segments, write email copy, decide which products to feature, set discount strategies, and optimize send timing. For a store with tens of thousands of customers, doing this well is a full-time job.
The merchant wanted something different: an email system that could make intelligent decisions autonomously, learning from customer behavior and adapting its strategy without constant human intervention.
The Approach
I built a full-stack email marketing engine deeply integrated with Shopify — not a plugin or template, but a custom platform that handles the entire campaign lifecycle from segmentation to send.
ML-Powered Customer Intelligence
The system builds a comprehensive profile of every customer using multiple ML models:
- RFM segmentation — Recency, Frequency, and Monetary scoring places each customer into segments like “Champions,” “At Risk,” or “Lost,” using KMeans clustering
- Churn prediction — a Random Forest model predicts which customers are likely to stop purchasing, allowing preemptive re-engagement
- Behavioral signals — a Shopify web pixel captures storefront browsing events (product views, collection browsing, cart activity), feeding real-time intent signals into customer profiles
AI Decision Engine
For each potential email send, the system uses Claude with Structured Outputs to make a series of decisions:
- Should this customer receive an email? — based on engagement history, recent purchases, and unsubscribe risk
- What type of campaign? — re-engagement, upsell, winback, product recommendation, or welcome sequence
- What tone and content? — professional, friendly, urgent, or conversational, matched to the customer’s segment
- Should a discount be offered, and how much? — with configurable guardrails to prevent over-discounting
If the AI decision fails (network error, model timeout), the system falls back to rule-based defaults rather than skipping the customer entirely.
Journey Engine
Beyond one-off campaigns, the system orchestrates multi-step email sequences:
- Welcome series — triggered automatically when Shopify creates a new customer
- Scheduled sequences — recurring campaigns at configurable intervals
- Per-customer state tracking — knows exactly where each customer is in each journey
- Reply handling — a SendGrid inbound webhook captures customer replies, matches them to the original campaign, and surfaces them in a Reply Inbox
Post-Purchase Upsell
A Shopify checkout extension presents personalized product offers in the 3-second post-purchase window. The offer selection uses product affinity scoring (based on co-purchase patterns), excludes previously offered items, and signs the offer payload with JWT to prevent tampering. Conversion is tracked end-to-end.
Compliance Built In
Email compliance isn’t optional. The system implements RFC 8058 one-click unsubscribe headers, maintains a consent ledger with full audit trail, handles GDPR deletion workflows via Shopify webhooks, and enforces CAN-SPAM requirements on every send.
The Results
The platform runs autonomously — segmenting customers, generating personalized campaigns, and making send decisions without merchant intervention. The merchant can review and approve campaigns at any autonomy level: manual approval for every send, one-click approval with confidence thresholds, or fully automatic (gated behind a minimum number of approved campaigns to build trust).
The system is built as a white-label platform with multi-tenant architecture, deployed on Railway with the Shopify app embedded directly in the admin sidebar. The intelligence engine (Python/FastAPI) communicates with the Shopify app (Remix) over private networking, with 54 database migrations tracking the evolution from basic segmentation to full journey orchestration.
Services: AI Agent Development · AI Workflow Automation