Integrations / Frameworks / Astro
Track events from Astro API endpoints and server actions. Works with any Astro adapter โ Node, Vercel, Cloudflare.
npm install logit
// src/lib/logit.ts
import { init } from "logit";
export const logit = init({ token: import.meta.env.LOGIT_API_KEY });
// src/pages/api/signup.ts
import type { APIRoute } from "astro";
import { logit } from "@/lib/logit";
export const POST: APIRoute = async ({ request }) => {
const { email } = await request.json() as { email: string };
// ... create user
await logit.now("signups", {
event: "New user signed up",
description: email,
icon: "๐ค",
notify: true,
metadata: { email },
});
return new Response(JSON.stringify({ ok: true }), {
headers: { "Content-Type": "application/json" },
});
};
// src/actions/index.ts
import { defineAction } from "astro:actions";
import { z } from "astro:schema";
import { logit } from "@/lib/logit";
export const server = {
signup: defineAction({
input: z.object({ email: z.string().email() }),
handler: async ({ email }) => {
await logit.now("signups", {
event: "New user signed up",
description: email,
icon: "๐ค",
notify: true,
});
return { ok: true };
},
}),
};
# .env
LOGIT_API_KEY=lk_live_xxxxxxxxxxxxxxxx
Tip: Use
import.meta.envnotprocess.envin Astro โ and prefix withLOGIT_to keep it server-only (noPUBLIC_prefix).
Ready to connect Astro?
7-day free trial. No credit card required.