vTilt
By roleFoundersKnow what to fix firstMarketersSee what happens after the clickCMOsSee what your budget really buys
By businessSaaSTurn signups into active usersEcommerceSee why shoppers abandon cartsAgenciesProve your work to clientsEnterpriseOne customer record for every team
MeasureWeb AnalyticsFind where buyers leaveSession ReplaySee why they left, not just that they didAdsKnow what paid visitors do nextIntegrationsOne snippet feeds your stack
ThinkPeopleOne profile per customerCustomer MemoryvTilt remembers every visitorSite KnowledgeAnswers and audits from your own pages
ActAsk AIAnswers from real behaviorAI ChatChat that knows the visitorEmail CampaignsEmail from real visits
PricingWhy vTiltDocs
Docs / Gatsby
Getting Started
OverviewInstallInitializeIdentify usersTrack eventsLogout & resetVerify eventsCommon mistakes
Guides
Event forwardingReverse proxyRealtime dashboardSite knowledge
Frontend frameworks
Next.jsNuxt.jsVue.jsReactReact RouterRemixGatsbySvelte / SvelteKitAstroAngularTanStack StartDocusaurus
Backend frameworks
NestJSHonoCloudflare WorkersDjangoFlaskLaravelPhoenixRuby on Rails
Backend languages
PythonPHPRubyElixirGoJava.NET / C#Rust
Stack guides
Vue + PHP
API Reference
Browser SDK
Script bundlesAutocaptureWeb VitalsSession recordingChat widgetFeature readinessRemote configurationDebug logging
Node SDK
Install & setupCapture, identify & aliasContext & shutdownGlobal properties & opt-outError tracking
MCP server
Guides
OverviewAuthenticationOAuthAgent skills (prompts)AI intelligenceSite knowledgeGoogle AdsMeta Ads
Client setup
CursorClaude DesktopVS CodeCodex

Getting Started

OverviewInstallInitializeIdentify usersTrack eventsLogout & resetVerify eventsCommon mistakes

Guides

Event forwardingReverse proxyRealtime dashboardSite knowledge
Next.jsNuxt.jsVue.jsReactReact RouterRemixGatsbySvelte / SvelteKitAstroAngularTanStack StartDocusaurus

API Reference

MCP server

On this page

On this page

  • 1. Add your environment variables
  • 2. Install & initialise
  • 3. Identify users
  • 4. Capture custom events
  • Next steps
DocsGuidesFrontend frameworksGatsby

Gatsby

Last updated July 22, 2026

Integrate vTilt with Gatsby — npm package via gatsby-browser.js or an inline script via gatsby-ssr.js, route pageviews, identify on page load.

Gatsby is a static-site React framework. vTilt initialises in the browser — either through gatsby-browser.js (npm) or an injected stub via gatsby-ssr.js (inline script).

#1. Add your environment variables

# .env.development / .env.production
GATSBY_VTILT_TOKEN=YOUR_PROJECT_TOKEN
GATSBY_VTILT_HOST=https://www.vtilt.com
text

#2. Install & initialise

Choose how you load the Browser SDK. npm boots the SDK in gatsby-browser.js; the inline script injects a stub via gatsby-ssr.js with no package to install. Both expose the same window.vt global — the rest of this guide is identical either way.

Install the package:

npm install @v-tilt/browser
bash

Boot the SDK in onClientEntry and emit pageviews from onRouteUpdate:

// gatsby-browser.js
import { vt } from '@v-tilt/browser'

export const onClientEntry = () => {
  vt.init(process.env.GATSBY_VTILT_TOKEN, {
    api_host: process.env.GATSBY_VTILT_HOST,
    autocapture: true,
    capture_pageview: false,
    capture_pageleave: true,
  })
}

export const onRouteUpdate = ({ location, prevLocation }) => {
  vt.capture('$pageview', {
    $current_url: window.location.href,
    $pathname: location.pathname + location.search,
    $referrer: prevLocation?.pathname,
  })
}
javascript

Note

Gatsby's @reach/router doesn't trigger History API events the SDK can pick up automatically. Keep capture_pageview: false and use the onRouteUpdate hook.

Tip

Need chat on first paint? Swap array.js for array.chat.js and add chat: { enabled: true }. See Script bundles.

#3. Identify users

Wrap your app with a small client component that watches your auth state and calls vt.identify() whenever a user is known.

// gatsby-browser.js (continued)
import { vt } from '@v-tilt/browser'
import React, { useEffect } from 'react'
import { useAuth } from './src/auth'

const Identify = ({ children }) => {
  const { user } = useAuth()
  useEffect(() => {
    if (user) vt.identify(user.id, { email: user.email })
  }, [user])
  return children
}

export const wrapRootElement = ({ element }) => <Identify>{element}</Identify>
tsx

Important

Gatsby pages are static HTML at build time. Your useAuth() hook must read the session cookie on the client, otherwise users arriving with an existing session stay anonymous. See Identify & alias for the full model.

#4. Capture custom events

import { vt } from '@v-tilt/browser'

export default function CtaButton() {
  return (
    <button onClick={() => vt.capture('cta_clicked', { location: 'hero' })}>
      Get started
    </button>
  )
}
jsx

#Next steps

  • Identify & alias — anonymous → known user merge, page-load identify pattern.
  • Autocapture — what's captured automatically.
  • Reverse proxy — block-resistant ingestion.
  • Common mistakes — integration pitfalls to avoid before you ship.
PreviousRemixIntegration guidesNextSvelte / SvelteKitIntegration guides