src/Sulu/Bundle/WebsiteBundle/EventListener/AppendAnalyticsListener.php
public function onResponse(FilterResponseEvent $event)
    {
        if ($this->preview
            || 0 !== strpos($event->getResponse()->headers->get('Content-Type'), 'text/html')
            || null === $this->requestAnalyzer->getPortalInformation()
        ) {
            return;
        }

        $portalUrl = $this->requestAnalyzer->getAttribute('urlExpression');

        $analyticsArray = $this->analyticsRepository->findByUrl(
            $portalUrl,
            $this->requestAnalyzer->getPortalInformation()->getWebspaceKey(),
            $this->environment
        );

        $analyticsContent = [];
        foreach ($analyticsArray as $analytics) {
            $analyticsContent = $this->generateAnalyticsContent($analyticsContent, $analytics);
        }

        $response = $event->getResponse();
        $response->setContent($this->setAnalyticsContent($response->getContent(), $analyticsContent));
    }
public function onResponse(FilterResponseEvent $event)
    {
        if ($this->preview
            || 0 !== strpos($event->getResponse()->headers->get('Content-Type'), 'text/html')
            || null === $this->requestAnalyzer->getPortalInformation()
        ) {
            return;
        }

        $portalUrl = $this->requestAnalyzer->getAttribute('urlExpression');

        $analyticsArray = $this->analyticsRepository->findByUrl(
            $portalUrl,
            $this->requestAnalyzer->getPortalInformation()->getWebspaceKey(),
            $this->environment
        );

        $analyticsContent = [];
        foreach ($analyticsArray as $analytics) {
            $analyticsContent = $this->generateAnalyticsContent($analyticsContent, $analytics);
        }

        $response = $event->getResponse();
        $response->setContent($this->setAnalyticsContent($response->getContent(), $analyticsContent));
    }
public function onResponse ( FilterResponseEvent $ event ) { if ( $ this -> preview || 0 !== strpos ( $ event -> getResponse ( ) -> headers -> get ( 'Content-Type' ) , 'text/html' ) || null === $ this -> requestAnalyzer -> getPortalInformation ( ) ) { return ; } $ portalUrl = $ this -> requestAnalyzer -> getAttribute ( 'urlExpression' ) ; $ analyticsArray = $ this -> analyticsRepository -> findByUrl ( $ portalUrl , $ this -> requestAnalyzer -> getPortalInformation ( ) -> getWebspaceKey ( ) , $ this -> environment ) ; $ analyticsContent = [ ] ; foreach ( $ analyticsArray as $ analytics ) { $ analyticsContent = $ this -> generateAnalyticsContent ( $ analyticsContent , $ analytics ) ; } $ response = $ event -> getResponse ( ) ; $ response -> setContent ( $ this -> setAnalyticsContent ( $ response -> getContent ( ) , $ analyticsContent ) ) ; }
Appends analytics scripts into body.

@param FilterResponseEvent $event
Appends analytics scripts into body .