vTilt
Why vTiltHow It WorksFeaturesFAQDocs
Docs / Gatsby
Quick startEvent forwarding
MCP server
Guides
OverviewAuthenticationOAuthAgent skills (prompts)AI intelligenceGoogle Ads
Client setup
CursorClaude DesktopVS CodeCodex
Realtime
Debug ViewRealtime Dashboard
Integration guides
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
SDK
Browser SDK
InstallScript bundlesEvent trackingAutocaptureIdentify & aliasWeb VitalsSession recordingChat widgetFeature readinessRemote configurationReverse proxyDebug logging
Node SDK
Install & setupCapture, identify & aliasContext & shutdown

Documentation

vTilt
Quick startEvent forwarding

MCP server

Realtime

Debug ViewRealtime Dashboard

Integration guides

Next.jsNuxt.jsVue.jsReactReact RouterRemixGatsbySvelte / SvelteKitAstroAngularTanStack StartDocusaurus

SDK

DocsIntegration guidesGatsby

Gatsby

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

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

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

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.
PreviousRemixIntegration guidesNextSvelte / SvelteKitIntegration guides

On this page

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