Web analytics

Let visitors opt out

Give visitors an analytics toggle with optOut and optIn, and keep the tracker from starting in browsers that send Do Not Track.

The tracker does not start in automated browsers that set navigator.webdriver, and Logdash drops events from known bots and from datacenter and cloud networks. Everything else is up to you and your visitors.

Add an analytics toggle

If your site has privacy settings, add an analytics toggle that calls optOut and optIn:

window.logdash?.optOut();
window.logdash?.optIn();
MethodWhat it does
optOut()Stops tracking at once: it drops queued events and removes its timers, listeners and history hooks. It writes localStorage['logdash:opt-out'] = '1' so the choice survives reloads.
optIn()Removes that flag and starts tracking again with a fresh pageview. window.logdash exists while a visitor is opted out, so optIn() stays reachable.
stop()Still works as an alias of optOut().

Respect Do Not Track

The tracker counts browsers that send Do Not Track or Global Privacy Control like any other. To keep it from starting in them, add data-respect-dnt to the script tag:

index.html
<script
  defer
  src="/_ld/script.js"
  data-site="your-site-id"
  data-endpoint="/_ld/events"
  data-respect-dnt
></script>

Whether your site needs consent for analytics is your call. Web analytics and privacy describes the processing precisely, so you can decide and explain it to your visitors. If you need consent, load the script only after the visitor agrees.