Integrations / Frameworks / Fastify
Track business events from Fastify route handlers. Fully typed, works with Fastify's schema validation and plugin system.
npm install logit fastify
import Fastify from "fastify";
import { init } from "logit";
const app = Fastify({ logger: true });
const logit = init({ token: process.env.LOGIT_API_KEY! });
interface SignupBody {
email: string;
plan: "free" | "pro";
}
app.post<{ Body: SignupBody }>("/signup", {
schema: {
body: {
type: "object",
required: ["email", "plan"],
properties: {
email: { type: "string" },
plan: { type: "string", enum: ["free", "pro"] },
},
},
},
}, async (request, reply) => {
const { email, plan } = request.body;
// ... create user
await logit.now("signups", {
event: "New user signed up",
description: `${email} joined on ${plan}`,
icon: "👤",
notify: true,
tags: { plan },
metadata: { email, ip: request.ip },
});
return reply.code(201).send({ ok: true });
});
import type { FastifyPluginAsync } from "fastify";
import { init, type LogitClient } from "logit";
declare module "fastify" {
interface FastifyInstance {
logit: LogitClient;
}
}
const logitPlugin: FastifyPluginAsync = async (app) => {
app.decorate("logit", init({ token: process.env.LOGIT_API_KEY! }));
};
export default logitPlugin;
Ready to connect Fastify?
7-day free trial. No credit card required.