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
1function track(name: string, props?: Props): void;
Parameters
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.
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 ..
The amount of a sale. Reserved: it must be a number, and it doesn't count against the 20.
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
1import { track } from "@viakite/sdk";23track("Signup", { plan: "pro", source: "pricing" });
1viakite.track("Signup", { plan: "pro", source: "pricing" });
A sale:
1import { track } from "@viakite/sdk";23track("Purchase", { revenue: 499, currency: "INR", product: "Pro yearly" });
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 send | What happens |
|---|---|
| A name over 120 characters | Cut to 120 |
| A name that is empty or only spaces | Nothing is sent |
| Text over 255 characters | Cut to 255 |
| A key over 40 characters | Cut 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 more | Dropped |
revenue that isn't a number ("499") | Dropped |
currency that isn't three letters | Dropped |
A property set to undefined | Left 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 line | Means |
|---|---|
[viakite] no event name | The name was empty; nothing was sent. |
[viakite] name cut to 120 | The name was too long. |
[viakite] plan cut to 255 | The value of plan was too long. |
[viakite] plan/tier: dropped | The 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.