tracker.destroy()
Tear down the tracker completely. Emits a final session:end event, flushes all queued events, removes all event proxies, and destroys the overlay.
typescript
tracker.destroy(): voidWhat It Does
- Emits a
session:endevent withsource: 'destroy' - Flushes the event queue (sends any remaining events)
- Stops the flush timer
- Removes all event proxies (
fetch,XHR,console,history) - Removes all DOM event listeners (
click,popstate,hashchange, etc.) - Destroys the overlay (removes the host element from the DOM)
- Marks the tracker as uninitialized — subsequent calls to
tracker.track()etc. are dropped silently
When to Use
typescript
import { tracker } from '@ndriadev/vite-plugin-monitor/client'
// Explicit cleanup (e.g. when the user opts out of tracking)
function onTrackingOptOut() {
tracker.destroy()
}
// Cleanup before a full-page logout redirect
authService.onLogout(() => {
tracker.destroy()
window.location.href = '/login'
})Re-initialization after destroy
After calling tracker.destroy(), the tracker cannot be re-initialized in the same page lifetime. If you need to start/stop tracking based on user preference without a page reload, consider using tracker.setUser(null) (to anonymize) rather than a full tracker.destroy().
Overlay Destroy
The overlay can also be removed independently using the "Remove Tracker Info" button in the overlay UI, which calls tracker.destroy() internally.
