viakite
Dashboard

Guides/Install/Install Analytics

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

WayBest forInstallCalls from your code
Script tagAny site: plain HTML, WordPress, Shopify, WebflowOne <script> linewindow.viakite.track(…)
npmApps with a bundler and no framework componentnpm install @viakite/sdk, then init()import { track } from "@viakite/sdk"
Next.jsApp Router and Pages Router<Analytics /> in the root layoutimport { track } from "@viakite/sdk"
ReactVite, Create React App, React Router<Analytics /> at the top of the appimport { track } from "@viakite/sdk"
VueVue 3 and Nuxt<Analytics /> in App.vueimport { track } from "@viakite/sdk"
SvelteSvelte 5 and SvelteKit<Analytics /> in the root layoutimport { 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

index.html
1<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…"></script>
src/main.ts
1import { init } from "@viakite/sdk";
2
3init({ project: "pk_live_us_…" });
app/layout.tsx
1import { Analytics } from "@viakite/sdk/react";
2
3export default function RootLayout({ children }: { children: React.ReactNode }) {
4 return (
5 <html lang="en">
6 <body>
7 {children}
8 <Analytics project="pk_live_us_…" />
9 </body>
10 </html>
11 );
12}
src/App.tsx
1import { Analytics } from "@viakite/sdk/react";
2
3export function App() {
4 return (
5 <>
6 <Analytics project="pk_live_us_…" />
7 {/* your routes */}
8 </>
9 );
10}
App.vue
1<script setup lang="ts">
2import { Analytics } from "@viakite/sdk/vue";
3</script>
4
5<template>
6 <Analytics project="pk_live_us_…" />
7 <RouterView />
8</template>
src/routes/+layout.svelte
1<script>
2 import Analytics from "@viakite/sdk/svelte";
3 let { children } = $props();
4</script>
5
6<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:

terminal
1npm install @viakite/sdk
terminal
1pnpm add @viakite/sdk
terminal
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 />.

index.html
1<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…" data-title data-hash></script>
app/layout.tsx
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

  1. Open your site

    Deploy, then visit a page with Viakite on it. Nothing is sent from localhost, 127.0.0.1 or file:// unless you add data-localhost (or the localhost prop). 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).

  2. 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.

  3. 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.

Next steps