ResponseSubscriber.php in Analytics 8
Namespace
Drupal\analytics\EventSubscriberFile
src/EventSubscriber/ResponseSubscriber.phpView source
<?php
namespace Drupal\analytics\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Analytics ResponseSubscriber.
*/
class ResponseSubscriber implements EventSubscriberInterface {
/**
* The analytics module configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs a new ResponseSubscriber.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory.
*/
public function __construct(ConfigFactoryInterface $config) {
$this->config = $config
->get('analytics.settings');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::RESPONSE => [
'onKernelResponse',
],
];
}
/**
* Respond to the kernel response event.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event.
*/
public function onKernelResponse(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
// Adds "Permissions-Policy: interest-cohort=()" header to disable FLoC.
if ($this->config
->get('privacy.disable_floc')) {
$event
->getResponse()->headers
->set('Permissions-Policy', 'interest-cohort=()');
}
}
}
Classes
Name | Description |
---|---|
ResponseSubscriber | Analytics ResponseSubscriber. |