Retention
BetaWho came back, as the Retention report counts them: recognized visitors grouped by when they started, and how many of them returned in each day, week, or month after.
Parameters
app.lyli.io/sites/<id>. /sites lists the ones your key can read./pricing (end it in * for every path that starts with it), or a custom event’s name, such as signup, not a goal’s name. Their first visit if left out.day, week, or month: the length of a cohort and of each step after it. week if left out.today, yesterday, 7d, 30d, 90d, 52w, or a range of days or hours: when the cohorts start. The last 30 days if left out. Periodsprevious, month, or year. Adds compared to the response.America/New_York. The site’s own if left out.country=SE. They pick who starts. FiltersRequest
An example site that recognizes returning visitors: weekly cohorts of first visits over the last 30 days.
curl -G https://app.lyli.io/api/v1/sites/s_k3m9x2p7qa/retention \
-H "Authorization: Bearer $LYLI_API_KEY" \
-d by=week \
-d period=30d \
-d timezone=Europe/Stockholm// Node 18 or later, on your server
const params = new URLSearchParams({
by: "week",
period: "30d",
timezone: "Europe/Stockholm",
});
const res = await fetch(`https://app.lyli.io/api/v1/sites/s_k3m9x2p7qa/retention?${params}`, {
headers: { Authorization: `Bearer ${process.env.LYLI_API_KEY}` },
});
if (!res.ok) throw new Error(`Lyli API: ${res.status}`);
const { cohorts, average } = await res.json();import os
import requests
res = requests.get(
"https://app.lyli.io/api/v1/sites/s_k3m9x2p7qa/retention",
params={
"by": "week",
"period": "30d",
"timezone": "Europe/Stockholm",
},
headers={"Authorization": f"Bearer {os.environ['LYLI_API_KEY']}"},
timeout=10,
)
res.raise_for_status()
cohorts = res.json()["cohorts"]Response
{
"site": "s_k3m9x2p7qa",
"period": {
"key": "30d",
"from": "2026-10-24",
"to": "2026-11-22",
"timezone": "Europe/Stockholm",
"interval": "day"
},
"retention": { "start": null, "back": null, "by": "week" },
"visitors": { "all": 447, "recognized": 279 },
"cohorts": [
{ "from": "2026-10-26", "to": "2026-11-01", "size": 39,
"back": [39, 10, 16, 8, 2], "complete": 4 },
{ "from": "2026-11-02", "to": "2026-11-08", "size": 44,
"back": [44, 18, 10, 0], "complete": 3 },
{ "from": "2026-11-09", "to": "2026-11-15", "size": 33,
"back": [33, 12, 2], "complete": 2 },
{ "from": "2026-11-16", "to": "2026-11-22", "size": 30,
"back": [30, 2], "complete": 1 }
],
"average": [100, 34.5, 31.3, 20.5, null],
"compared": null
}An example site’s numbers, read on Nov 23, 2026, the day each cohort’s last step began: those steps are still running.
timezone, and its step, interval, as in the Overview.start and back, each a kind (page or event) and a match, or null for a first visit and any visit; and by.by=day, only in the period’s last 90 days, the days its cohorts cover.from, to its last, to.back[0] is the size, back[1] the step after the cohort, and so on, up to the step running now. Each person counts once a step.back, the last step is still running, and its count can still grow.null where no cohort counts yet.null, or with against: the other period’s from, to, and average. Also null when that period starts before the site’s data does.How cohorts are counted
- Coming back is counted up to now, not only within the period, so an older cohort has more steps.
backholds at most 91 steps by day, 105 by week, and 37 by month. - Filters, a segment, and a cohort pick who starts, not who comes back: with
country=SE, a visitor who started in Sweden counts as back wherever their next visit comes from. - A first time is looked for in all the data the site keeps, so someone whose first visit, or first time doing
start, came before the period isn’t in any of its cohorts. - Cohorts under 20 people are listed with their counts but left out of
average, as the report shows counts rather than shares for them. - Only what Lyli recorded counts. History imported from Google Analytics isn’t in Retention, in the app or here.
Who can be in a cohort
Only recognized visitors: the site’s Visitors choice, in Site settings › General › Tracking, is Recognize returning visitors, and the visitor’s browser sent the ID the script keeps once data-remember is on its tag. A visitor with a daily code can’t be followed to another day, and visits recorded while a site is cookieless are never recognized: there, every cohort’s size is 0. Cohorts that ended before the site’s first recognized visit are left out.
The ID needs consent in the EU and UK. Recognizing returning visitors stores an ID in the visitor’s browser, so add data-remember only once they agree, through your consent tool. Recognizing returning visitors
Errors
start, back, by, period, filter, or time zone we can’t parse; a segment or cohort the site doesn’t have; or against=month for a period over 5 weeks.Every endpoint can also return 401 (missing, revoked, or expired key) and 429 (rate limit reached). All errors
Start from a report
In the app, open Reports › Retention, then the Share menu’s Copy as API request: the report on your screen as a curl request, with its start, back, and by, and its period, comparison, and filters as parameters. It reads your API key from the LYLI_API_KEY environment variable, so a copied request never contains a key. A cohort is read by its ID, so save one before you pass it as cohort.