viakite
Dashboard

SDKs/Web/Options

Options

Every option of init and its types

These are the options of init(). The same settings are the script tag's data-* attributes and the props of <Analytics /> for React, Vue and Svelte, with the same names and defaults everywhere. Only project is required.

Every option

projectstringrequired

Your project's public key, pk_live_<region>_… or pk_test_<region>_…. The region in the key decides where events go. A missing key, or one that isn't a public key, turns tracking off.

Script tag: data-project.

apistringdefault https://<region>.e.vk.viabio.me/v1/events

Send events to this address instead of your region's, for a proxy or a local API. A full address, or a path on your own site (/va/e). With the script tag, a path is read from the script's own address.

Script tag: data-api.

titlebooleandefault false

Send the page title with each page view. Off by default, because titles can hold personal data.

Script tag: data-title.

hashbooleandefault false

Count hash routes (/#/about) as page views, and keep the fragment's path in page URLs. Off by default: the fragment is dropped.

Script tag: data-hash.

paramsstring[] | stringdefault none

Extra query parameters to keep in page URLs, as a list or comma-separated text: ["plan", "coupon"] or "plan,coupon". They are added to the parameters kept by default (below).

Script tag: data-params.

outboundbooleandefault true

Send an Outbound link event, with the link's url, when someone clicks a link to another site.

Script tag: data-outbound, turned off with data-outbound="false".

downloadsbooleandefault true

Send a File download event, with the link's url, when someone clicks a link to a file with one of the download extensions.

Script tag: data-downloads, turned off with data-downloads="false".

downloadExtensionsstring[] | stringdefault see below

The file extensions that count as downloads, as a list or comma-separated text. It replaces the default list. An empty list keeps the default.

Script tag: data-download-ext.

notFoundbooleandefault false

This page is the not-found page: its first page view counts as a broken page. For single-page apps, see pageview().

Script tag: data-404.

debugbooleandefault false

Log every event and warning in the console, with a [viakite] prefix, and send nothing. It also shows events on localhost. See Debugging.

Script tag: data-debug.

localhostbooleandefault false

Track on localhost, 127.0.0.1, [::1], *.localhost and file://. Off by default, so your own development doesn't count.

Script tag: data-localhost.

autoPageviewsbooleandefault true

Send a page view on init() and on every path change in a single-page app. Turn it off to send page views yourself with pageview().

Script tag: none. The script tag always sends page views.

Options are read once, when init() runs. With a component, props that change after it mounts are ignored.

The same settings, three ways

src/main.ts
1init({
2 project: "pk_live_us_…",
3 title: true,
4 params: ["plan", "coupon"],
5 outbound: false,
6 downloadExtensions: ["pdf", "zip", "apk"],
7});
index.html
1<script defer src="https://us.api.vk.viabio.me/v1/a.js"
2 data-project="pk_live_us_…"
3 data-title
4 data-params="plan,coupon"
5 data-outbound="false"
6 data-download-ext="pdf,zip,apk"></script>
app/layout.tsx
1<Analytics
2 project="pk_live_us_…"
3 title
4 params={["plan", "coupon"]}
5 outbound={false}
6 downloadExtensions={["pdf", "zip", "apk"]}
7/>

In Vue, write a value that isn't text with a colon: :outbound="false", :params="['plan', 'coupon']".

Defaults

Download extensions: pdf, zip, rar, 7z, dmg, apk, exe, msi, doc, docx, xls, xlsx, pptx, csv, mp4, mov, mp3.

Query parameters kept in page URLs: utm_source, utm_medium, utm_campaign, utm_term, utm_content, ref, gclid, fbclid, msclkid, li_fat_id, q, query, search, s, plus the ones in params. Every other parameter is removed before sending, and the server applies the same list again. The project's tracking settings can also hold extra parameters (through the API only for now, with no screen yet), but the SDK removes every parameter that isn't on its own list first, so add them to params too.

Types

The package exports four types:

ts
1import type { Options, PageviewOptions, Props, PropValue } from "@viakite/sdk";
@viakite/sdk
1/** A property value: text (up to 255 characters), a number, true/false or null. */
2type PropValue = string | number | boolean | null | undefined;
3
4/**
5 * Properties of a custom event, or traits of an identified user: up to 20,
6 * flat (no objects or lists), keys of 1 to 40 letters, digits, `_`, `-` or `.`.
7 * `revenue` (a number) and `currency` (an ISO code such as `INR`) are reserved
8 * and don't count against the 20.
9 */
10type Props = Record<string, PropValue>;
11
12/** Options for `init`. Each one matches an attribute of the script tag. */
13interface Options {
14 project: string; // data-project
15 api?: string; // data-api
16 title?: boolean; // data-title
17 hash?: boolean; // data-hash
18 params?: string[] | string; // data-params
19 outbound?: boolean; // data-outbound, default true
20 downloads?: boolean; // data-downloads, default true
21 downloadExtensions?: string[] | string; // data-download-ext
22 notFound?: boolean; // data-404
23 debug?: boolean; // data-debug
24 localhost?: boolean; // data-localhost
25 autoPageviews?: boolean; // npm and components only, default true
26}
27
28/** Options for a page view sent by hand. */
29interface PageviewOptions {
30 notFound?: boolean;
31}

The React and Svelte entries also export AnalyticsProps, which is the same as Options.

Next steps