Disabling Google FLoC with a Symfony event subscriber
Published on 2021-05-08 • Modified on 2021-05-08
In this snippet, we see how to disable Google FLoC with a Symfony event subscriber. In a previous snippet, we modified an Apache configuration to deactivate Google Floc globally. In this one, we see how to do it on the fly in a Symfony project with an event subscriber that adds the needed header. Fabpot originally proposed this snippet as a gist (check the "more on the web" button).
<?php
declare(strict_types=1);
namespace App\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class PermissionsPolicySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ResponseEvent::class => 'addPermissionsPolicyHeader',
];
}
public function addPermissionsPolicyHeader(ResponseEvent $event): void
{
$event->getResponse()->headers->set('permissions-policy', 'interest-cohort=()');
}
}
More on Stackoverflow Read the doc More on the web Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉
