Guides / SaaS
Feature flags are invisible by default. Logging them lets you:
// lib/flags.ts
import { logit } from "@/lib/logit";
interface FlagEval {
flagKey: string;
value: boolean | string;
userId: string;
source: "launchdarkly" | "growthbook" | "posthog" | "custom";
}
export async function trackFlagEval({ flagKey, value, userId, source }: FlagEval) {
// Only log enabled flags to avoid noise
if (value === false) return;
await logit.now("feature-flags", {
event: "Feature flag enabled",
description: `${flagKey} โ ${String(value)} for user ${userId}`,
icon: "๐ฉ",
notify: false,
tags: { flag: flagKey, source },
metadata: { flagKey, value: String(value), userId, source },
});
}
// When you toggle a flag in your admin panel
export async function trackFlagToggle(
flagKey: string,
newValue: boolean,
toggledBy: string
) {
await logit.now("feature-flags", {
event: newValue ? "Flag enabled" : "Flag disabled",
description: `${flagKey} toggled by ${toggledBy}`,
icon: newValue ? "๐ข" : "๐ด",
notify: true,
tags: { flag: flagKey, action: newValue ? "enable" : "disable" },
metadata: { flagKey, newValue, toggledBy, timestamp: new Date().toISOString() },
});
}
import * as LaunchDarkly from "@launchdarkly/node-server-sdk";
const ldClient = await LaunchDarkly.init(process.env.LD_SDK_KEY!);
const flagValue = await ldClient.variation("new-checkout", { key: userId }, false);
await trackFlagEval({ flagKey: "new-checkout", value: flagValue, userId, source: "launchdarkly" });
import { PostHog } from "posthog-node";
const posthog = new PostHog(process.env.POSTHOG_API_KEY!);
const isEnabled = await posthog.isFeatureEnabled("new-checkout", userId);
if (isEnabled) {
await trackFlagEval({ flagKey: "new-checkout", value: true, userId, source: "posthog" });
}
Try LogIt free
7-day trial. No credit card required.