public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); $headers = $response->headers; if (!$headers->has('Content-Length') && !$headers->has('Transfer-Encoding')) { $headers->set('Content-Length', strlen($response->getContent())); } }
public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); if ($response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $event->getRequest()->getRequestFormat()) { return; } $response->setContent($response->getContent() . "<script>\n (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n ga('create', 'UA-67517854-1', 'auto');\n ga('send', 'pageview');\n\n</script>"); }
public function onResponse(ResponseEvent $event) { $response = $event->getResponse(); if ($response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $event->getRequest()->getRequestFormat()) { return; } $response->setContent($response->getContent() . 'GA CODE'); }