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
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.
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.
Send the page title with each page view. Off by default, because titles can hold personal data.
Script tag: data-title.
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.
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.
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".
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".
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.
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.
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.
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.
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
1init({2project: "pk_live_us_…",3title: true,4params: ["plan", "coupon"],5outbound: false,6downloadExtensions: ["pdf", "zip", "apk"],7});
1<script defer src="https://us.api.vk.viabio.me/v1/a.js"2data-project="pk_live_us_…"3data-title4data-params="plan,coupon"5data-outbound="false"6data-download-ext="pdf,zip,apk"></script>
1<Analytics2project="pk_live_us_…"3title4params={["plan", "coupon"]}5outbound={false}6downloadExtensions={["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:
1import type { Options, PageviewOptions, Props, PropValue } from "@viakite/sdk";
1/** A property value: text (up to 255 characters), a number, true/false or null. */2type PropValue = string | number | boolean | null | undefined;34/**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 reserved8* and don't count against the 20.9*/10type Props = Record<string, PropValue>;1112/** Options for `init`. Each one matches an attribute of the script tag. */13interface Options {14project: string; // data-project15api?: string; // data-api16title?: boolean; // data-title17hash?: boolean; // data-hash18params?: string[] | string; // data-params19outbound?: boolean; // data-outbound, default true20downloads?: boolean; // data-downloads, default true21downloadExtensions?: string[] | string; // data-download-ext22notFound?: boolean; // data-40423debug?: boolean; // data-debug24localhost?: boolean; // data-localhost25autoPageviews?: boolean; // npm and components only, default true26}2728/** Options for a page view sent by hand. */29interface PageviewOptions {30notFound?: boolean;31}
The React and Svelte entries also export AnalyticsProps, which is the same as Options.