Event Tracking
Track component usage with Insightcn.
Event tracking is the core feature of Insightcn. It allows you to track when users install, view, or download components from your registry.
Event Types
Insightcn supports three types of events:
| Event Type | Description |
|---|---|
installed | User installed a component via CLI |
viewed | User viewed a component in browser |
downloaded | User downloaded a component file |
How It Works
- User performs an action (install, view, or download)
- Your app receives the HTTP request
- You call
captureRegistryEventwith the request - SDK validates the request (checks path and user-agent)
- SDK sends the event to the Insightcn backend
- You can view analytics in the dashboard
Basic Usage
import { captureRegistryEvent } from "@insightcn/sdk";
const request = new Request("https://your-registry.com/r/ui/button.json", {
method: "GET",
headers: { "user-agent": "node-fetch" },
});
// Track an installation event
await captureRegistryEvent(request, "your-api-key", "installed");Private Events
If you need to track events without validation (e.g., for internal events), use capturePrivateRegistryEvent:
import { capturePrivateRegistryEvent } from "@insightcn/sdk";
// Track without validation
await capturePrivateRegistryEvent(request, "your-api-key", "installed");Event Data
Each event contains:
registryId- The registry identifiertype- The event type (installed,viewed, ordownloaded)timestamp- When the event occurredip- Anonymized client IP addressuserAgent- Client user agent stringcomponentPath- Path to the component in the registry