Requirements
- A browser app built with a bundler (Vite, webpack, Next.js, Rollup, esbuild…).
- A public ingest key (
cs_…_pk_…) from an active Codeskop plan.
The package ships as both ES modules and CommonJS, with TypeScript types included. It has no runtime dependencies and is tree-shakeable.
Install
npm install @codeskop/trackeryarn add @codeskop/trackerpnpm add @codeskop/trackerIt's a public, MIT-licensed package, no npm token or .npmrc entry needed. You can install and try it without an account; it only starts sending data once it has a valid key.
No bundler?
Server-rendered sites, WordPress, Webflow and Shopify can use one script tag instead, with no build step.Initialize
Call init once, as early as possible in your entry file, so errors thrown while your app boots are captured too.
import { init } from "@codeskop/tracker"; init({ apiKey: import.meta.env.VITE_CODESKOP_KEY, // cs_live_pk_… release: import.meta.env.VITE_APP_VERSION,});From this point on, the SDK automatically captures:
- uncaught errors and unhandled promise rejections,
- failed
fetchandXMLHttpRequestcalls (network errors and HTTP 4xx/5xx), - the timing of every request,
- a presence heartbeat while the tab is visible.
init returns immediately; queue setup, the config fetch and sending all happen in the background. Requests to Codeskop itself are never captured.
Calling init again
A secondinit call replaces the first: the previous setup is torn down and a fresh one starts with the new config. Most apps call it exactly once.Use a test key outside production
Keep development traffic out of your production data by switching keys per build:
init({ apiKey: import.meta.env.PROD ? "cs_live_pk_YOUR_LIVE_KEY" : "cs_test_pk_YOUR_TEST_KEY",});Identify users
import { identify, reset } from "@codeskop/tracker"; onLogin((user) => identify(user.id));onLogout(() => reset());Use your own stable user ID, never an email address. Until you call identify, events are attributed to an anonymous ID stored in localStorage (or a cookie if storage is unavailable).
About traits
identify accepts an optional traits object for API compatibility, but the web SDK doesn't send traits today; only the user ID reaches Codeskop.Report handled errors
Errors you catch yourself never reach the global handlers. Report the ones you care about with recordException:
import { recordException } from "@codeskop/tracker"; try { await checkout(cart);} catch (error) { recordException(error); showCheckoutError();}Handled exceptions are always kept and never sampled away.
Let users opt out
import { setEnabled } from "@codeskop/tracker"; // e.g. when a user turns off diagnostics in your settings screensetEnabled(false);setEnabled(false) pauses all capture until you call setEnabled(true). It lasts for the current page session. Call it again after init on the next load if the user's choice should persist.
Server-side rendering
The SDK only does browser work, and every function is safe to import on the server. In Next.js, Remix and similar frameworks, call init from client-only code. For React apps, the React provider handles this for you.