Skip to main content

How to opt visitors out of Web Visitors tracking (optOut / optIn)

Learn how to use optOut() and optIn() to fully stop or resume Web Visitors tracking for an individual visitor, and how these differ from rejectCookie().

Written by Ruthie Keith

The Web Visitors tracker gives you two methods, optOut() and optIn(), that let you fully stop tracking an individual visitor without removing the script from your site. Use them to honour a visitor's do-not-track choice, a "reject all" click, or a standalone opt-out link.

If you're looking for how to make the tracker work alongside a cookie banner or Consent Management Platform, that's a different setup. See Using Web Visitors tracker with consent to comply with GDPR instead.


What optOut() does

Calling window.ldfdr.optOut():

  1. Sets a first-party cookie, ldfdr_opt_out=1, on your domain.

  2. Clears the visitor's existing _lfa client-ID cookie and the matching localStorage entry.

  3. Stops the tracker sending anything further. Pageviews, identify() calls, and every plugin event become a no-op while the opt-out cookie is present.

Calling window.ldfdr.optIn() clears the ldfdr_opt_out cookie. Tracking resumes on the visitor's next event.


How this differs from rejectCookie()

These are two different levers and it's easy to reach for the wrong one.

rejectCookie()

optOut()

Still sends events?

Yes, with an anonymous client ID

No, sends nothing

Requires Consent Mode?

Yes, only available when consentManagementEnabled is on

No, works either way

Company still identified?

Yes

No

Use it for

Visitors who declined cookies but can still be counted anonymously

Visitors who asked not to be tracked at all

If your goal is GDPR-compliant tracking with a cookie banner, rejectCookie() and Consent Mode are usually what you want, because they keep identifying companies. Use optOut() when a visitor has asked for a hard stop.


How to use it

Always check that the tracker has loaded before calling the method. The script loads asynchronously, so a bare call can run before window.ldfdr exists.

<script>

if (window.ldfdr && window.ldfdr.optOut) {

window.ldfdr.optOut();

}

</script>

And to opt the visitor back in:

<script>

if (window.ldfdr && window.ldfdr.optIn) {

window.ldfdr.optIn();

}

</script>


How it behaves

  • Opt-out wins over opt-in. If a page calls both acceptCookie() and optOut(), the opted-out state takes precedence.

  • Works regardless of your settings. It doesn't matter whether Consent Mode or cookies are enabled in your tracker settings.

  • Applies to every tracker on the page. If you have more than one Web Visitors tracker installed, one optOut() call covers all of them.

  • Opting back in creates a new visitor. Because the _lfa client ID was cleared on opt-out, a visitor who opts back in is seen as a new visitor, not a returning one.

  • Future traffic only. Opting out stops new data being collected. It does not remove visits already recorded.


How to check it worked

Open your site in a browser, trigger your opt-out, then open developer tools:

  1. Application → Cookies → your domain. You should see ldfdr_opt_out with a value of 1, and the _lfa cookie should be gone.

  2. Application → Local Storage. The _lfa entry should be gone too.

  3. Network tab. Reload the page and filter for requests to the tracker. You should see none.

To confirm optIn() works, call it, reload, and check that ldfdr_opt_out is gone and tracker requests resume.


Things to know

The opt-out is per browser and per device

Because the choice is stored in a cookie on the visitor's browser, it applies to that browser on that device only. A visitor who opts out on their laptop and then visits from their phone will be tracked again. If they clear their cookies, the opt-out goes with them.

What about data you've already collected?

Opting a visitor out only affects future traffic. Visits already recorded stay in your account.


Questions, comments, feedback? Please let us know by contacting our support team via the chat or by sending us an email at support@leadfeeder.com.

Did this answer your question?