Back to Shopify Flow

Setup guide

Klaviyo Smart Engagement Flow

Build the Klaviyo flow that sends the AI-composed emails written by llea.ai’s AI Composer, then reports whether each one was received, opened, and clicked back to llea.ai’s own API.

1. What this flow does

This flow connects the llea.ai AI Composer tool inside Shopify to Klaviyo, so that every time llea.ai’s AI drafts and sends a personalized “Smart Engagement” email to a customer, Klaviyo automatically sends that exact AI-written email and then reports back to llea.ai, in real time, whether the email was received, opened, and clicked.

In sequence, the flow does four things: it sends the AI-composed email, waits a few minutes, then checks engagement in stages (received, then opened, then clicked) and after each stage that succeeds it calls a webhook back to llea.ai’s API (api.llea.ai) so the platform always knows how each AI-sent email actually performed.

Why a webhook, not just Klaviyo analytics?

llea.ai AI Composer lives outside Klaviyo. The only way it can learn whether its own AI-written emails are landing, being opened, or being clicked is if Klaviyo actively reports back, hence a webhook call at every engagement milestone, aimed at llea.ai’s own API.

How the flow behaves

Each engagement check only runs if the one before it said “yes”, a drill-down funnel, not three independent checks. Every “yes” also reports back to llea.ai before the flow moves on:

Trigger firesllea_smart_engagementSend the AI-written emailsubject + preview text + bodyWait 5 minutesReceived the email?NoNo further actionYesTell Llea: receivedOpened it?NoNo further actionYesTell Llea: openedWait 5 more minutesClicked it?NoNo further actionYesTell Llea: clickedFlow complete
Each “opened” check only runs after “received” says yes, and each “clicked” check only runs after “opened” says yes, a drill-down funnel, not three independent checks. Every “yes” also reports back to Llea before the flow moves on.

2. Prerequisites

  • Admin access to your Shopify store running the llea.ai app.
  • Admin access to the Klaviyo account connected to that store.
  • The llea.ai app’s own Settings → Manage panel for the Klaviyo integration must be reachable; it supplies the exact webhook Destination URL and JSON payload template used three times in this guide.
  • A test customer record (with a real inbox you can check) to preview and send the initial test email.

3. Step-by-step setup

The full build is 131 recorded steps, grouped into eight parts. Work through them in order; each part builds on the one before it.

Part 1 – Fire the trigger event

Before the Klaviyo flow can be built, Klaviyo needs to have seen at least one llea_smart_engagement event; otherwise it won’t offer that metric as a trigger option. This part sends one such test event.

Do this before building the flow

You need to fire a test event from llea.ai AI Composer to receive the llea_smart_engagement trigger in Klaviyo. Do this before building the flow in Part 2.

  1. Step 1In the Shopify admin, open the llea.ai app and go to AI Composer.
  2. Step 2Select the Smart Engagement tool (“AI continuously finds the right customers and products, then writes a personalized email, subject and body included”).
  3. Step 3Click Preview.
  4. Step 4Click Select a customer, then search for a test recipient (e.g. type part of their name).
  5. Step 5Click the matching customer to select them as the preview recipient.
  6. Step 6Click Send test.
  7. Step 7Click Proceed & send to confirm.

This sends a live test email through Klaviyo and creates the llea_smart_engagement metric/event that the flow will listen for in Part 2.

Part 2 – Create the flow and trigger

  1. Step 8Switch to the Klaviyo browser tab and open Flows.
  2. Step 9Click Create flow.
  3. Step 10Click Build your own (a blank flow, not a template).
  4. Step 11Click the Name field and type llea_smart_engagement.
  5. Step 12Click Create flow.
  6. Step 13On the trigger card, click All triggers.
  7. Step 14Click Metric.
  8. Step 15Select llea_smart_engagement from the metric list (Klaviyo will only list it here after the test event from Part 1 has landed).
  9. Step 16Click Save.
  10. Step 17Click Confirm and save. Klaviyo warns that the trigger can’t be changed after saving; that’s expected.

Part 3 – Build the AI-personalized email

This adds the Email action that actually sends the AI-composed message. Rather than writing static copy, the email pulls its subject, preview text, and body straight from the trigger event’s payload using Klaviyo Liquid tags.

  1. Step 18Click the + (Add action) icon under the trigger.
  2. Step 19Click Email.
  3. Step 20Click the Email name field and type llea_smart_engagement.
  4. Step 21Click the Subject line field.
  5. Step 22Click the Subject line field again to place the cursor, then press Backspace to clear the default text.
  6. Step 23Type {{event.subject}}, which pulls the AI-written subject line from the event that triggered the flow.
  7. Step 24Click the Preview text field.
  8. Step 25Type {{event.previewText}}.
  9. Step 26Click Save.
  10. Step 27Click Set up email.
  11. Step 28Open the menu on the email action card.
  12. Step 29Click Edit.
  13. Step 30Click Drag and drop (the visual editor).
  14. Step 31Click Create to start from a blank template.
  15. Step 32Click the add-content icon on the blank template, then click Add content.
  16. Step 33Click Text to add a text content block.
  17. Step 34Click the new text block to open Edit text.
  18. Step 35Press Backspace to clear the placeholder copy, then type {{event.messageHtml|safe}}; the |safe filter tells Klaviyo to render the AI-generated HTML as-is instead of escaping it.
  19. Step 36Click away from the block to confirm it, then click the icon to leave the block editor.
  20. Step 37Click Exit.
  21. Step 38Click Done to return to the flow canvas.

Liquid tags used in this email:

{{event.subject}}
{{event.previewText}}
{{event.messageHtml|safe}}

Part 4 – Add the initial delay

Before checking whether the email was received, the flow waits so there is actually time for it to land in the inbox.

  1. Step 39Click the + (Add action) icon.
  2. Step 40Click Logic.
  3. Step 41Click Time delay.
  4. Step 42Click Set up time delay.
  5. Step 43Click the Set time delay field and type 5.
  6. Step 44Click the units dropdown (showing Days).
  7. Step 45Click Minutes.
  8. Step 46Click Save.

Part 5 – Branch 1: did they receive it?

This is the first of three matching “split → webhook” blocks. Once you’ve built this one, Parts 6 and 7 repeat the same pattern with different metrics.

  1. Step 47Click the + (Add action) icon.
  2. Step 48Click Logic.
  3. Step 49Click Split.
  4. Step 50Click the Split name field and rename it from “Split #1” to Email_received_callback.
  5. Step 51On Path #1, click Edit path.
  6. Step 52Click Select a condition…
  7. Step 53Type “ha” to search for “has.”
  8. Step 54Click the matching search result.
  9. Step 55Click What someone has done (or not done).
  10. Step 56Click Choose metric…
  11. Step 57Click Received Email.
  12. Step 58Click in the last.
  13. Step 59Click since starting this flow.
  14. Step 60Click Save. This produces two paths: Path #1 (people who received the email) and Everyone else (people who haven’t yet, and who get no further action).
  15. Step 61Inside Path #1, click the + icon.
  16. Step 62Click Data.
  17. Step 63Click Webhook.
  18. Step 64Click the Webhook name field and type Email_received_webhook.
  19. Step 65Click the Destination URL field.
  20. Step 66Switch to the Shopify Flow / llea.ai admin browser tab.
  21. Step 67In the Shopify admin sidebar, click llea.ai.
  22. Step 68Click Settings.
  23. Step 69Find the Klaviyo integration and click Manage.
  24. Step 70Click Copy to copy the webhook URL llea.ai provides: https://api.llea.ai/functions/v1/engagement-callback.
  25. Step 71Switch back to the Klaviyo tab.
  26. Step 72Click the Destination URL field and paste (Cmd+V).
  27. Step 73Back in the llea.ai Manage panel, click Copy again, this time under “JSON body: Received (delivered) event”, to copy the JSON payload template.
  28. Step 74Switch back to Klaviyo.
  29. Step 75Click the JSON body field. Klaviyo pre-fills this field with a default of { "email": "{{ person.email }}" }.
  30. Step 76Paste (Cmd+V).
  31. Step 77Click Save.

What actually gets pasted into the JSON body: llea.ai’s Manage panel supplies a template with four fields; only eventType changes per stage:

{ "email": "{{ person.email }}", "messageId": "{{ event.messageId }}", "channel": "email", "eventType": "received" }

Always copy fresh from the Manage panel

Parts 6 and 7 paste the same shape with eventType set to "opened" and "clicked". Copy each value fresh from the Manage panel; don’t reuse or hand-type it. A mismatched field name will cause llea.ai’s API to reject the payload.

Part 6 – Branch 2: did they open it?

This split is added inside Path #1 of the “received” split above, directly beneath the Email_received_webhook action, so it only evaluates profiles who already registered as having received the email.

  1. Step 78Click the + (Add action) icon.
  2. Step 79Click Logic.
  3. Step 80Click Split.
  4. Step 81Click the Split name field and type Email_open_callback.
  5. Step 82Click Add path criteria.
  6. Step 83Click Select a condition…
  7. Step 84Click What someone has done (or not done).
  8. Step 85Click Choose metric…
  9. Step 86Click Opened Email.
  10. Step 87Click in the last.
  11. Step 88Click since starting this flow.
  12. Step 89Click Save.
  13. Step 90Click the + icon.
  14. Step 91Click Data.
  15. Step 92Click Webhook.
  16. Step 93Click the Webhook name field and type Email_open_callback_webhook.
  17. Step 94Click the Destination URL field.
  18. Step 95Switch to the llea.ai Manage panel and click Copy, the same URL as before, https://api.llea.ai/functions/v1/engagement-callback.
  19. Step 96Switch back to Klaviyo and paste (Cmd+V).
  20. Step 97In the llea.ai panel, scroll to “JSON body: Opened event” and click Copy.
  21. Step 98Switch back to Klaviyo, click the JSON body field, and paste (Cmd+V), which pastes the same 4-field shape with eventType set to "opened".
  22. Step 99Click Save.

Part 7 – Branch 3: did they click it?

This branch sits inside the “opened” path above. Because a click can happen a little while after an open, a second 5-minute delay is added first.

  1. Step 100Click the + (Add action) icon.
  2. Step 101Click Logic.
  3. Step 102Click Time delay.
  4. Step 103Click the Set time delay field and type 5.
  5. Step 104Click the units dropdown (Days).
  6. Step 105Click Minutes.
  7. Step 106Click Save.
  8. Step 107Click the + (Add action) icon.
  9. Step 108Click Logic.
  10. Step 109Click Split.
  11. Step 110Click the Split name field and type Email_clicked_callback.
  12. Step 111Click Add path criteria.
  13. Step 112Click Select a condition…
  14. Step 113Click What someone has done (or not done).
  15. Step 114Click Choose metric…
  16. Step 115Click Clicked Email.
  17. Step 116Click in the last.
  18. Step 117Click since starting this flow.
  19. Step 118Click Save.
  20. Step 119Click the + icon.
  21. Step 120Click Data.
  22. Step 121Click Webhook.
  23. Step 122Click the Webhook name field and type Email_clicked_callback_webhook.
  24. Step 123Click the Destination URL field.
  25. Step 124Switch to the llea.ai Manage panel and click Copy, the same URL again, https://api.llea.ai/functions/v1/engagement-callback.
  26. Step 125Switch back to Klaviyo and paste (Cmd+V).
  27. Step 126In the llea.ai panel, scroll to “JSON body: Clicked event” and click Copy.
  28. Step 127Switch back to Klaviyo, click the JSON body field, and paste (Cmd+V), which pastes the same 4-field shape with eventType set to "clicked".
  29. Step 128Click Save.

Part 8 – Review and activate

  1. Step 129Click Review and turn on.
  2. Step 130Click Save.
  3. Step 131Click Preview to do a final visual check of the whole flow before it goes live.

Once turned on, the flow runs automatically every time llea.ai AI Composer sends a Smart Engagement email through this store.

4. Webhook contract

All three engagement webhooks call the same llea.ai endpoint with the same request shape; only the eventType field (and the split that fires it) differs.

SettingValue
MethodPOST (Klaviyo Webhook action default)
URLhttps://api.llea.ai/functions/v1/engagement-callback
HeadersNone; the field is left empty for all three webhook actions.
AuthNone required. Klaviyo is connected to the Shopify store natively, so llea.ai does not issue or expect an API key for this endpoint.

Request body, the same four fields on every call:

FieldTypeValue / sourceDescription
emailstring{{ person.email }}Recipient's email address (Klaviyo profile Liquid tag).
messageIdstring{{ event.messageId }}Klaviyo message ID of the sent email.
channelstring"email"Static literal; this integration only sends the email channel.
eventType"received" | "opened" | "clicked"Static literal, one value per webhook actionIdentifies which engagement stage this call reports.

The three payloads, identical except for eventType:

{ "email": "{{ person.email }}", "messageId": "{{ event.messageId }}", "channel": "email", "eventType": "received" }
{ "email": "{{ person.email }}", "messageId": "{{ event.messageId }}", "channel": "email", "eventType": "opened" }
{ "email": "{{ person.email }}", "messageId": "{{ event.messageId }}", "channel": "email", "eventType": "clicked" }

Provisioning source of truth

Do not hand-type the Destination URL or JSON body. Both are copied from the llea.ai app itself: Shopify admin → llea.ai → Settings → Integrations → Klaviyo → ManageCopy. That panel is the canonical source; if it ever changes, re-copy rather than editing the values here by hand.

5. Verification & testing

Validate the flow before releasing it; use the Email action’s Preview to confirm the AI-composed subject, preview text, and body render for a test recipient, walk the canvas end-to-end so each split’s “Yes” path leads to the correct nested webhook, then confirm with llea.ai that the received/opened/clicked calls arrive as real customers engage. Work down the checklist:

Quick reference

SettingValue
Klaviyo flow namellea_smart_engagement
TriggerMetric: llea_smart_engagement
Email action namellea_smart_engagement
Subject line{{event.subject}}
Preview text{{event.previewText}}
Email body block{{event.messageHtml|safe}}
Delays5 minutes, twice (before the “received” check, and before the “clicked” check)
Splits (nested, in order)Email_received_callbackEmail_open_callbackEmail_clicked_callback
Webhook namesEmail_received_webhook, Email_open_callback_webhook, Email_clicked_callback_webhook
Webhook URL (all three)https://api.llea.ai/functions/v1/engagement-callback
Webhook method / headers / authPOST / none / none (native Shopify–Klaviyo connection)
Webhook provisioningCopy URL + JSON body from the llea.ai app → Settings → Integrations → Klaviyo → Manage; never hand-type.

6. Troubleshooting

  • llea_smart_engagement doesn’t appear as an available metric: fire a test send from llea.ai AI Composer first (Part 1); the metric only appears after Klaviyo has seen at least one matching event.
  • A webhook call isn’t reaching llea.ai: re-copy the Destination URL and JSON body from the llea.ai app’s Manage panel rather than typing them by hand; even a small mismatch in the JSON key names will cause llea.ai’s API to reject the payload.
  • A profile never reaches the “opened” or “clicked” webhook: remember the branches are nested. If a profile is routed to “Everyone else” at the “received” split, it will never be evaluated for “opened” or “clicked” at all.
  • Subject line or body looks wrong in testing: check that the llea.ai AI Composer test send actually populated {{event.subject}}, {{event.previewText}}, and {{event.messageHtml}}; an empty preview usually means the trigger event’s payload is missing one of those fields.