Analytics
Product analytics: track, identify, funnels and cohorts.
Overview
Base path:
/v1/analyticsPython namespace:
infra.analyticstext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.analyticsMethods
analytics.track
POST /v1/analytics/track
Track one or more analytics events.
Python
python
infra.analytics.track(event=..., distinct_id=..., properties=None)TypeScript
typescript
client.analytics.track(ev: AnalyticsEvent | AnalyticsEvent[]): Promise<{ ok, accepted }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
event | string | Required | Event name. |
distinct_id | string | Required | Stable id of the acting user. |
properties | Record<string, unknown> | Optional | Arbitrary event properties. |
Returns
{ ok, accepted }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
infra.analytics.track(event="signup", distinct_id="u_123",
properties={"plan": "standard"})
print("tracked")analytics.identify
POST /v1/analytics/identify
Associate traits with a distinct id.
Python
python
infra.analytics.identify(distinct_id=..., user_id=None, traits=None)TypeScript
typescript
client.analytics.identify(opts): Promise<{ ok }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
distinct_id | string | Required | Stable id of the acting user. |
user_id | string | Optional | Id of the connecting user. |
traits | Record<string, unknown> | Optional | User traits to set. |
Returns
{ ok: boolean }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
infra.analytics.identify(distinct_id="u_123", user_id="u_123",
traits={"email": "alice@example.com", "plan": "pro"})
print("identified")analytics.funnel
POST /v1/analytics/funnel
Compute a conversion funnel across event steps.
Python
python
infra.analytics.funnel(steps=[...], from_=..., to=...)TypeScript
typescript
client.analytics.funnel(opts): Promise<{ steps }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
steps | string[] | Required | Ordered event names forming the funnel. |
from | string | Required | Start of the time range. |
to | string | Required | End of the time range. |
Returns
{ steps: Array<{ event, count, conversion_pct }> }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
f = infra.analytics.funnel(steps=["signup", "activate", "pay"],
from_="2026-01-01", to="2026-01-31")
for s in f.get("steps", []):
print(s.get("event"), s.get("count"), s.get("conversion_pct"))analytics.cohort
POST /v1/analytics/cohort
Compute cohort buckets over a time range.
Python
python
infra.analytics.cohort(definition=..., from_=..., to=...)TypeScript
typescript
client.analytics.cohort(opts): Promise<{ buckets }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
definition | { event, filter? } | Required | Cohort definition with an event and optional filter. |
from | string | Required | Start of the time range. |
to | string | Required | End of the time range. |
Returns
{ buckets: Array<{ bucket, size }> }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
c = infra.analytics.cohort(definition={"event": "signup"},
from_="2026-01-01", to="2026-01-31")
for b in c.get("buckets", []):
print(b.get("bucket"), b.get("size"))