Usage
Using Umami tracking functions and directive.
Functions
umTrackView()
Track page views.
Route changes are tracked automatically if autoTrack
is enabled.
If you're tracking manually, call the function onMounted
;
Params
- url: the tracked path. Example:
/about
,/contact?by=phone#office
. Optional, defaults torouter.fullPath
. - referrer: the page referrer.
Optional, defaults to
document.referrer
or theref
in searchParams (eg: example.com/?ref=website.com).
umTrackEvent()
Track custom events.
Params
- name: the event name. Required.
- data: the event data should be a
{key: value}
object, wherekey
is a string andvalue
is a string, number, or boolean.
umIdentify()
Tracks a session with dynamic data.
umTrackRevenue()
Collect revenue data.
Params
- eventName: the event name.
Examples:
cart-checkout
,upgrade-checkout
. - revenue: amount to track.
Examples:
24.99
,5000
. - currency: currency code, ISO 4217 standard.
Wikipedia: List of ISO 4217 currency codes.
Extra Props
Under the hood, umTrackRevenue
is a convenient wrapper around umTrackEvent
.
If you need to add more data to your payload, you should consider extending umTrackEvent
.
Return Value
All tracking functions return Promise<{ok: boolean}>
.
The functions do not throw errors, use the ok
status to check whether
the request ran successfuly.
(During dev or if logErrors
is set, errors
are logged to the console.)
Sometimes API calls can be long-running, I don't recommend await
-ing them.
Directive
You can use umTrackEvent
as a directive, v-umami
.
Add useDirective: true
to your config.
v-umami
requires a string as the event name,
or an object containing a name
property.
Every other property will be passed on as event data.