Skip to content

Retention

Beta

Who 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.

GET/api/v1/sites/{site}/retention

Parameters

NameWhat it does
siteIn the path, requiredThe site’s ID, as in its address in the app: app.lyli.io/sites/<id>. /sites lists the ones your key can read.
startOptionalWhat starts a visitor’s count, the first time they do it: a path, such as /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.
backOptionalWhat counts as coming back: a path or a custom event’s name, not a goal’s name. Any visit if left out.
byOptionalday, week, or month: the length of a cohort and of each step after it. week if left out.
periodOptionaltoday, yesterday, 7d, 30d, 90d, 52w, or a range of days or hours: when the cohorts start. The last 30 days if left out. Periods
againstOptionalprevious, month, or year. Adds compared to the response.
timezoneOptionalA time zone name, such as America/New_York. The site’s own if left out.
channel … contentOptionalAny of the 14 filters, such as country=SE. They pick who starts. Filters
segment, cohortOptionalA saved segment’s or cohort’s ID.

Request

An example site that recognizes returning visitors: weekly cohorts of first visits over the last 30 days.

Your terminal
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

Response

200 OK · application/json
{
  "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.

FieldWhat it holds
periodThe period read: its first and last day in timezone, and its step, interval, as in the Overview.
retentionThe settings read: start and back, each a kind (page or event) and a match, or null for a first visit and any visit; and by.
visitors.allVisitors with a visit in the period, with the filters. With by=day, only in the period’s last 90 days, the days its cohorts cover.
visitors.recognizedOf them, those the site recognized. Only they can be in a cohort; the others are left out, never counted as gone.
cohortsOne for each day, week, or month of the period, oldest first, from its first day, from, to its last, to.
cohorts.sizeThe recognized visitors who started in it.
cohorts.backHow many came back in each step: 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.
cohorts.completeHow many steps have ended. When it’s less than the length of back, the last step is still running, and its count can still grow.
averageThe share back at each step, in percent, over the cohorts of at least 20 people whose step has ended, so step 0 is 100. null where no cohort counts yet.
comparednull, 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

byThe period’s cohorts
dayEach day that starts in the period, up to its last 90 days.
week7-day blocks counted back from the period’s end, so a period that isn’t whole weeks leaves its first days out. The example’s 30 days hold four weeks, from Oct 26.
monthThe calendar months that start in the period. The last one ends where the period does.
  • Coming back is counted up to now, not only within the period, so an older cohort has more steps. back holds 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

StatusCodeWhen
400invalid_parameterA parameter it doesn’t take; a 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.
402workspace_pausedThe workspace is paused.
403site_not_allowedYour key doesn’t have access to this site.
404not_foundNo site with this ID in the workspace.

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.