Script tag
One line in your <head>, every attribute
The script tag is the SDK as one file, a.js, loaded from a <script> element. It works on any website, needs no build step, and is under 3 KB gzipped. You set it up with data-* attributes and call it from your code through window.viakite.
Add it to your pages
Paste it into the <head> of every page, or once in the layout or template your pages share:
1<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…"></script>
Your key is on the dashboard's Install page, with the snippet ready to copy. The key carries your region, so events go to https://<region>.e.vk.viabio.me/v1/events without more setup (https://us.e.vk.viabio.me/v1/events for a pk_live_us_… key).
Where a.js comes from
The API of your region serves the script at GET /v1/a.js (https://us.api.vk.viabio.me/v1/a.js for the United States region, the only one today). This is the address the dashboard's Install page gives you, so copy the snippet from there. Browsers cache the file for a day, so a new version reaches everyone within a day.
Use defer, so the script never holds up your page. It sends the page view as soon as it runs.
Attributes
A flag is on when the attribute is there (data-title) and off when it is missing or "false". Flags that are on by default are turned off with "false" (data-outbound="false").
Your project's public key: pk_live_<region>_… or pk_test_<region>_…. A missing key, or one that isn't a public key, turns tracking off (with a warning in debug mode).
Send events to another address, such as your own proxy or a local API. A path (/va/e) is read from the script's own address, so src="https://example.com/va/a.js" data-api="/va/e" sends to https://example.com/va/e. See Proxy.
Send the page title with each page view. Off by default, because titles can hold personal data.
Count hash routes (/#/about) as pages. Without it, the fragment is dropped from every URL.
Extra query parameters to keep in page URLs, comma-separated: data-params="plan,coupon". Every parameter not on the list is removed before sending.
Send an Outbound link event when someone clicks a link to another site.
Send a File download event when someone clicks a link to a file with one of the download extensions.
The file extensions that count as downloads, comma-separated. It replaces the default list: data-download-ext="pdf,zip,apk".
Put it on your not-found page. Its page view counts as a broken page.
Log every event and warning in the browser console, and send nothing. See Debugging.
Track on localhost, 127.0.0.1, [::1], *.localhost and file://. Without it, nothing is sent from those.
The same settings are options of init() and props of <Analytics />; Options maps each one.
Default download extensions
pdf, zip, rar, 7z, dmg, apk, exe, msi, doc, docx, xls, xlsx, pptx, csv, mp4, mov, mp3.
The match ignores case, so Report.PDF counts. Only http and https links are followed, for left and middle clicks; the event's url property is the link without its query and fragment.
Call it from your code
The script sets window.viakite with three functions:
1viakite.track("Signup", { plan: "pro", source: "pricing" });2viakite.track("Purchase", { revenue: 499, currency: "INR", product: "Pro yearly" });3viakite.identify("user_8231", { plan: "pro", company: "Acme" });4viakite.reset(); // on sign-out
They work like the npm functions of the same name: track(), identify(), reset(). The function form works too: viakite("track", "Signup", { plan: "pro" }) is the same as viakite.track("Signup", { plan: "pro" }). An unknown name is ignored.
pageview() is not on window.viakite: the script tag always sends page views itself. To send page views by hand, use the npm package.
Call it before it loads
With defer, the script runs after the page is parsed. To call it earlier, from an inline script, add this stub above the script tag:
1<script>2window.viakite = window.viakite || function () { (window.viakite.q = window.viakite.q || []).push(arguments) };3</script>4<script defer src="https://us.api.vk.viabio.me/v1/a.js" data-project="pk_live_us_…"></script>
Calls made before the script loads wait in the stub's queue. When it loads, the script starts, sends the page view, then runs the queued calls in order. Until then only the function form works:
1viakite("identify", "user_8231");2viakite("track", "Signup", { plan: "pro" });
After it loads, both forms work.
Events without code
A class on any element sends an event when it, or anything inside it, is clicked:
1<button class="btn viakite-event-name=Signup viakite-event-plan=pro">Sign up</button>
viakite-event-name=… names the event; every other viakite-event-<key>=<value> class becomes a property. Write a space as +: viakite-event-name=Sign+up. An element with properties but no name sends nothing. More in Custom events.
Content Security Policy
If your site sets a Content Security Policy, allow the script's host in script-src and the events host in connect-src:
1script-src 'self' https://us.api.vk.viabio.me;2connect-src 'self' https://us.e.vk.viabio.me;
us is the region in your key; https://us.api.vk.viabio.me serves a.js. With the stub, also allow the inline script (with a nonce or a hash), or move the stub into a file of your own. With data-api, allow that address in connect-src instead.