Email automation is one of the most powerful levers for scaling a Shopify store. Klaviyo already provides excellent segmentation tools, but when you combine it with Shopify's event-driven webhooks and a Node.js middleware, you unlock real-time personalization that standard built-in integrations cannot match.
In this technical guide, we'll walk you through how Shopify events (orders, carts, customers) can be captured in Node.js and then sent to Klaviyo to trigger personalized flows instantly. You'll learn the architecture, the event flow, and how to validate Shopify webhooks, how to send structured events to Klaviyo's API, with a code example.
This is ideal for teams building custom automation, advanced retention workflows, or a headless commerce experience. Many businesses partner with experienced Shopify Experts when building scalable automation like this, since the solution often combines backend engineering, Shopify API knowledge, and CRM logic.
1. Why Event-Driven Automation Matters
Traditional email automation relies on time triggers, for example, sending a welcome email after signup or a post-purchase sequence after payment. But modern ecommerce flows require real-time responsiveness:
Send the order confirmation immediately upon checkout.
- Trigger Klaviyo to send personalized recommendations based on purchased items.
- Notify customers when an order is fulfilled or delayed.
- Send abandoned checkout emails with real cart data.
- Trigger subscription-specific workflows (for change orders)
Using Shopify-Node.js-Klaviyo gives businesses full control over event data and custom triggers that aren't possible through native connectors.
2. Architecture Overview
Here's the architecture of the event driven system:
1. Shopify Store
Emits events via webhooks:
orders/createorders/fulfilledcheckout/createcustomers/createcarts/update
2. Node.js Middleware
This service handles:
- HMAC verification of webhook integrity
- Parsing and transforming event data
- Sending formatted events to Klaviyo through their API
- logging, queuing, retires
3. Klaviyo
Receives events and triggers:
- Flows
- Segmentation
- Product recommendations
- Transactional templates It's a reliable and lightweight architecture that works for any Shopify merchant.
3. Step-by-Step Implementation Tutorial
Step 1: Create Webhooks in Shopify Admin
Go to:
Shopify Admin - Settings - Notifications -Webhooks
Add a new webhook:
Event: Orders Create
Format: JSON
URL: https://yourdomain.com/webhooks/orders-create
Do this for any event you want to automate.
Step 2: Build the node.js Webhook Receiver
Install Dependencies:
https://yourdomain.com/webhooks/orders-create
Create a server
import express from "express";
import crypto from "crypto";
import bodyParser from "body-parser";
const app = express();
app.use(bodyParser.raw({ type: "application/json" }));
const SHOPIFY_SECRET = process.env.SHOPIFY_SECRET;
HMAC Validation (Required for Security)
function verifyHmac(req) {
const hmacHeader = req.headers["x-shopify-hmac-sha256"];
const digest = crypto
.createHmac("sha256", SHOPIFY_SECRET)
.update(req.body, "utf8")
.digest("base64");
return digest === hmacHeader;
}
Webhook Endpoint
app.post("/webhooks/orders-create", async (req, res) => {
if (!verifyHmac(req)) return res.status(401).send("Unauthorized");
const orderData = JSON.parse(req.body.toString());
await sendEventToKlaviyo(orderData);
res.status(200).send("OK");
});
This Ensures:
- Shopify's data is verified
- The system processes the order instantly
- Klaviyo receives structured event data
Step 3: Create a Function to Send Event Data to Klaviyo
Klaviyo requires events in a specific JSON format.
import axios from "axios";
async function sendEventToKlaviyo(order) {
const payload = {
data: {
type: "event",
attributes: {
metric: { name: "Order Placed" },
properties: {
order_id: order.id,
total_price: order.total_price,
line_items: order.line_items
},
profile: {
email: order.email,
phone_number: order.phone,
first_name: order.customer?.first_name
}
}
}
};
await axios.post("https://a.klaviyo.com/api/events/", payload, {
headers: {
Authorization: `Klaviyo-API-Key ${process.env.KLAVIYO_KEY}`,
"Content-Type": "application/json"
}
});
}
Every Shopify order now automatically triggers a Klaviyo metric event.
That metric can trigger:
- Transactional emails
- Upsells flows
- Product education flows
- VIP segmentation
This is far more flexible than native integrations.
Step 4: Build Klaviyo Flow Based on Custom Events
Inside Klaviyo:
- Go to Flows
- Create a new Flow
- Choose Metric Trigger
- Select Order Placed (Custom Event)
Now you can build:
- Personalized order confirmations
- Follow-ups based on items purchased
- "How to use your product" sequence
- Customer segmentation based on AOV
4. Handing Other Events
You can repeat the same process for:
1. Abandon Checkout
Webhook: checkouts/create
2. Customer Signup
Webhook: customers/create
3. Order Fulfilled
Webhook: orders/fulfilled
5. Adding Queue Processing (Optional but recommended)
For a high-volume store, use:
- Reis+BullMQ
- RabbitMQ
- AWS QSQ `import Queue from "bull";
const eventQueue = new Queue("klaviyo-events");
eventQueue.process(async (job) => {
await sendEventToKlaviyo(job.data);
});
6. Why Companies Use Custom Integrations Like This
Native Shopify -Klaviyo integration is good but:
- It doesn't allow advanced personalization.
- It cannot reformat event data dynamically.
- It doesn't allow multi-store or multi-location rules.
- It doesn't support additional APIs (ERP, CRM, backend).
- It cannot create custom metrics for flows.
That’s why brands building event-driven automation often Hire dedicated Shopify Developer teams to build and maintain advanced backend workflows.
8. Conclusion
Integrating Shopify, Node.js, and Klaviyo enables a scalable, real-time email automation system that responds instantly to customer behavior. This architecture supports personalization, higher conversion rates, and lifecycle marketing automation beyond what native tools provide.
More established brands often collaborate with Shopify experts to ensure data quality, security, webhook reliability, and scalable code structure. With proper design, this system becomes a long-term engine for retention, automated revenue, and customer loyalty.
Top comments (0)