public function GoogleAnalyticResponseSubscriber::addTag in Multidomain Google Analytics 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/GoogleAnalyticResponseSubscriber.php \Drupal\multidomain_google_analytics\EventSubscriber\GoogleAnalyticResponseSubscriber::addTag()
Add a tags in boby.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event:
Set response.
File
- src/EventSubscriber/ GoogleAnalyticResponseSubscriber.php, line 54 
Class
- GoogleAnalyticResponseSubscriber
- Class GoogleAnalyticResponseSubscriber.
Namespace
Drupal\multidomain_google_analytics\EventSubscriberCode
public function addTag(FilterResponseEvent $event) {
  if (!$event
    ->isMasterRequest()) {
    return;
  }
  $response = $event
    ->getResponse();
  $compact = '';
  if ($this->activeDomain) {
    $compact = $this->config
      ->get($this->activeDomain);
  }
  // Insert snippet after the opening body tag.
  if ($compact) {
    $response_text = preg_replace('@<body[^>]*>@', '$0' . $this
      ->getTag($compact), $response
      ->getContent(), 1);
    $response
      ->setContent($response_text);
  }
}