JavaScript SDK - 'discard' method
This method stops recording for good without sending what is still buffered, for example when the user withdraws consent. Unlike stop(), which flushes buffered data, discard() drops pending messages, canvas uploads and analytics batches (uploads and analytics requests in flight are aborted). It also clears the tracker’s own keys from the configured localStorage / sessionStorage (session token, tab id, device id, offline buffer, analytics identity); other app storage is left alone.
After calling it, tracker methods are no-ops (start() resolves { success: false }), tracker.analytics sends nothing and stores no ids, and a second tracker instance on the page is refused.
With crossdomain.enabled, the trackers in cross-origin iFrames discard too, the next time they poll the parent (within about a quarter of a second). The iFrame needs a tracker version that supports discard() as well.
Signature
Section titled Signaturediscard(): void
Return value
Section titled Return valueThis method does not return any value.
Example
Section titled ExampleconsentBanner.onWithdraw(() => {
tracker.discard()
})