/** * */ public function dispatchLoopShutdown() { if (!Tool::isHtmlResponse($this->getResponse())) { return; } if ($this->enabled && ($code = AnalyticsHelper::getCode())) { // analytics $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 = stripos($body, "</head>"); if ($headEndPosition !== false) { $body = substr_replace($body, $code . "</head>", $headEndPosition, 7); } $this->getResponse()->setBody($body); } }