viakite
Dashboard

Guides/Events and goals/Custom events

Custom events

Send events with properties, with or without code

Page views come on their own. A custom event records something that matters to your business: a signup, a purchase, a click on a pricing plan. Send one from your code with track, or from your HTML with a class, and add properties to say more about it.

Send an event

Give the event a name and, if you like, properties:

checkout.ts
1import { track } from "@viakite/sdk";
2
3track("Signup", { plan: "pro", source: "pricing" });
checkout.js
1viakite.track("Signup", { plan: "pro", source: "pricing" });

With the npm package or a framework component, calls made before Viakite has started are kept and sent once it does. With the script tag, the script loads with defer; to call it earlier, add this stub above the script tag and use the function form until the script has loaded:

index.html
1<script>
2 window.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>
5<script>
6 viakite("track", "Signup", { plan: "pro" });
7</script>

Events are sent at once and show in Analytics → Events and in Realtime within seconds. track never throws and never blocks your page; a failed send is retried after 1, 5 and 15 seconds.

Properties

Properties are flat key and value pairs. A value is text, a number, true/false or null. Objects and lists are dropped, so flatten them:

checkout.ts
1// Not sent: address is an object
2track("Order placed", { address: { city: "Pune" } });
3
4// Sent
5track("Order placed", { address_city: "Pune", items: 3, gift: false });

Name events and properties the way you want to read them in reports. Keep the same name for the same thing: Signup and signup are two different events.

E-mail addresses, phone numbers and long tokens found in property values are replaced with [email], [phone] and [token] before anything is stored. See Privacy.

Limits

Limit
Event name1 to 120 characters
PropertiesUp to 20 per event
Property names1 to 40 characters: letters, digits, _, -, .
Property valuesText up to 255 characters, a number, true/false or null
revenue and currencyA number and a 3-letter ISO code; they don't count against the 20. See Revenue

Values over a limit are cut, never rejected; anything that can't be sent is dropped. The SDK and the server apply the same rules. With data-debug each cut or drop is a warning in the browser console, and the Last events list on the Install page shows the server's warnings next to each event.

Events without code

A class on any element sends an event when it is clicked. This works with the script tag and with every component, with no JavaScript of your own:

pricing.html
1<button class="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. The class can sit on the clicked element or on any of its parents. Left and middle clicks count.

Automatic events

Two events are sent for you, on by default:

EventWhenPropertyTurn off
Outbound linkA click on a link to another siteurl: the link, without its query and fragmentdata-outbound="false" or outbound={false}
File downloadA click on a link to a fileurl: the file's addressdata-downloads="false" or downloads={false}

A link counts as a download when its path ends in one of these extensions: pdf, zip, rar, 7z, dmg, apk, exe, msi, doc, docx, xls, xlsx, pptx, csv, mp4, mov, mp3. Replace the list with data-download-ext="pdf,zip,apk" (or the downloadExtensions option).

Broken pages

To mark your not-found page, add data-404 to its script tag (or notFound to its component, or call pageview({ notFound: true })). Its page view is then stored as a broken page. A custom event named 404 is marked the same way.

Broken pages show in Analytics → Broken pages, with the pages that linked to them.

No reports for these yet

Outbound link and File download show as event names on the Events page, but have no report of their own yet.

Next steps