alepha@docs:~/framework/docs/reference/primitives$
cat $eventLog.md | pretty
2 min read
Last commit: Nov 28, 2026

#$eventLog

#Import

typescript
1import { $eventLog } from "alepha/api/analytics";

#Overview

Declares an event log: one stored row per event, kept for a bounded time, queried with exact distinct counts under any combination of filters.

A dataset ($analytics) folds events into a sum per bucket as they are recorded, which is cheap to keep forever but cannot say how many different visitors, sessions or devices a bucket saw. An event log keeps the events themselves, so it can, for as long as keep says.

Append only: a later fact about an event (an engagement after a view) is a row of its own. Every backend that holds an event log is exact, so a result always reports estimated: false.

#Options

Option Type Required Description
name string No Storage-facing name, snake_case
index string Yes The column nearly every query filters on, such as an app or a tenant
schema ZObject Yes The columns of a row: strings, numbers and booleans
keep string Yes How long a row is kept: <n>h or <n>d, such as "90d"

#Examples

ts
 1class Traffic { 2  pageviews = $eventLog({ 3    name: "pageviews", 4    index: "appId", 5    schema: z.object({ 6      appId: z.text(), 7      sessionId: z.text(), 8      path: z.text(), 9      country: z.text(),10      views: z.integer(),11    }),12    keep: "90d",13  });14 15  async onView(16    appId: string,17    sessionId: string,18    path: string,19    country: string,20  ) {21    await this.pageviews.append([22      { appId, sessionId, path, country, views: 1 },23    ]);24  }25 26  async topPages(appId: string) {27    return this.pageviews.query({28      since: "2026-11-01",29      where: { appId },30      groupBy: ["path"],31      select: {32        views: { sum: "views" },33        visitors: { distinct: "sessionId" },34      },35      orderBy: { key: "visitors", direction: "desc" },36      limit: 20,37    });38  }39}