Getting Started
SDK Quickstart
Get Flowgrid tracking in your app in under 5 minutes. Pick the path that fits your stack — script tag for zero-build sites, or the npm SDK for typed, full-feature access in any JS runtime.
The package is published on npm: npmjs.com/package/flowgrid-sdk.
Let your AI assistant set it up
Copy the prompt into the assistant or coding agent you build with. It installs flowgrid-sdkwith your package manager (npm, pnpm, bun or yarn), or the CDN script tag where there's no build step, and identifies signed-in users.
Paste it into Claude Code in your project, or into claude.ai.
Set up Flowgrid analytics (https://flow-grid.xyz) on my website. If you can see my code (Claude Code, or a repo I've attached), make the changes; if not, tell me exactly what to paste and where.
My Flowgrid Website ID and API key: don't ask me for them, and never write them into code or into this chat.
- In a codebase, read them from public environment variables — NEXT_PUBLIC_FLOWGRID_WEB_ID and NEXT_PUBLIC_FLOWGRID_API_KEY (or the framework's own public prefix, e.g. VITE_FLOWGRID_WEB_ID). Add the names to the env example file and tell me which file to put the values in; I'll paste them myself from Flowgrid (Dashboard → my website).
- Where there is no codebase (a CMS head snippet), keep the placeholders YOUR_WEBSITE_ID and YOUR_API_KEY exactly as written and tell me where to replace them.
1. Find out what my website is built with (read package.json and the lockfile, or ask me which CMS) and tell me before changing anything.
2. Install the Flowgrid SDK (https://www.npmjs.com/package/flowgrid-sdk) with the package manager the project already uses — match the lockfile:
- package-lock.json: npm install flowgrid-sdk
- pnpm-lock.yaml: pnpm add flowgrid-sdk
- bun.lock or bun.lockb: bun add flowgrid-sdk
- yarn.lock: yarn add flowgrid-sdk
3. Start it once, for the whole app:
- Next.js: in the root layout, wrap {children} in <FlowgridProvider webId={process.env.NEXT_PUBLIC_FLOWGRID_WEB_ID} apiKey={process.env.NEXT_PUBLIC_FLOWGRID_API_KEY}> imported from "flowgrid-sdk/next".
- React (Vite, Lovable, Bolt): the same <FlowgridProvider>, imported from "flowgrid-sdk/react", around the app in the entry file.
- Any other JavaScript app (Vue, Svelte, plain TS): call Flowgrid.init({ webId, apiKey }) once in the entry file, imported from "flowgrid-sdk".
- No build step (plain HTML, or a CMS like WordPress, Webflow, Shopify, Framer): skip the install and put this tag once in <head> instead:
<script src="https://cdn.flow-grid.xyz/flowgrid.min.js" data-site="YOUR_WEBSITE_ID" data-api-key="YOUR_API_KEY"></script>
Pageviews, sessions, page changes in single-page apps, Core Web Vitals, heatmaps and traffic sources are then tracked automatically. Don't add manual page-view calls.
4. If the website has sign-in, identify the signed-in user once the session is known:
- React or Next.js: render <FlowgridUser id={user.id} traits={{ email: user.email, name: user.name }} /> (same import as the provider) inside the provider. For a next-auth, Clerk or Supabase session, <FlowgridUser from={session} /> works too.
- Script tag: window.FlowGrid && window.FlowGrid.identify(user.id, { email: user.email, name: user.name });
5. Custom events, only where I ask for them: Flowgrid.instance()?.track("event_name", { ...properties }) (Flowgrid from "flowgrid-sdk"), or window.FlowGrid.track(...) with the script tag. Feature flags: useFlag("flag-key") from the same React import.
6. Tell me how to check it works: tracking is off on localhost by design, so deploy or open a preview URL, browse a page, and confirm requests to core.flow-grid.xyz in the browser's network tab and a live visitor in the Flowgrid dashboard.
Forms: the SDK doesn't capture forms. If I give you a form ID, follow the forms step at https://flow-grid.xyz/documentation/create-form-events instead of inventing one.
Rules: use only the Flowgrid APIs above or in https://flow-grid.xyz/documentation — never guess a method name. Don't add or remove other analytics tools. Keep the change small and explain each edit.Option A — Script tag no build step
Paste one tag in your <head>. Flowgrid auto-tracks pageviews, SPA navigation, sessions, scroll depth, performance (Core Web Vitals), heatmaps, and attribution immediately.
1<script
2 src="https://cdn.flow-grid.xyz/flowgrid.min.js"
3 data-site="YOUR_WEBSITE_ID"
4 data-api-key="YOUR_API_KEY"
5></script>Where to find your IDs
Open your Dashboard and select your site. Your data-site (Website ID) and data-api-key(API key) are shown alongside your connected site. Paste both into the snippet above and you're live.
The global FlowGrid object is available for custom events:
1<script>
2 FlowGrid.track("signup_clicked", { placement: "hero" });
3 FlowGrid.identify("user_123", { plan: "pro", email: "alice@example.com" });
4 FlowGrid.track("product_view", { productId: "sku_1", name: "T-Shirt", price: 29 });
5 FlowGrid.track("add_to_cart", { productId: "sku_1", name: "T-Shirt", price: 29, quantity: 1 });
6</script>Localhost
Events are blocked on localhost
Option B — npm SDK TypeScript · any runtime
Works in React, Vue, Next.js, Svelte, Node, Cloudflare Workers, Vercel Edge — anywhere with fetch. Zero peer dependencies, Node >= 18.12.
Install the package
1npm install flowgrid-sdkCreate a shared instance
Call FlowGrid.init() once — in your app entry point or a dedicated lib file — then import the result everywhere.
1import { FlowGrid } from "flowgrid-sdk";
2
3export const fg = FlowGrid.init({
4 webId: process.env.NEXT_PUBLIC_FLOWGRID_WEB_ID!,
5 apiKey: process.env.NEXT_PUBLIC_FLOWGRID_API_KEY!,
6 autoTrack: {
7 replay: true, // session replay
8 engagement: true, // scroll depth, time on page, idle detection
9 performance: true, // Core Web Vitals
10 },
11});Environment variables
Store your IDs as NEXT_PUBLIC_FLOWGRID_WEB_ID and NEXT_PUBLIC_FLOWGRID_API_KEY. Never hard-code credentials in source.
Track your first event
1import { fg } from "@/lib/flowgrid";
2
3// Record a signup: identifies the user, fills the "Signed up" stage and counts them as active.
4fg.trackAuth({ event: "signup", userId: "u_123", email: "alice@example.com", method: "google" });That's it — you're tracking. Read on for events, identification, ecommerce, and more.
Track events
fg.track(eventName, properties) handles everything. Use any string for custom events. Certain well-known names are automatically routed to the correct feature module.
1import { fg } from "@/lib/flowgrid";
2
3// Custom events — any name works
4await fg.track("cta_clicked", { placement: "hero" });
5await fg.track("filter_applied", { filter: "size", value: "L" });
6await fg.track("video_played", { videoId: "intro", duration: 120 });
7
8// Named events routed to feature modules
9await fg.track("feature_used", { featureId: "export", featureName: "Data Export", userId: "u_1" });
10await fg.track("add_to_cart", { productId: "sku_1", name: "T-Shirt", price: 29, currency: "USD", quantity: 1 });
11await fg.track("purchase", { orderId: "ord_1", total: 49.99, currency: "USD", items: [] });
12
13// Acquisition — one-liners for signup/login (see the Signups & Logins guide)
14fg.signup("u_1", "google"); // → Acquisition Funnel "Signed up"
15fg.login("u_1", "google"); // → returning-user / Logins tileIdentify users
Call setUser wherever your app knows who is signed in, on every page load. Every event from then on belongs to that person, and the traits you pass feed feature flag rules.
1import { fg } from "@/lib/flowgrid";
2
3fg.setUser(user.id, {
4 email: user.email,
5 plan: user.plan,
6 company: user.company,
7});
8
9// On sign-out
10fg.setUser(null);Sign-ins that complete on your server use trackAuth there instead. See Identify users.
All namespaces
Every namespace is a lazy property — zero overhead until accessed. Use them for strongly-typed, module-specific APIs instead of track().
| Group | Namespaces |
|---|---|
| Core | activation, features, prompts, flags |
| Analytics | pageViews, sessions, events, identify, heatmaps, performance, replay |
| Growth | funnels, multiPathFunnels, retention, attribution, subscriptions |
| Enterprise | engagement, cohorts, churn, monetization, support, acquisition, paths, alerts, security, forecasting |
Session replay
Enabled by autoTrack.replay: true in your init config (shown above). Records DOM/scroll/click events via rrweb and sends sequenced chunks to your dashboard. No extra code needed — toggle the sample rate and input masking to tune it.
1FlowGrid.init({
2 webId: "...", apiKey: "...",
3 autoTrack: {
4 replay: { sampleRate: 0.25, maskAllInputs: true }, // tune it
5 // replay: false, // or opt out entirely
6 },
7});Cookie consent
Ask visitors for consent in a couple of lines. setupConsent()creates a consent manager and keeps FlowGrid's consent gates in sync automatically, and attachConsentBanner()wires an existing HTML banner's buttons for you.
1import { attachConsentBanner } from "flowgrid-sdk";
2
3// Wires #accept-btn / #reject-btn inside #cookie-banner and shows it
4// only when the visitor hasn't consented yet.
5attachConsentBanner({ cookieName: "my_app_consent", cookieDays: 180, respectDNT: true });Full walkthrough — banner markup, a React component, re-opening the banner, and consent categories — on the Cookie consent page.
Server-side & edge
Use the dedicated flowgrid-sdk/server entry point — a Node/edge-safe client for identity, feature usage and API / server error tracking. Works in Node ≥ 18, Bun, Deno, Cloudflare Workers, Vercel Edge — anywhere with fetch.
1import { FlowGridServer } from "flowgrid-sdk/server";
2
3const fg = FlowGridServer.init({
4 webId: process.env.NEXT_PUBLIC_FLOWGRID_WEB_ID!,
5 apiKey: process.env.FLOWGRID_API_KEY!, // private key — server env only
6});
7
8// Identity from a server auth flow: identify + login event + DAU ping.
9await fg.trackAuth({ event: "login", userId: user.id, email: user.email });
10
11// Feature usage from an API route.
12await fg.trackFeature({ featureId: "csv_export", featureName: "CSV Export", userId: user.id });
13
14// Server error tracking with endpoint context.
15await fg.trackError(err, { route: "/api/export", method: "POST", statusCode: 500 });Full guide — auth events, linking the web session via visitorIdFromCookies(), defineFeature, error wrapping and delivery guarantees — on the Server-Side Tracking page.