Get Registry Analytics
Retrieve analytics data for your registry.
Insightcn provides a Convex backend for storing and querying analytics data. This page covers the available queries for retrieving analytics data.
Overview
The analytics API provides the following queries:
getRegistryOverview— Get total stats for a registrygetTopComponents— Get top components by installsgetEvents— Get events with paginationgetDailyEventCounts— Get daily event counts for charts
getRegistryOverview
Get analytics overview for a registry.
Signature
function getRegistryOverview(args: {
registryId: Id<"registries">;
}): Promise<RegistryStats>;Parameters
| Parameter | Type | Description |
|---|---|---|
registryId | string | The registry ID |
Returns
interface RegistryStats {
totalDownloads: number;
totalInstalls: number;
totalViews: number;
uniqueComponents: number;
}Example
import { api } from "../convex/_generated/api";
import { useQuery } from "convex/react";
function RegistryStats({ registryId }: { registryId: string }) {
const stats = useQuery(api.queries.getRegistryOverview, { registryId });
if (!stats) return <div>Loading...</div>;
return (
<div>
<p>Total Downloads: {stats.totalDownloads}</p>
<p>Total Installs: {stats.totalInstalls}</p>
<p>Total Views: {stats.totalViews}</p>
<p>Unique Components: {stats.uniqueComponents}</p>
</div>
);
}getTopComponents
Get top components by installs.
Signature
function getTopComponents(args: {
registryId: Id<"registries">;
limit?: number;
}): Promise<ComponentStats[]>;Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
registryId | string | - | The registry ID |
limit | number | 10 | Maximum results |
Returns
interface ComponentStats {
_id: string;
registryId: string;
componentName: string;
componentPath: string;
totalDownloads: number;
totalInstalls: number;
totalViews: number;
}Example
import { api } from "../convex/_generated/api";
import { useQuery } from "convex/react";
function TopComponents({ registryId }: { registryId: string }) {
const components = useQuery(api.queries.getTopComponents, {
limit: 5,
registryId,
});
if (!components) return <div>Loading...</div>;
return (
<ul>
{components.map((comp) => (
<li key={comp._id}>
{comp.componentName} - {comp.totalInstalls} installs
</li>
))}
</ul>
);
}getEvents
Get events for a registry with pagination.
Signature
function getEvents(args: {
registryId: Id<"registries">;
limit?: number;
}): Promise<Event[]>;Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
registryId | string | - | The registry ID |
limit | number | 50 | Maximum results |
Returns
interface Event {
_id: string;
registryId: string;
type: "installed" | "viewed" | "downloaded";
timestamp: number;
ip: string;
userAgent: string;
componentPath: string;
}Example
import { api } from "../convex/_generated/api";
import { useQuery } from "convex/react";
function EventList({ registryId }: { registryId: string }) {
const events = useQuery(api.queries.getEvents, {
limit: 20,
registryId,
});
if (!events) return <div>Loading...</div>;
return (
<ul>
{events.map((event) => (
<li key={event._id}>
{event.type} - {event.componentPath} -{" "}
{new Date(event.timestamp).toLocaleDateString()}
</li>
))}
</ul>
);
}getDailyEventCounts
Get daily event counts for charts.
Signature
function getDailyEventCounts(args: {
registryId: Id<"registries">;
days?: number;
}): Promise<DailyCounts>;Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
registryId | string | - | The registry ID |
days | number | 30 | Number of days |
Returns
interface DailyCounts {
[date: string]: {
downloaded: number;
installed: number;
viewed: number;
};
}Example
import { api } from "../convex/_generated/api";
import { useQuery } from "convex/react";
function EventChart({ registryId }: { registryId: string }) {
const dailyCounts = useQuery(api.queries.getDailyEventCounts, {
days: 7,
registryId,
});
if (!dailyCounts) return <div>Loading...</div>;
return (
<div>
{Object.entries(dailyCounts).map(([date, counts]) => (
<div key={date}>
<p>Date: {date}</p>
<p>Installed: {counts.installed}</p>
<p>Viewed: {counts.viewed}</p>
<p>Downloaded: {counts.downloaded}</p>
</div>
))}
</div>
);
}Setup
To use these queries, you need to set up the Convex backend. See the installation guide for details.