npm package
npm install @x3growth/sdkThe package is published on npm as @x3growth/sdk
(source: X3Growth/x3-sdk, MIT). Other package managers:
pnpm add @x3growth/sdk
yarn add @x3growth/sdk
bun add @x3growth/sdkImports: @x3growth/sdk, @x3growth/sdk/next, @x3growth/sdk/react, @x3growth/sdk/server, … (ESM and
CommonJS, bundled TypeScript types). Installs from the tarball URL an X3 API served before the registry
release (/v1/sdk/x3growth-sdk-<version>.tgz) keep working; switch them to the registry with
npm install @x3growth/sdk.
import { init, track } from "@x3growth/sdk";
init({ key: "pk_3x_YOUR_PUBLISHABLE_KEY", host: "https://api.3x.example" });
track("newsletter_signup", { list: "weekly" });Call init once, as early as possible on the client (for example in src/main.tsx before
rendering). It is idempotent: a second call behaves like a SPA navigation, never a second tracker.
On the server (SSR) every function is a no-op.
Entry points
| Import | Contents |
|---|---|
@x3growth/sdk | init, track, goal, funnelStep, page, identify, conversion, consent, flush, getIds, optOut, optIn, the preset helpers, the x3 object, VERSION and the attribute maps DATA_ATTRIBUTES / LEGACY_DATA_ATTRIBUTES (Data attributes) |
@x3growth/sdk/plugins | video(), sections(), forms(), identify(), consent(), bookings(), journeys() – tree-shakeable plugins, plus CMP_ADAPTERS |
@x3growth/sdk/presets | funnel bridges, booking/quiz listeners, reportBooking(), event ids and CMP bridges (Presets entry point) |
@x3growth/sdk/react | <X3Provider>, useX3(), useTrackOnMount() (React) |
@x3growth/sdk/next | <X3Analytics>, fetchClientConfig(), QUEUE_STUB, inlineJson() (Next.js) |
@x3growth/sdk/next/proxy | createX3ProxyHandler() for the first-party proxy and its building blocks (Proxy for Next.js) |
@x3growth/sdk/server | createX3Server(), requestContext(), clientIpFrom(), cookieValue(), X3ServerError – Node/edge helper with a secret key (Server helper) |
@x3growth/sdk/pixel | createX3Pixel(), shopifyPixel() – DOM-free transport for sandboxed pixels (Pixel transport) |
ESM and CommonJS builds are shipped for the core, /server, /next/proxy, /presets and
/plugins; /react and /next are ESM with "use client" preserved. Types are bundled.
Plugins
The npm core does not include the video, sections and forms plugins – install the ones you need:
import { init } from "@x3growth/sdk";
import { forms, sections, video } from "@x3growth/sdk/plugins";
init({ key: "pk_3x_…", host: "/n3", plugins: [video(), sections(), forms()] });| Plugin | What it adds |
|---|---|
video() | <video> coverage, video_start / video_complete (Video) |
sections() | section reach and visible time (Sections) |
forms() | form_start, form_submit, form_abandon (Forms) |
identify() | normalization and hashing for identify() (Identify) |
consent() | the CMP adapters configured in consent.cmp (Consent) |
bookings() | the booking adapters and window-event bridges of the tracking config |
journeys() | visitor id, click ids and ad cookies after consent (Journeys after consent) |
Plugins you do not pass are loaded lazily (dynamic import()) when the project config enables them
or the API is first used – identify(), consent adapters and booking adapters included.
Options
init({
key: "pk_3x_…", // publishable key (required)
host: "/n3", // API origin or proxy path; default "/n3" (the first-party proxy) – set the API origin if you have no proxy
config: clientConfig, // inline client config (skips GET /v1/c/{pk})
consent: "pending", // initial consent; default: read from the consent key / CMP adapters
autocapture: { pageviews: true, clicks: true, scroll: true, engagement: true, forms: true, video: true, sections: true }, // outboundLinks/downloads/notFound: false switches a project's auto-capture off on this page
plugins: [], // ESM plugins
hashRouting: false, // #/route changes are pageviews
test: false, // mark this page load as test traffic
respectDoNotTrack: false, // true: no tracking at all when the browser sends DNT (overrides the project setting)
debug: false, // window.__x3 + console diagnostics
});The complete API with every method is in the SDK reference.
Pixel transport
@x3growth/sdk/pixel is a transport without DOM, window or storage – only fetch(keepalive) and
timers – for sandboxes such as Shopify app/custom web pixels and web workers. Pageviews carry no
viewport or scroll data (like consent mode strict); events attach to the latest pageview.
import { createX3Pixel, shopifyPixel } from "@x3growth/sdk/pixel";
const x3 = createX3Pixel({ key: "pk_3x_…", host: "https://api.3x.example", consent: init.customerPrivacy.analyticsProcessingAllowed });
analytics.subscribe("all_standard_events", (event) => shopifyPixel(x3, event));createX3Pixel({ key, host, config?, consent?, test?, fetch?, flushDelayMs? })returnspage({ url, referrer? }),track(name, props?, { flush? }),consent(granted),flush()andgetIds().hostmust be absolute (the sandbox has no page origin).shopifyPixel(pixel, event)maps Shopify standard events:page_viewed→ pageview,checkout_completed→purchase {value, currency}(sent right away),checkout_started,product_added_to_cart→add_to_cart,product_viewed,search_submitted→search. No order ids, e-mail addresses or line items are sent.
Script tag or npm?
Both have the same behaviour. Prefer npm when you have a bundler and want types and tree-shaking; prefer the script tag when you cannot add dependencies or want the tracker updated without a deploy. Do not use both on the same page.