Esempio n. 1
0
 public function testSetPayload()
 {
     $event = new RenderEvent($this->renderizer, [], $this->item);
     $event->setPayload(['name' => 'Spress']);
     $this->assertTrue(is_array($event->getPayload()));
     $this->assertCount(1, $event->getPayload());
     $this->assertArrayHasKey('name', $event->getPayload());
 }
 public function onAfterRender(RenderEvent $event)
 {
     // Google Analytics Content.
     $ga_code = "\n      <!-- Google Analytics Tracker -->\n      <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', 'GA_ID', 'GA_SITE');\n        ga('send', 'pageview');\n      </script>\n      <!-- End of Google Analytics Tracker -->";
     $payload = $event->getPayload();
     // Validate if Google Analytics settigns are available.
     if (isset($payload['site']['google_analytics']['id']) && isset($payload['site']['google_analytics']['site'])) {
         // Get content
         $content = $event->getContent();
         // Set google analytics variables
         $ga_code = str_replace('GA_ID', $payload['site']['google_analytics']['id'], $ga_code);
         $ga_code = str_replace('GA_SITE', $payload['site']['google_analytics']['site'], $ga_code);
         // Append Google Analytics code to end of page
         $content = str_replace('</body>', $ga_code . "\n </body> ", $content);
         $event->setContent($content);
     }
 }