You are here

class ResponseSubscriber in Analytics 8

Analytics ResponseSubscriber.

Hierarchy

  • class \Drupal\analytics\EventSubscriber\ResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ResponseSubscriber

1 string reference to 'ResponseSubscriber'
analytics.services.yml in ./analytics.services.yml
analytics.services.yml
1 service uses ResponseSubscriber
analytics.response_subscriber in ./analytics.services.yml
Drupal\analytics\EventSubscriber\ResponseSubscriber

File

src/EventSubscriber/ResponseSubscriber.php, line 13

Namespace

Drupal\analytics\EventSubscriber
View source
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=()');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResponseSubscriber::$config protected property The analytics module configuration.
ResponseSubscriber::getSubscribedEvents public static function
ResponseSubscriber::onKernelResponse public function Respond to the kernel response event.
ResponseSubscriber::__construct public function Constructs a new ResponseSubscriber.