Celebrating 20 years online :)
Web Dev + WordPress + Security

Opt Out of Google FLOC for Site Visitors (One Line of Code)

Floc of Sheep

Google has another new thing they are doing, called FLOC (Federated Learning of Cohorts). It’s used to — surprise — track user activity across websites. Opting out ideally is handled by the user, who can customize their browser settings to disable FLOC while surfing around the Web. Beyond configuring your browser to opt-out of FLOC, you can disable it on any website with a single line of code.


Opt-out your self

For end-users, the easiest way to opt-out of FLOC data collection is to either:

  • Don’t use Chrome browser
  • OR use a Chrome extension that disables FLOC

Either of those methods will prevent Google FLOC from tracking your activity. If you have a website and want to opt-out of FLOC for your users, you can do it easily with one line of code.

Opt-out your site

To opt any website or web page out of the FLOC monitoring program, add the following Permissions-Policy header to your page(s):

Permissions-Policy: interest-cohort=()

You can read all of the details about this HTTP response header in the official spec. And remember, this disables Google FLOC data collection on your site only. Once the visitor leaves your site, their activity may be tracked by FLOC elsewhere on the Web (unless it is disabled via some other method).

Below are several ways to add the Permissions-Policy header: via Apache/.htaccess, Nginx, or WordPress.

How to add via Apache/.htaccess

As explained in my tutorial on adding custom HTTP headers with .htaccess, we can use Apache’s Header set directive to add the Permissions-Policy header to your entire website:

Header set Permissions-Policy "interest-cohort=()"

Add that line to your site’s public/root .htaccess file, save changes, and done. Instant relief from Google’s latest data harvesting protocol for all of your site visitors.

How to add via Nginx

Nginx users can add the Permissions-Policy header via the add_header directive:

server {
	location / {
		add_header Permissions-Policy interest-cohort=();

Add that code to your site’s configuration file, save changes, and reload/restart the server for changes to take effect. Here is one possible way of doing it:

nginx -t && service nginx reload

That line checks the syntax of your configuration file and then reloads Nginx if no errors are found.

How to add via WordPress

If you don’t have access to server configuration files, or just want a super-easy way to opt-out your site from FLOC, you can install a free plugin. Currently there are five free plugins that can do it (that I was able to find when writing this post):

I would recommend the first plugin in the list, as it’s from a trusted WordPress contributor. The others may also be great, just make sure to read the documentation and fine print, etc.

Test if it’s working

After implementing new headers, Google Chrome will not collect data from users while they are at your website. So your site will not be included in FLOC’s profiling of your visitor’s browsing habits. Again, the header only opts out your site. Once the user leaves your site, they are susceptible to FLOC data collection (unless they have disabled/opted-out via some other method).

You can verify proper inclusion of the header by using a free browser extension, or you can just enter your site URL in a free online header checker tool, for example:

And the results will show you all of the headers that are returned for requests made to your site. Also there are plenty of other free header-checking services out there, take advantage.

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
Banhammer: Protect your WordPress site against threats.

9 responses to “Opt Out of Google FLOC for Site Visitors (One Line of Code)”

  1. The more tracking I see recently, the more it increases my drive to setup pihole quicker!

  2. The question is: Does the ban hurt search engine optimization if you don’t let Google track your website anymore? I think so. But it would be important for privacy, that’s true.

    • Jeff Starr 2021/05/01 8:50 am

      I’ve not read that anywhere, but it could be the case given how they’ve been doing things lately. If my site visits drop suddenly, then I’ll write another post letting people know about it.

  3. @DKeu FLOC has got nothig to do with seo or seo rankings! FLOC is to do with adverts only. You can learn more here: https://github.com/WICG/floc

    • Already clear, but think further. If Google tracks like this, they will also find out more about your website and the user behavior there. If you forbid them to do that, they can’t use that data for you or against you. But in case of doubt they bring an advantage.

  4. You can’t opt-out of FLOC as Google Chrome doesn’t work see my open bug tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1212363

    • Jeff Starr 2021/06/13 9:09 am

      Thanks for reporting, will keep a close eye on it. Hopefully Google has enough resources to get the issue resolved quickly.

  5. ux design services 2021/06/22 9:09 pm

    Google’s promise is that FLoC cohort IDs will be anonymous data points in a larger network and that each cohort’s data will be sent to advertisers without them knowing the identity of individual users.

Comments are closed for this post. Something to add? Let me know.
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
SAC Pro: Unlimited chats.
Crazy that we’re almost halfway thru 2024.
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.