src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php
public function addTargetGroupHitScript(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();

        if ($this->preview
            || 0 !== strpos($response->headers->get('Content-Type'), 'text/html')
            || Request::METHOD_GET !== $request->getMethod()
        ) {
            return;
        }

        $script = $this->twig->render('SuluAudienceTargetingBundle:Template:hit-script.html.twig', [
            'url' => $this->targetGroupHitUrl,
            'urlHeader' => $this->urlHeader,
            'refererHeader' => $this->referrerHeader,
            'uuidHeader' => $this->uuidHeader,
            'uuid' => $request->attributes->has('structure') ? $request->attributes->get('structure')->getUuid() : null,
        ]);

        $response->setContent(str_replace(
            '</body>',
            $script . '</body>',
            $response->getContent()
        ));
    }
public function addTargetGroupHitScript(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();

        if ($this->preview
            || 0 !== strpos($response->headers->get('Content-Type'), 'text/html')
            || Request::METHOD_GET !== $request->getMethod()
        ) {
            return;
        }

        $script = $this->twig->render('SuluAudienceTargetingBundle:Template:hit-script.html.twig', [
            'url' => $this->targetGroupHitUrl,
            'urlHeader' => $this->urlHeader,
            'refererHeader' => $this->referrerHeader,
            'uuidHeader' => $this->uuidHeader,
            'uuid' => $request->attributes->has('structure') ? $request->attributes->get('structure')->getUuid() : null,
        ]);

        $response->setContent(str_replace(
            '</body>',
            $script . '</body>',
            $response->getContent()
        ));
    }
public function addTargetGroupHitScript ( FilterResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; if ( $ this -> preview || 0 !== strpos ( $ response -> headers -> get ( 'Content-Type' ) , 'text/html' ) || Request :: METHOD_GET !== $ request -> getMethod ( ) ) { return ; } $ script = $ this -> twig -> render ( 'SuluAudienceTargetingBundle:Template:hit-script.html.twig' , [ 'url' => $ this -> targetGroupHitUrl , 'urlHeader' => $ this -> urlHeader , 'refererHeader' => $ this -> referrerHeader , 'uuidHeader' => $ this -> uuidHeader , 'uuid' => $ request -> attributes -> has ( 'structure' ) ? $ request -> attributes -> get ( 'structure' ) -> getUuid ( ) : null , ] ) ; $ response -> setContent ( str_replace ( '</body>' , $ script . '</body>' , $ response -> getContent ( ) ) ) ; }
Adds a script for triggering an ajax request, which updates the target group on every hit.

@param FilterResponseEvent $event
Adds a script for triggering an ajax request which updates the target group on every hit .