viakite
Dashboard

SDKs/Web/track()

track()

Send a custom event

track() sends a custom event: a name, and up to 20 properties. Use it for what matters to your business, such as a signup, a purchase or a search. Add revenue and currency to record a sale.

Signature

ts
1function track(name: string, props?: Props): void;

Parameters

namestringrequired

The event's name, 1 to 120 characters. It is trimmed; a longer name is cut to 120. An empty name sends nothing. Names are case-sensitive, so pick one spelling (Signup) and keep it.

propsProps

Up to 20 flat properties. Each value is text (up to 255 characters), a number, true/false or null. Keys are 1 to 40 characters of letters, digits, _, - and ..

props.revenuenumber

The amount of a sale. Reserved: it must be a number, and it doesn't count against the 20.

props.currencystring

The sale's currency, a three-letter ISO code such as INR or USD. Reserved, sent in capitals, and doesn't count against the 20.

Examples

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

A sale:

src/checkout.ts
1import { track } from "@viakite/sdk";
2
3track("Purchase", { revenue: 499, currency: "INR", product: "Pro yearly" });
checkout.js
1viakite.track("Purchase", { revenue: 499, currency: "INR", product: "Pro yearly" });

Then turn the event into a goal to count conversions, or see it on the Events page. More on sales in Revenue.

Currencies without a rate are left out

Reports convert revenue to your project's currency at the European Central Bank's rate for the event's day. Revenue in a currency the bank has no rate for (such as AED) is left out of revenue. See Revenue.

What is cut and what is dropped

Values over a limit are cut, never rejected. Values that break a rule are dropped; the rest of the event is still sent.

What you sendWhat happens
A name over 120 charactersCut to 120
A name that is empty or only spacesNothing is sent
Text over 255 charactersCut to 255
A key over 40 charactersCut to 40
A key with other characters (plan name, plan/tier)The property is dropped
An object or a list ({ address: { city } })The property is dropped. Flatten it: address_city
A 21st property and moreDropped
revenue that isn't a number ("499")Dropped
currency that isn't three lettersDropped
A property set to undefinedLeft out, with no warning

Lengths are counted in characters, so an emoji or a letter in Hindi counts as one. The server applies the same limits again.

Timing

The event is sent at once, with the current page's URL and, after identify(), your user id. A failed send is retried after 1, 5 and 15 seconds. Called before init(), the event waits and is sent once init() runs. With the script tag, use the stub to call it before the script loads.

Warnings in debug mode

track() never throws. With debug on, each cut or drop is a [viakite] line in the console, and nothing is sent:

Console lineMeans
[viakite] no event nameThe name was empty; nothing was sent.
[viakite] name cut to 120The name was too long.
[viakite] plan cut to 255The value of plan was too long.
[viakite] plan/tier: droppedThe property broke a rule and was left out.
[viakite] send {…}The event as it would be sent.

Events without code

The same events can come from a class on any element, with no JavaScript: class="viakite-event-name=Signup viakite-event-plan=pro". See Custom events.

Next steps