Exemple #1
0
 public function dispatchLoopShutdown()
 {
     if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled && Pimcore_Google_Analytics::isConfigured()) {
         // analytics
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = strpos($body, "</head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, Pimcore_Google_Analytics::getCode() . "</head>", $headEndPosition, 7);
         }
         // website optimizer
         if ($this->document) {
             $top = Pimcore_Google_Analytics::getOptimizerTop($this->document);
             $bottom = Pimcore_Google_Analytics::getOptimizerBottom($this->document);
             $conversion = Pimcore_Google_Analytics::getOptimizerConversion($this->document);
             if ($top || $bottom || $conversion) {
                 $html = str_get_html($body);
                 if ($html) {
                     $body = $html->find("body", 0);
                     if ($top && $bottom) {
                         $body->innertext = $top . $body->innertext . $bottom;
                     } else {
                         if ($conversion) {
                             $body->innertext = $body->innertext . $conversion;
                         } else {
                             if ($bottom) {
                                 $body->innertext = $body->innertext . $bottom;
                             }
                         }
                     }
                     $body = $html->save();
                 }
             }
         }
         $this->getResponse()->setBody($body);
     }
 }