Skip to content

Analytics

Product analytics: track, identify, funnels and cohorts.

1. Overview

Base path: https://api.infrai.cc/v1/analytics
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/analytics capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/analytics/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. Methods (8)

2.1analytics.track

POST /v1/analytics/track

Track one or more analytics events.

Parameters

NameTypeRequiredDescription
eventstring
Required
Event name.
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
distinct_idstring
Required
Stable id of the acting user.
propertiesRecord<string, unknown>OptionalArbitrary event properties.

Returns

{ ok, accepted }
NameTypeDescription
acceptedbooleanNumber of items accepted for processing
event_idstring | nullUnique identifier for this event
reasonstring | nullReason for the current state or action

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/track \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"event": "sample", "distinct_id": "sample"}'

2.2analytics.identify

POST /v1/analytics/identify

Associate traits with a distinct id.

Parameters

NameTypeRequiredDescription
distinct_idstring
Required
Stable id of the acting user.
user_idstringOptionalId of the connecting user.
traitsRecord<string, unknown>OptionalUser traits to set.

Returns

{ ok: boolean }
NameTypeDescription
distinct_idstringDistinct identifier for the user or entity
traits_merged_countinteger | nullNumber of traits merged during identification
≥ 0

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/identify \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"distinct_id": "sample"}'

2.3analytics.alias

POST /v1/analytics/alias

合并身份别名

Parameters

NameTypeRequiredDescription
old_idstring
Required
要合并的来源 distinct_id(例如匿名 id)。
new_idstring
Required
合并目标的规范 distinct_id。
idempotency_keystringOptional可选幂等键,确保重复请求只生效一次。

Returns

AliasResult { merged: boolean }
NameTypeDescription
old_idstringPrevious identifier before aliasing
new_idstringNew identifier after aliasing
mergedbooleanWhether the identities were merged

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/alias \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"old_id": "sample", "new_id": "sample"}'

2.4analytics.batch

POST /v1/analytics/batch

批量上报事件

Parameters

NameTypeRequiredDescription
eventsTrackEvent[]
Required
至多 1000 条 TrackEvent 事件,每条事件自带幂等键。
1–1000 items

Returns

{ ok: boolean, accepted: number }
NameTypeDescription
acceptedintegerNumber of items accepted for processing
≥ 0
rejectedintegerNumber of items rejected due to validation errors
≥ 0
errorsobject[]Array of per-item errors (for batch operations)
errors[].indexinteger-
≥ 0
errors[].reasonstring-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/batch \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"events": [{"event": "sample", "distinct_id": "sample"}]}'

2.5analytics.group

POST /v1/analytics/group

关联群组

Parameters

NameTypeRequiredDescription
distinct_idstring
Required
要关联到群组的用户 distinct_id。
group_typestring
Required
群组维度,例如 company / team。
group_keystring
Required
在 group_type 下的群组标识符。
traitsRecord<string, unknown>Optional可选的群组档案属性。
idempotency_keystringOptional可选幂等键,确保重复请求只生效一次。

Returns

{ ok: boolean }
NameTypeDescription
distinct_idstringDistinct identifier for the user or entity
group_typestringType of the analytics group
group_keystringKey of the analytics group

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/group \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"distinct_id": "sample", "group_type": "sample", "group_key": "sample"}'

2.6analytics.query.events

POST /v1/analytics/query/events

查询原始事件

Parameters

NameTypeRequiredDescription
sincestring
Required
时间窗口起点(含)。
format: date-time
untilstring
Required
时间窗口终点(不含)。
format: date-time
filterRecord<string, unknown>Optional可选属性过滤(键/值匹配)。
limitnumberOptional本页返回的最大条数(1-1000,默认 1000)。
1–1000default: 1000
cursorstringOptional来自上一页 next_cursor 的不透明游标。

Returns

EventQueryResult { events: object[], next_cursor?: string }
NameTypeDescription
itemsany[]Array of result items in this page
next_cursorstring | nullOpaque cursor to fetch the next page; null/absent if this is the last page
total_estimateinteger | nullEstimated total number of matching events
≥ 0

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/query/events \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"since": "sample", "until": "sample"}'

2.7analytics.query.retention

POST /v1/analytics/query/retention

查询留存

Parameters

NameTypeRequiredDescription
born_eventstring
Required
定义群组归属(第 0 天)的事件。
return_eventstring
Required
其再次发生用于衡量留存的事件。
sincestring
Required
时间窗口起点。
format: date-time
untilstring
Required
时间窗口终点。
format: date-time
interval"day" | "week" | "month"Optional分桶周期(默认 day)。
default: "day"

Returns

RetentionResult { matrix: number[][] }
NameTypeDescription
cohortsobject[]Retention cohort data points
cohorts[].datestring-
format: date
cohorts[].totalinteger-
≥ 0
cohorts[].returningobject[]-
cohorts[].returning[].intervalinteger-
≥ 0
cohorts[].returning[].ninteger-
≥ 0

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/query/retention \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"born_event": "sample", "return_event": "sample", "since": "sample", "until": "sample"}'

2.8analytics.query.path

POST /v1/analytics/query/path

查询行为路径

Parameters

NameTypeRequiredDescription
start_eventstring
Required
路径树展开的根事件。
sincestring
Required
时间窗口起点。
format: date-time
untilstring
Required
时间窗口终点。
format: date-time
max_depthnumberOptional路径树最大深度(1-20,默认 5)。
1–20default: 5

Returns

PathResult { root: string, children: object[] }
NameTypeDescription
rootstringRoot node of the path tree
childrenobject[]Child nodes in the path tree
children[].eventstring-
children[].usersinteger-
≥ 0
children[].childrenobject[]-

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/analytics/query/path \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"start_event": "sample", "since": "sample", "until": "sample"}'

3. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

analytics.aliasPOST /v1/analytics/alias

Rename or merge an anonymous distinct_id (old_id) into a known identity (new_id).

Parameters (3)
NameTypeRequiredDescription
old_idstringRequiredThe distinct_id to rename from (e.g. anonymous id).
new_idstringRequiredThe canonical distinct_id to merge into.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
analytics.batchPOST /v1/analytics/batch

Ingest up to 1000 TrackEvent events in a single call (idempotency is per-event).

Parameters (1)
NameTypeRequiredDescription
eventsobject[]RequiredUp to 1000 TrackEvent items.
1–1000 items
analytics.groupPOST /v1/analytics/group

Associate a distinct_id with a group (organization/team/account) for B2B account-level aggregation.

Parameters (5)
NameTypeRequiredDescription
distinct_idstringRequiredDistinct identifier for the user or entity
group_typestringRequiredGroup dimension, e.g. "company" / "team".
group_keystringRequiredGroup identifier within group_type.
traitsobject | nullOptionalOptional group profile traits.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
analytics.identifyPOST /v1/analytics/identify

Set profile traits on a distinct_id, optionally merging a prior id via alias_for.

Parameters (4)
NameTypeRequiredDescription
distinct_idstringRequiredDistinct identifier for the user or entity
traitsobject | nullOptionalProfile traits to merge onto the user.
alias_forstring | nullOptionalOptional prior distinct_id to merge into this one at identify time.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
analytics.query.eventsPOST /v1/analytics/query/events

Query raw events within a time window, with attribute filters and cursor pagination.

Parameters (5)
NameTypeRequiredDescription
sincestringRequiredWindow start (inclusive).
format: date-time
untilstringRequiredWindow end (exclusive).
format: date-time
filterobject | nullOptionalOptional property filter (key/value match).
limitintegerOptionalMaximum number of items to return per page
1–1000default: 1000
cursorstring | nullOptionalOpaque cursor from a prior page's next_cursor.
analytics.query.pathPOST /v1/analytics/query/path

Build behavioral path/sequence trees rooted at a start event within a time window.

Parameters (4)
NameTypeRequiredDescription
start_eventstringRequiredRoot event the path tree branches from.
sincestringRequiredISO 8601 date when the current tier or state became effective
format: date-time
untilstringRequiredISO 8601 date/time for the end of the query range
format: date-time
max_depthintegerOptionalMaximum depth of the path tree to return
1–20default: 5
analytics.query.retentionPOST /v1/analytics/query/retention

Compute a retention matrix bucketed by period from a born event to a return event.

Parameters (5)
NameTypeRequiredDescription
born_eventstringRequiredEvent that defines cohort membership (day 0).
return_eventstringRequiredEvent whose recurrence defines retention.
sincestringRequiredISO 8601 date when the current tier or state became effective
format: date-time
untilstringRequiredISO 8601 date/time for the end of the query range
format: date-time
interval"day" | "week" | "month"OptionalTime interval for retention buckets (e.g. day, week)
default: "day"
analytics.trackPOST /v1/analytics/track

Ingest a single product analytics event with properties for a distinct user; idempotent.

Parameters (6)
NameTypeRequiredDescription
eventstringRequiredEvent name you are recording (e.g. 'signup', 'purchase') — the verb of the action.
pattern: ^[a-zA-Z][a-zA-Z0-9_.-]{0,127}$
distinct_idstringRequiredDistinct identifier for the user or entity
propertiesobject | nullOptionalAdditional properties for risk assessment
timestampstring | nullOptionalUnix timestamp of the data point
format: date-time
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
contextobject | nullOptional{ip, ua, session_id}

4. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · analytics — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) analytics.track — POST /v1/analytics/track · Ingest a single product analytics event with properties for a distinct user; idempotent.
r1 = show("analytics.track", infrai("POST", "/v1/analytics/track", {"event":"checkout_completed","distinct_id":"user_42","properties":{"amount":19.99}}))

# 2) analytics.identify — POST /v1/analytics/identify · Set profile traits on a distinct_id, optionally merging a prior id via alias_for.
r2 = show("analytics.identify", infrai("POST", "/v1/analytics/identify", {"distinct_id":"sample"}))