
Launchdarkly Metric Instrument
Instrument product and experiment metrics with LaunchDarkly `track()` using the correct server-side vs client-side SDK patterns in an existing codebase.
Overview
LaunchDarkly metric instrument is an agent skill most often used in Grow (also Build integrations) that teaches correct LaunchDarkly SDK `track()` patterns for count and value metrics.
Install
npx skills add https://github.com/launchdarkly/agent-skills --skill launchdarkly-metric-instrumentWhat is this skill?
- Documents server-side vs client-side `track()` rules (context required on server; not on browser client)
- Node.js patterns for `@launchdarkly/node-server-sdk` including count metrics, value metrics, and custom payloads
- Browser client patterns for `launchdarkly-js-client-sdk` signup and conversion-style events
- Shows explicit `flush()` for tests and short-lived server processes
- Matches instrumentation to patterns already present in the repo before adding new calls
- Server-side LaunchDarkly SDKs require a context on every `track()` call; client-side browser SDKs do not.
- Reference covers Node server (`@launchdarkly/node-server-sdk`) and browser (`launchdarkly-js-client-sdk`) track patterns
Adoption & trust: 1.3k installs on skills.sh; 16 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need LaunchDarkly custom metrics in production code but each SDK calls `track()` differently and server-side context requirements are easy to get wrong.
Who is it for?
SaaS or app builders already on LaunchDarkly who are adding checkout, signup, or latency metrics during feature work or growth experiments.
Skip if: Teams who only need boolean feature flags with no custom metrics, or greenfield projects with no LaunchDarkly SDK in the stack yet.
When should I use this skill?
You are adding or fixing LaunchDarkly custom metric `track()` calls and need SDK-specific patterns aligned with the codebase.
What do I get? / Deliverables
Your agent adds `track()` calls that match LaunchDarkly’s server vs client contracts and your repo’s existing SDK usage so experiments collect reliable metric data.
- Correct `track()` invocations for count and value metrics
- Optional custom data payloads and test-time flush handling
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Canonical shelf is Grow because the skill’s purpose is measurable outcomes and metric events, not flag authoring alone. Analytics is where solo builders wire occurrence and value metrics to experiments and releases after features ship.
Where it fits
Add `api-response-time` value metrics on a Fastify route while rolling out a flag-gated endpoint.
Verify `checkout-completed` occurrence events flush correctly in staging before enabling a production experiment.
Standardize purchase amount value metrics with custom payloads for apparel vs digital goods cohorts.
How it compares
Use for SDK metric wiring reference, not as a full LaunchDarkly project bootstrap or flag-definition skill.
Common Questions / FAQ
Who is launchdarkly-metric-instrument for?
Solo and indie builders shipping web or Node services who use LaunchDarkly for experimentation and need correct `track()` instrumentation in TypeScript or JavaScript codebases.
When should I use launchdarkly-metric-instrument?
During Build when wiring backend or client integrations, during Ship when validating experiment events before launch, and during Grow when defining analytics for conversions, purchases, or performance value metrics.
Is launchdarkly-metric-instrument safe to install?
Treat it as procedural guidance that may suggest SDK keys and network calls; review the Security Audits panel on this Prism page and scope secrets via environment variables before running agent-suggested installs.
SKILL.md
READMESKILL.md - Launchdarkly Metric Instrument
# SDK Track Patterns How to call `track()` in each LaunchDarkly SDK. Use this reference to match the patterns already in use in the codebase — and to add the right call when starting fresh. The key distinction across all SDKs: **server-side SDKs require a context per call; client-side SDKs do not.** --- ## JavaScript / TypeScript — Node.js (Server-side) **Package:** `@launchdarkly/node-server-sdk` (v9+) or `launchdarkly-node-server-sdk` (v6–v8) ```bash npm install @launchdarkly/node-server-sdk ``` ```typescript import * as ld from '@launchdarkly/node-server-sdk'; const client = ld.init(process.env.LD_SDK_KEY!); await client.waitForInitialization(); // Count / occurrence metric (no metricValue) client.track('checkout-completed', context); // Value metric — pass the measurement as metricValue client.track('api-response-time', context, null, responseTimeMs); // With custom data payload client.track('item-purchased', context, { itemId: 'abc123', category: 'apparel' }, purchaseAmount); // Flush explicitly in tests / short-lived processes await client.flush(); ``` --- ## JavaScript / TypeScript — Browser (Client-side) **Package:** `launchdarkly-js-client-sdk` ```bash npm install launchdarkly-js-client-sdk ``` ```typescript import * as ld from 'launchdarkly-js-client-sdk'; const client = ld.initialize(clientSideId, context); await client.waitForInitialization(); // Count / occurrence metric — no context, no metricValue client.track('signup-completed'); // Value metric client.track('page-load-time', null, performanceMs); // With custom data client.track('item-added-to-cart', { itemId: 'abc123' }, itemPrice); // Flush (useful in tests or before navigating away) await client.flush(); ``` --- ## React (Client-side) **Package:** `launchdarkly-react-client-sdk` ```bash npm install launchdarkly-react-client-sdk ``` ```tsx import { useLDClient } from 'launchdarkly-react-client-sdk'; function CheckoutButton() { const ldClient = useLDClient(); const handleSubmit = async () => { await processCheckout(); // Count / occurrence metric ldClient?.track('checkout-completed'); // Value metric ldClient?.track('checkout-revenue', null, orderTotal); }; return <button onClick={handleSubmit}>Complete Order</button>; } ``` **Initialization** (typically in the app root via `LDProvider` or `asyncWithLDProvider`): ```tsx import { LDProvider } from 'launchdarkly-react-client-sdk'; // Wrap your app — context is set here, not in each track() call <LDProvider clientSideID={clientSideId} context={userContext}> <App /> </LDProvider> ``` --- ## Python (Server-side) **Package:** `launchdarkly-server-sdk` ```bash pip install launchdarkly-server-sdk ``` ```python import ldclient from ldclient.config import Config ldclient.set_config(Config(sdk_key)) client = ldclient.get() # Count / occurrence metric client.track('checkout-completed', context) # Value metric client.track('api-response-time', context, None, response_time_ms) # With data payload client.track('item-purchased', context, {'item_id': 'abc123'}, purchase_amount) # Flush client.flush() ``` --- ## Go (Server-side) **Package:** `github.com/launchdarkly/go-server-sdk/v7` ```bash go get github.com/launchdarkly/go-server-sdk/v7 ``` ```go import ( ld "github.com/launchdarkly/go-server-sdk/v7" "github.com/launchdarkly/go-server-sdk/v7/ldcontext" ) client, _ := ld.MakeClient(sdkKey, 5*time.Second) defer client.Close() // Count / occurrence metric client.TrackEvent("checkout-completed", context) // Value metric client.TrackMetric("api-response-time", context, responseTimeMs, nil) // With data payload data := ldvalue.BuildObject().Set("itemId", ldvalue.String("abc123")).Build() client.TrackData("item-purchased", context, data) ``` --- ## Java (Server-side) **Package:** `com.launchdarkly:launchdarkly-java-server-sdk` ```xml <!-- Maven --> <dependency> <groupId>com.launchdarkly</groupId> <artifactId>launchdarkly-java-server-