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.
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://core.flow-grid.xyz/flowgrid.js"
3 data-site="YOUR_WEBSITE_ID"
4 project-id="YOUR_PROJECT_ID"
5 defer
6></script>Where to find your IDs
Open your Dashboardand select your project. Under the project name you'll see a Project ID chip — click it to copy your project-id. Your data-site(Website ID) is 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.productView({ productId: "sku_1", name: "T-Shirt", price: 29 });
5 FlowGrid.addToCart({ productId: "sku_1", name: "T-Shirt", price: 29 }, 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
3await fg.track("signup_completed", { plan: "pro" });
4fg.identifyUser("u_123", { plan: "pro", email: "alice@example.com" });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: [] });Identify users
Call identifyUser after sign-in. All subsequent events from that session are attributed to this user in your dashboard.
1import { fg } from "@/lib/flowgrid";
2
3fg.identifyUser("u_123", {
4 email: "alice@example.com",
5 plan: "pro",
6 company: "Acme Corp",
7 createdAt: "2024-01-15",
8});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, experiments |
| Analytics | pageViews, sessions, events, identify, heatmaps, performance, replay |
| Ecommerce | products, cart, checkout, purchases, refunds, promotions, wishlist, ltv, search, subscriptions |
| Enterprise | engagement, cohorts, churn, monetization, support, acquisition, paths, 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
Be GDPR / CCPA-friendly 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
Works in Node, Bun, Deno, Cloudflare Workers, Vercel Edge — anywhere with fetch. Construct an instance directly on the server.
1import { FlowGrid } from "flowgrid-sdk";
2
3const fg = new FlowGrid(
4 process.env.FLOWGRID_WEB_ID!,
5 "https://core.flow-grid.xyz",
6 process.env.FLOWGRID_API_KEY!,
7);
8
9export async function POST(req: Request) {
10 const { userId, event } = await req.json();
11 await fg.events.track({ eventName: event, properties: { userId } });
12 return Response.json({ ok: true });
13}