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.
Params
- data: session data should be a
{key: value}
object, wherekey
is a string andvalue
is a string, number, or boolean.
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.