Quick Start
Get up and running with Insightcn.
This page assumes you have completed the installation steps.
Track Your First Event
The simplest way to track an event is to use captureRegistryEvent directly:
import { NextRequest, NextResponse } from "next/server";
import { captureRegistryEvent } from "@insightcn/sdk";
export async function GET(
request: NextRequest,
{ params }: { params: { slug: string[] } }
) {
const registryUrl = `https://your-registry.com/r/${params.slug.join("/")}.json`;
const registryResponse = await fetch(registryUrl);
// Track the installation event
await captureRegistryEvent(
request,
process.env.INSIGHTCN_API_KEY!,
"installed"
);
return NextResponse.json(await registryResponse.json());
}Generate an RSS Feed
Generate an RSS feed from your registry to keep users updated:
import { NextResponse } from "next/server";
import { generateRegistryRssFeed } from "@insightcn/sdk";
export async function GET() {
const rssFeed = await generateRegistryRssFeed({
baseUrl: "https://your-registry.com",
rss: {
title: "My Shadcn Registry",
description: "Custom components for shadcn/ui",
endpoint: "/api/rss",
},
github: {
owner: "your-org",
repo: "your-registry",
token: process.env.GITHUB_TOKEN,
},
});
if (!rssFeed) {
return new NextResponse("No items found", { status: 404 });
}
return new NextResponse(rssFeed, {
headers: {
"Content-Type": "application/rss+xml",
"Cache-Control": "public, max-age=3600",
},
});
}Detect Component Types
Automatically detect the type of a registry item:
import { determineRegistryItemType } from "@insightcn/sdk";
const item = {
name: "button",
title: "Button",
description: "A clickable button",
files: [{ path: "/ui/button.tsx" }],
};
const type = determineRegistryItemType(item);
console.log(type); // "component"