Skip to content

Weekly

Flag customers who may stop buying

Each week customers whose orders have dropped off are scored and the high-risk ones are added to a list.

Runs
Weekly
Apps
Klaviyo
AI
Yes, uses the built-in AI allowance
Access
read (events) + write (lists)

Send this to your assistant

Create a ClickRuntime automation: every Sunday, look at each Klaviyo customer's Placed Order history, score their churn risk, add high-risk customers to my 'Win-back' list and email me how many were added.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

An online store using Klaviyo knows who bought last month, but not who is quietly slipping away. A customer who used to order every three weeks and has now gone eight weeks without a purchase rarely announces it. By the time the gap shows up in a quarterly review, the discount that might have brought them back has been replaced by an expensive win-back campaign, or nothing at all.

Each week, ClickRuntime pulls Placed Order events for every profile in Klaviyo, looks at how often each person buys and how long it has been since their last order, and scores the likelihood that they are drifting away using ClickRuntime's built-in AI. Profiles it rates high-risk are added to a Klaviyo list, and you get an email summarizing who was flagged and why.

The list can then feed a flow, so a targeted offer reaches exactly those customers.

What you get out of it

  • Lapsing buyers are found before they are gone

    Spotting a loyal customer whose rhythm has changed lets you reach out while the relationship is still alive. Winning back someone at week eight is far cheaper than finding them again after a year of silence.

  • Discounts go only where they matter

    Blanket coupons teach everyone to wait for a sale and cost margin on people who would have bought anyway. A list of high-risk customers keeps incentives for those who need a nudge.

  • Retention work gets a ready audience

    Because flagged profiles land on a Klaviyo list, a win-back flow can be pointed straight at them. There is no weekly export, no manual segment building and no excuse for the campaign to slip.

  • The email explains the reasoning

    A summary that says who was flagged and why, for example a long gap compared with their usual order interval, lets you sanity check the scoring and trust it, instead of treating it as a black box.

  • Churn trends show across weeks

    Seeing 40 flagged customers this week against 15 last week is an early alarm about something, such as a shipping problem or a price change. That prompts questions long before revenue drops visibly.

How it works

What happens, step by step

  1. Once a week ClickRuntime looks at the last year of orders in Klaviyo, customer by customer.

  2. It picks out customers who haven't ordered in more than 60 days and notes how often they used to buy.

  3. AI compares their order history and picks out the ones most likely to stop buying.

  4. Those high-risk customers are added to your win-back list in Klaviyo, and you get an email saying how many were added.

Before it runs live

  • Connect Klaviyo

What you get

RunsWeekly
Flag customers who may stop buyingtoday, 9:00Succeeded
Email · Win-back list updatedAdded 143 high-risk customers out of 4,210 buyers.

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Change what the AI looks for, or how it writes the result
  • Add another app, for example also send it to Slack
  • Combine it with other Klaviyo steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
churn_risk_tagging_with_ai.pyexample
from collections import defaultdict
from datetime import datetime, timedelta, timezone
from clickruntime import on_trigger, credentials, http, ai, notify

API = "https://a.klaviyo.com/api"
PLACED_ORDER_METRIC_ID = "RESQ6t"
WIN_BACK_LIST_ID = "Wb4Lst"

def klaviyo():
    return {"Authorization": f"Klaviyo-API-Key {credentials.secret('KLAVIYO_API_KEY')}",
            "revision": "2024-10-15", "accept": "application/vnd.api+json", "content-type": "application/vnd.api+json"}

@on_trigger
def run(event):
    h = klaviyo()
    since = (datetime.now(timezone.utc) - timedelta(days=365)).strftime("%Y-%m-%dT%H:%M:%SZ")
    url, params, orders = f"{API}/events", {"filter": f'equals(metric_id,"{PLACED_ORDER_METRIC_ID}"),greater-than(datetime,{since})',
                                            "fields[event]": "datetime", "page[size]": 200}, defaultdict(list)
    while url:
        page = http.get(url, headers=h, params=params).json()
        for e in page["data"]:
            orders[e["relationships"]["profile"]["data"]["id"]].append(datetime.fromisoformat(e["attributes"]["datetime"]))
        url, params = page["links"].get("next"), None
    now = datetime.now(timezone.utc)
    quiet = [(pid, sorted(d)) for pid, d in orders.items() if now - max(d) > timedelta(days=60)]
    lines = [f"{i}. orders={len(d)} days_since_last={(now - d[-1]).days} "
             f"avg_gap_days={(d[-1] - d[0]).days // max(len(d) - 1, 1)}" for i, (_, d) in enumerate(quiet[:300])]
    high_risk = []
    if lines:
        r = ai.generate("Each line is a customer's order history. Return the numbers of customers at high churn risk.\n"
                        + "\n".join(lines), max_output_tokens=800,
                        json_schema={"type": "object", "properties": {"high": {"type": "array", "items": {"type": "integer"}}}})
        high_risk = [quiet[i][0] for i in r.json["high"] if i < len(quiet)]
    for i in range(0, len(high_risk), 1000):
        http.post(f"{API}/lists/{WIN_BACK_LIST_ID}/relationships/profiles", headers=h,
                  json={"data": [{"type": "profile", "id": p} for p in high_risk[i:i + 1000]]}).raise_for_status()
    notify.email_me("Win-back list updated", f"Added {len(high_risk)} high-risk customers out of {len(orders)} buyers.")
    return {"added": len(high_risk)}

FAQ

Common questions

How does it decide that someone is likely to churn?
It looks at the Placed Order events for each profile, mainly the number of orders, the usual gap between them and the time since the last one. A profile whose current gap is far longer than their normal pattern scores high. The AI step weighs these signals and explains the result.
Do I need an OpenAI or Anthropic key for the AI scoring?
No. The scoring step uses the AI that is built into ClickRuntime, so there is nothing to sign up for. You only need the Klaviyo connection. The same applies on every plan, including the free plan.
What happens to customers who have only ordered once?
With one order there is no pattern to compare against, so the scoring treats them more cautiously. Many stores handle first-time buyers with a separate post-purchase flow. You can ask to exclude single-order profiles or to score them by days since purchase.
What permissions does it need?
read (events) + write (lists). Nothing else in your accounts is used.
Does it need AI?
Yes. It uses ClickRuntime's built-in AI, so you don't need an OpenAI or Anthropic key. Every plan includes a monthly AI allowance.
How many runs does it use?
One run each time it runs (weekly). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Flag customers who may stop buying” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.