@cockpitify/js
v0.1.3
Published
Cockpitify usage analytics for web apps: screen views, events and sessions.
Maintainers
Readme
@cockpitify/js
Usage analytics for web apps: page views, events and sessions, sent to the ops layer that
Cockpitify installs in your own Supabase project. You see them in the Cockpitify app.
npm install @cockpitify/jsUsing an AI coding assistant? Point it at AI.md (also in node_modules/@cockpitify/js/AI.md).
import { Ops } from '@cockpitify/js';
import { supabase } from './supabase';
Ops.init(supabase); // page views are recorded from here on
// When a feature is used:
Ops.track('report_exported', { rows: 120 });Page views come from the History API. Id-like path segments become [id], so /orders/8412 is
counted as /orders/[id].
Not on Supabase Auth
Send batches to your own endpoint, which verifies the user and passes the batch on to ops.ingest_batch:
import { Ops, httpTransport } from '@cockpitify/js';
Ops.init(httpTransport({ endpoint: 'https://api.example.com/ops', getToken: () => auth.currentUser?.getIdToken() }));API
| | |
|---|---|
| Ops.init(target, options?) | target: a supabase-js client, an httpTransport(...), or full options. Options: appVersion, pageViews (default true), screenName(pathname), debug. Safe to call again. |
| Ops.track(name, props?) | An event. Props are strings, numbers or booleans. |
| Ops.screen(name) | A screen view, when you name screens yourself. |
| Ops.flush() | Sends what is queued now. |
| Ops.optOut() / Ops.optIn() | Stops or resumes recording on this device. |
Recording never throws into your code. Events are queued, sent in batches and retried when offline. A new session starts after 30 minutes away.
