SproutCMS

This is the code documentation for the SproutCMS project

source of /skin/default/partials/_google_analytics.php

  1. <?php
  2. use Sprout\Helpers\AdminAuth;
  3.  
  4.  
  5. $analytics_id = Kohana::config('sprout.google_analytics_id');
  6.  
  7. if (!IN_PRODUCTION) {
  8. // Test server - trace output
  9. echo "<script type=\"text/javascript\">function ga(){ console.log('Google Analytics', arguments); }</script>\n";
  10. return;
  11.  
  12. } else if (!$analytics_id or AdminAuth::isLoggedIn()) {
  13. // Don't log analytics for admin users or if no config
  14. return;
  15. }
  16. ?>
  17.  
  18. <script>
  19. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  20. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  21. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  22. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  23.  
  24. ga('create', '<?php echo $analytics_id; ?>', 'auto');
  25. ga('send', 'pageview');
  26. </script>
  27.