Install Analytics
Pick the script tag, npm or your framework
There are 3 ways to add Viakite Analytics to a site: the script tag, the npm package, or the <Analytics /> component for your framework. All of them send the same data and take the same options. Pick the one that fits how your site is built, then check that events arrive.
Pick a way
| Way | Best for | Install | Calls from your code |
|---|---|---|---|
| Script tag | Any site: plain HTML, WordPress, Shopify, Webflow | One <script> line | window.viakite.track(…) |
| npm | Apps with a bundler and no framework component | npm install @viakite/sdk, then init() | import { track } from "@viakite/sdk" |
| Next.js | App Router and Pages Router | <Analytics /> in the root layout | import { track } from "@viakite/sdk" |
| React | Vite, Create React App, React Router | <Analytics /> at the top of the app | import { track } from "@viakite/sdk" |
| Vue | Vue 3 and Nuxt | <Analytics /> in App.vue | import { track } from "@viakite/sdk" |
| Svelte | Svelte 5 and SvelteKit | <Analytics /> in the root layout | import { track } from "@viakite/sdk" |
Every way follows page changes in single-page apps, measures engaged time and scroll depth, and tracks outbound links and file downloads. The script is under 3 KB gzipped, sets no cookies and stores nothing on the visitor's device.
You need your project's public key, which starts with pk_live_. The Install page in the dashboard (Analytics → Install) shows it, and gives you every snippet below with the key filled in.
Add it to your site
1<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…"></script>
1import { init } from "@viakite/sdk";23init({ project: "pk_live_us_…" });
1import { Analytics } from "@viakite/sdk/react";23export default function RootLayout({ children }: { children: React.ReactNode }) {4return (5<html lang="en">6<body>7{children}8<Analytics project="pk_live_us_…" />9</body>10</html>11);12}
1import { Analytics } from "@viakite/sdk/react";23export function App() {4return (5<>6<Analytics project="pk_live_us_…" />7{/* your routes */}8</>9);10}
1<script setup lang="ts">2import { Analytics } from "@viakite/sdk/vue";3</script>45<template>6<Analytics project="pk_live_us_…" />7<RouterView />8</template>
1<script>2import Analytics from "@viakite/sdk/svelte";3let { children } = $props();4</script>56<Analytics project="pk_live_us_…" />7{@render children()}
Put the script tag in the <head> of every page. For the other ways, install the package first:
1npm install @viakite/sdk
1pnpm add @viakite/sdk
1yarn add @viakite/sdk
React, Vue and Svelte are optional peer dependencies of the package, so you only need the one you use. Add <Analytics /> once, at the root of your app; a second one does nothing.
Where the script lives
Today the script is served from your region's API host, https://us.api.vk.viabio.me/v1/a.js. A CDN address is planned. Copy the snippet from the Install page and you always get the current address.
Turn on options
The same options work everywhere: as data- attributes on the script tag, as fields of init(), or as props of <Analytics />.
1<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…" data-title data-hash></script>
1<Analytics project="pk_live_us_…" title hash />
The most used are title (send the page title, off by default), hash (count /#/about routes as pages), params (keep extra query parameters), outbound and downloads (on by default), debug and localhost. The Install page's Options card sets them all (switches, extra parameters, download extensions, and a note on data-404 for your not-found page) and updates the snippet as you go. The full list is in Options.
Check that it works
Open your site
Deploy, then visit a page with Viakite on it. Nothing is sent from
localhost,127.0.0.1orfile://unless you adddata-localhost(or thelocalhostprop). An ad blocker may stop the script; try a private window, or serve it through your own domain (the Install page's Serve from your domain card gives the config for your host).Watch the Install page
The top of the Install page says Waiting for the first event… until your project's first event arrives, then turns to Events are arriving on its own. Below it, Last events lists the events of the last 24 hours with their page, browser and any warnings, and refreshes every 5 seconds.
See yourself in Realtime
Open Analytics → Realtime. Your visit shows within a few seconds.
Still nothing? Add data-debug (or the debug prop) and reload: each event shows in the browser console, and nothing is sent. More in Debugging.
With a test key (pk_test_…), your visit won't show in Realtime or any report: test events are kept apart. Look for it in the event list on the Install page instead, marked test.