Guides / Signups & Auth
SvelteKit ships with great server-side primitives — form actions, load functions, hooks — but there's no built-in way to know when someone signs up unless you poll a database.
npm install logit
Create src/lib/logit.ts:
import { init } from "logit";
import { LOGIT_API_KEY } from "$env/static/private";
export const logit = init({ token: LOGIT_API_KEY });
// src/routes/signup/+page.server.ts
import type { Actions } from "./$types";
import { logit } from "$lib/logit";
export const actions: Actions = {
default: async ({ request }) => {
const data = await request.formData();
const email = data.get("email") as string;
const plan = data.get("plan") as string;
// ... create user in your DB
await logit.now("signups", {
event: "New user signed up",
description: email,
icon: "👤",
notify: true,
tags: { plan, source: "signup-form" },
metadata: { email, plan },
});
return { success: true };
},
};
// src/routes/api/signup/+server.ts
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";
import { logit } from "$lib/logit";
export const POST: RequestHandler = async ({ request }) => {
const { email, plan } = await request.json();
// ... create user
await logit.now("signups", {
event: "New user signed up",
description: `${email} joined on ${plan}`,
icon: "👤",
notify: true,
tags: { plan },
metadata: { email },
});
return json({ ok: true });
};
$env/static/private (not $env/dynamic/private) so the key is tree-shaken out of client bundles.LOGIT_API_KEY to your .env file and your hosting provider's environment variables.notify: false if you expect many signups and rely on Smart Actions for threshold alerts instead.Try LogIt free
7-day trial. No credit card required.