Custom events
Beyond automatic pageviews, Cosmic Insights tracks any event you fire from your app.
Programmatic
window.cosmicInsights('signup', { plan: 'team' });
The first argument is the event name (max 120 chars). The second is a free-form props object. Anything not in the promotable fields list is stored as JSON on the event row in event_props.
Declarative (zero JS)
Add data-cosmic-event to any element. Optional data-cosmic-prop-* attributes become props. The tracker delegates clicks from document, so dynamically-rendered components work without re-binding.
<button
data-cosmic-event="cta_click"
data-cosmic-prop-location="hero"
data-cosmic-prop-variant="b"
>
Start free trial
</button>
Kebab-case prop keys are normalized to snake_case, so data-cosmic-prop-revenue-cents="4900" lands as revenue_cents: 4900 and is promoted to a top-level column. Numeric coercion is applied to revenue_cents automatically; other props are sent as strings.
Conversions
Conversions are aggregated per event name in the dashboard's Custom events view. Fire any named event from your app and it shows up automatically:
window.cosmicInsights('subscribe_completed', { plan: 'team' });
The Custom events view counts unique converters and (if you also pass revenue_cents) revenue per event name. Drill into the raw rows from the Events tab.
Revenue
Pass revenue_cents as a number; the snippet automatically tags event_type='revenue' and rolls the value up by source and object.
window.cosmicInsights('order_paid', {
revenue_cents: 4900,
currency: 'USD',
});
Object attribution
Send object_id (and optionally object_type) on each page so the dashboard can roll up traffic per Cosmic object:
<meta name="cosmic-context" content='{"object_id":"OBJ_ID","object_type":"posts"}'>
The Insights dashboard uses object_id to populate the per-object analytics in the Content tab and the Performance card on each object detail page.
Promotable fields
These keys, if present in your event props, the cosmic-context meta tag, or the script tag, are promoted to top-level columns and become first-class filters in the dashboard. Anything else stays in the JSON event_props blob.
| Field | Type | Used by |
|---|---|---|
object_id | 24-char ObjectId | Per-object Performance card |
object_type | string | Per-object Performance card |
bucket_id | 24-char ObjectId | Bucket dropdown filter |
agent_id | 24-char ObjectId | Per-agent attribution (when shipped) |
automation_id | 24-char ObjectId | Per-automation attribution (when shipped) |
user_id | 24-char ObjectId | Per-author attribution (when shipped) |
revenue_cents | number | Revenue rollups; sets event_type='revenue' |
currency | ISO 4217 string | Revenue rollups |
The snippet warns once per typo per page load if it sees common camelCase mistakes (agentId, userId, objectId, revenueCents, etc.) so you can catch them in the browser console during development.
Limits
| Field | Limit |
|---|---|
| Event name | 120 chars |
| Path | 2048 chars |
| Referrer | 2048 chars |
cosmic-context meta tag content | 1024 bytes |
| Batch size | 50 events / request |
FAQ
How much does Cosmic cost?
Project plans are Free ($0), Builder ($99/mo), Team ($299/mo), Business ($499/mo), Enterprise (custom pricing). Yearly billing saves 10%. Workspace plans are Small Workspace ($999/mo) and Large Workspace ($2,999/mo), and they start with a 30-day free trial. Allowances, add-on rates, and the rest of the pricing FAQ are plain text at https://www.cosmicjs.com/pricing.md.
Are API keys required, and is content private?
Each Bucket has a read key and a write key in Bucket Settings > API Access. GET requests use the read key. POST, PATCH, and DELETE use the write key as Authorization: Bearer. Do not put the write key in a browser bundle, a mobile app, or a NEXT_PUBLIC_ variable. SAML single sign-on is on Large Workspace and Enterprise. The audit log is append-only. Text versions: https://www.cosmicjs.com/security.md and https://www.cosmicjs.com/docs/dashboard/audit-log.md.
Can an agent create a Cosmic project without an existing account?
Yes. POST https://dapi.cosmicjs.com/v3/agents/sign-up provisions a free-tier project and bucket tied to a human email, with no existing Cosmic account. The human claims it with the emailed one-time code. The playbook is https://www.cosmicjs.com/docs/ai-onboarding.md.