How to Enable Google Analytics Opt-Out for Site Users?
Enhanced Ecommerce Google Analytics for WooCommerce can add a GA4 opt-out mechanism to your store's tracking script. Once enabled, you can give visitors a link that lets them opt themselves out of Google Analytics 4 tracking, useful for privacy compliance or for site sections where you don't want any visitor activity recorded.
Enabling the toggle sets up the mechanism, it doesn't stop tracking for everyone by itself. A visitor is only opted out after they click the opt-out link (or you trigger it programmatically), which stores an opt-out cookie in their browser for 26 months.
In The Article
Benefits
Enabling GA4 opt-out can help:
- Give visitors a way to stop being tracked, without disabling GA4 tracking site-wide
- Support privacy compliance requirements that call for a visible opt-out option
- Let you trigger the opt-out yourself for specific pages or scenarios via the same JavaScript function
How It Works
When you turn on Google Analytics Opt Out, the plugin adds a small script to your tracking code that checks for an opt-out cookie tied to your GA4 Measurement ID. It also makes a JavaScript function, ga4Optout() , available on the page. Calling that function sets the opt-out cookie for 26 months and tells GA4 to stop collecting data for that browser.
Until a visitor clicks the opt-out link (or the function is called for them), tracking continues as normal, the toggle alone doesn't pause data collection for existing visitors.
How to Enable Opt-Out Tracking
Step 1: Turn on Google Analytics Opt Out
Go to Ecommerce Tracking → Ecommerce Tracking, open Core Tracking, and turn on Google Analytics Opt Out. Save your settings.

Step 2: Add the opt-out link to your site
To let visitors opt out themselves, add a link like this to your theme, for example in the header or footer:
<a href="javascript:ga4Optout()">Click here to opt-out of Google Analytics 4</a>
When a visitor clicks this link, their current and future sessions in that browser stop being tracked, until the opt-out cookie expires or is cleared.
Example Use Cases
Privacy-conscious stores: If your store operates in a region with strict privacy expectations, add the opt-out link to your footer so visitors always have the option to stop being tracked.
Temporary tracking pause: If you want a quick way to stop tracking your own testing sessions, enable the toggle and click the opt-out link yourself before browsing the site.
Compliance requirements: If your privacy policy promises an analytics opt-out, this gives you a working mechanism to point to rather than a manual workaround.
Conclusion
The Google Analytics Opt Out setting adds the infrastructure for visitors to stop GA4 tracking on their own, but it's the opt-out link (or a call to ga4Optout() ) that actually takes effect, not the toggle alone. Turn it on, add the link where you want it, and visitors control their own opt-out from there.
FAQs
1. Does turning on this toggle stop all tracking immediately?
No. It adds the opt-out mechanism to your tracking script. Tracking only stops for visitors who click the opt-out link or trigger ga4Optout() .
2. Where do I add the opt-out link?
Anywhere in your theme, commonly the header or footer, using <a href="javascript:ga4Optout()">Click here to opt-out of Google Analytics 4</a> .
3. How long does the opt-out last?
The opt-out cookie is set for 26 months. After it expires (or if the visitor clears their cookies), tracking resumes unless they opt out again.
4. Can I trigger the opt-out without a visible link?
Yes. Since ga4Optout() is a standard JavaScript function once the toggle is enabled, you can call it from your own script wherever it makes sense, for example, based on a cookie consent choice.