Guides / Signups & Auth

How to Track User Signups in SvelteKit

3 min read·Signups & Auth

The Problem

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.

Setup

bash
npm install logit

Create src/lib/logit.ts:

ts
import { init } from "logit";
import { LOGIT_API_KEY } from "$env/static/private";

export const logit = init({ token: LOGIT_API_KEY });

In a Form Action

ts
// 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 };
  },
};

In an API Route

ts
// 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 });
};

Tips

  • Use $env/static/private (not $env/dynamic/private) so the key is tree-shaken out of client bundles.
  • Add LOGIT_API_KEY to your .env file and your hosting provider's environment variables.
  • Set 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.

Start free