Skip to content
duxt

useDuxtAnalytics()

Report one reader interaction to the site's own callback, or to nobody.

Signature

const analytics = useDuxtAnalytics();

analytics.track({ name: 'feedback', helpful: true });

Returns

{ track }. track(event) stamps the documentation context onto the event and hands it to duxt.analytics.track, if the site configured one.

It returns nothing and never throws: a call site must not care whether reporting worked, or whether anybody is listening at all.

Notes

The event is one of a closed union — search, search-result, copy, api-request, feedback — and track adds the context: the documentation path without its locale prefix, query string or fragment, the locale, and the source and version where the site has more than one.

Client only. track returns immediately on the server, so a build and a prerender report nothing — a static render is not a reader.

There is no transport behind this. No queue, no buffer, no storage, no cookie and no network call: the site's own function is the only thing that leaves the page, which is what keeps the provider, the consent gate and the decision to transmit at all on the side that owns them. A callback that throws or rejects is swallowed.

Wiring one up, the full event contract and what is deliberately never sent: Send analytics events.

Was this page helpful?