On this page
Install
Last updated
Add the vTilt Browser SDK via the inline script stub (recommended default) or the npm package. Both are fully supported and expose the same API once init runs.
Add the Browser SDK one of two ways — both are fully supported and expose the same API once you call vt.init():
- Inline script stub — recommended default. Same snippet as the dashboard Integration Script. It queues calls before
array.jsfinishes loading (nothing is dropped during boot) and always loads the latest SDK from the CDN. No build step, no dependency to keep updated. - npm / pnpm package —
@v-tilt/browser. A great fit when your app is already bundled and you want typed imports and a pinned version that ships in your own bundle.
#Choose an install path
Paste this into your HTML <head> — or copy it from Settings → Project → Integration Script in the dashboard. The loader is minified to one line (same pattern as Google's gtag.js); vt.init() follows in the same block:
<!-- Add to your HTML <head> -->
<script>
!function(t,e){var o,n,p,r;function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}if(!e.__SV&&!(window.vt&&window.vt.__loaded)){window.vt=e,e._i=[],o="init capture identify setUserProperties resetUser getUserIdentity getDeviceId getUserState alias getConfig getSessionId updateConfig setConsent on once off startAutocapture stopAutocapture startSessionRecording stopSessionRecording openChat closeChat toggleChat showChat hideChat sendChatMessage gtag setGoogleUserData".split(" ");for(n=0;n<o.length;n++)g(e,o[n]);e.init=function(i,s,a){(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.script_host?s.script_host+"/array.js":s.api_host+"/dist/array.js",p.onerror=function(){console.error("vTilt: Failed to load library script:",p.src)},(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="vt",u.toString=function(t){var e="vt";return"vt"!==a&&(e+="."+a),t||(e+=" (stub)"),e},n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1}}(document,window.vt||[]);
vt.init('YOUR_PROJECT_TOKEN', {
api_host: 'https://www.vtilt.com',
autocapture: true,
capture_pageview: true,
capture_pageleave: true,
persistence: 'localStorage',
});
</script>The minified loader creates window.vt and queues every call; vt.init() then loads array.js and flushes the queue. For all init options see Initialize the SDK.
#Script tag vs npm — which should I pick?
Both ship the same SDK. The inline script is the recommended default; the npm package is a fully-supported alternative. Here are the trade-offs:
#Inline script — pros and cons
Pros
- Queues early calls.
identify()/capture()made beforearray.jsloads are buffered and flushed — nothing is dropped during boot. - Always the latest SDK.
array.jsis served from the CDN, so fixes and features arrive with no version bump on your side. - Zero build tooling. Works on any site, including no-build and server-rendered stacks (Rails, Laravel, Django, plain HTML).
- Sets
window.vtfor you; matches the dashboard Integration Script verbatim.
Cons
- One extra network request for
array.js(async, non-blocking). - If you call APIs very early, the stub must list every method you use (see note below).
- You don't pin a version — you always track the latest published SDK.
#npm package — pros and cons
Pros
- Typed imports and editor autocomplete from
@v-tilt/browser. - Pinned version that ships inside your own bundle (reproducible builds).
- No separate loader request — the SDK is part of your JS bundle.
Cons
- Requires a build step / bundler.
- You upgrade the SDK by bumping the package version yourself.
window.vtis not set automatically — use the importedvt, or assign it once (see the npm tab above).
If you use the script tag and call APIs early (vt.sendChatMessage(), vt.updateConfig(…)), ensure your stub lists every method you use. The canonical set is VTILT_SNIPPET_STUB_METHOD_NAMES in @v-tilt/browser.
#Script tag
For sites without a build step, paste the stub into <head>. It creates window.vt, queues every call, and loads array.js when you call init().
The full stub (including a sample vt.init()) is in the Inline script tab above and in Settings → Project → Integration Script.
#Next step
Call vt.init() once with your project token — Initialize the SDK.