Changeset - d6ed1e1daa85
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 15 years ago 2010-10-10 17:01:18
ohnobinki@ohnopublishing.net
Generalized and configurable Google Analytics tracking.
2 files changed with 42 insertions and 14 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
<?php
 

	
 
/**
 
 * Not sure if there's a better place for this... it'd be a pita to
 
 * make a new include file like doconfig.inc but maybe that'll make
 
 * sense soon.
 
 */
 
/* defaults */
 
$clean_urls = FALSE;
 
$ga_trackers = array();
 

	
 
$config_inc = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.inc';
 
if (file_exists($config_inc))
 
  require_once($config_inc);
 

	
 
/* Class for general page generation */
 
class page
 
{
 
  private $base_title = 'SlatePermutate';
 
  private $doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"';
 
  private $htmlargs = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"';
 
  private $bodyargs = '';
 
  public $lastJobTable = '';
 
  private $pageGenTime = 0;
 

	
 
  /* whether or not to output valid XHTML */
 
  private $xhtml = FALSE;
 

	
 
  // Scripts and styles
 
  private $headCode = array();
 

	
 
  /* the inclusion of ga.js is augmented in __construct(). */
 
  private $trackingcode = '
 
			  <script type="text/javascript">
 
				var nathangPageTracker = _gat._getTracker("UA-17441156-1");
 
				nathangPageTracker._trackPageview();
 
				
 
				var ethanzPageTracker = _gat._getTracker("UA-2800455-1");
 
				ethanzPageTracker._trackPageview();
 
			</script>'; // Google analytics ga.js tracking code
 
  /*
 
   * Google analytics ga.js tracking code. Expanded in __construct().
 
   */
 
  private $trackingcode = '';
 

	
 
  private $pagetitle = ''; // Title of page
 
  private $scripts = array(); // Scripts to include on page
 

	
 
  /* the current school. See get_school(). */
 
  private $school;
 

	
 
  public function __construct($ntitle, $nscripts = array(), $immediate = TRUE)
 
  {
 
    global $ga_trackers;
 

	
 
    require_once('school.inc');
 

	
 
    // Scripts and styles available to include
 
    $this->headCode['jQuery'] = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript" />';
 
    $this->headCode['jQueryUI'] = '<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js" type="text/javascript" /><link rel="stylesheet" href="styles/jqueryui.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['jValidate'] = '<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>';
 
    $this->headCode['schedInput'] = '<script type="text/javascript" src="scripts/scheduleInput.js"></script>';
 
    $this->headCode['outputPrintStyle'] = '<link rel="stylesheet" href="styles/print.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['outputStyle'] = '<link rel="stylesheet" href="styles/output.css" type="text/css" media="screen" charset="utf-8" />'; 
 
    $this->headCode['gliderHeadcode'] = '<link rel="stylesheet" href="styles/glider.css" type="text/css" media="screen" charset="utf-8" />'; 
 
   $this->headCode['uiTabsKeyboard'] = '<script type="text/javascript" src="scripts/uiTabsKeyboard.js"></script>'; 
 
   $this->pagetitle = $ntitle;
 
   $this->scripts = $nscripts;
 

	
 
   /* compliant browsers which care, such as gecko, explicitly request xhtml: */
 
   if(!empty($_SERVER['HTTP_ACCEPT'])
 
      && strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') !== FALSE
 
      || !strlen($_SERVER['HTTP_ACCEPT']) /* then the browser doesn't care :-) */)
 
     {
 
       $this->xhtml = TRUE;
 
       header('Content-type: application/xhtml+xml');
 
     }
 

	
 
   $ga_www = 'http://www.';
 
   if ($_SERVER['SERVER_PORT'] != 80)
 
     $ga_www = 'https://ssl.';
 
   $this->trackingcode = '<script type="text/javascript" src="' . $ga_www . 'google-analytics.com/ga.js" />' . "\n"
 
     . $this->trackingcode;
 
   if (count($ga_trackers))
 
     {
 
       $ga_www = 'http://www.';
 
       if ($_SERVER['SERVER_PORT'] != 80)
 
	 $ga_www = 'https://ssl.';
 

	
 
       $this->trackingcode = '<script type="text/javascript" src="' . $ga_www . 'google-analytics.com/ga.js" />' . "\n"
 
	 . $this->trackingcode
 
	 . '  <script type="text/javascript">' . "\n"
 
	 . '  ' . ($this->xhtml ? '<![CDATA[' : '') . "\n"
 
	 . "     var mytrackers = new Array();";
 

	
 
       $i = 0;
 
       foreach ($ga_trackers as $ga_tracker)
 
	 {
 
	   $this->trackingcode .= "\n"
 
	     . '      mytrackers[' . $i . '] = _gat._getTracker(\'' . $ga_tracker . "');\n"
 
	     . '      mytrackers[' . $i . "]._trackPageview();\n";
 
	 }
 

	
 
       $this->trackingcode .= '  ' . ($this->xhtml ? ']]>'       : '') . "\n"
 
	 . "  </script>\n";
 
     }
 

	
 
   self::session_start();
 
    if($immediate
 
       && $ntitle != "NOHEAD")
 
      $this->head();
 

	
 
    /* everything that needs sessions started to work: */
 

	
 
    $this->school = school_load_guess();
 
 }
 

	
 
  /**
 
   * \brief
 
   *   Adds some headcode to this page.
 
   *
 
   * \param $key
 
   *   The key to register this headcode under.
 
   * \param $code
 
   *   The actual code, such as a <script/>.
 
   * \param $enable
 
   *   Whether or not to enable this code while adding it.
 
   */
 
  public function headcode_add($key, $code, $enable = FALSE)
 
  {
inc/config.inc.example
Show inline comments
 
@@ -5,24 +5,34 @@
 
 * This file is a part of slate_permutate.
 
 *
 
 * slate_permutate is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * slate_permutate is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with slate_permutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/**
 
 * \brief
 
 *   Use clean URLs for saved schedules. Default: FALSE.
 
 *
 
 * Before setting this to TRUE, make sure that you have read and
 
 * understood ../.htaccess.example and copied it to ../.htaccess .
 
 */
 
/* $clean_urls = FALSE; */
 

	
 
/**
 
 * \brief
 
 *   List of Google Analytics trackers to enable. Default: empty list.
 
 *
 
 * Set this to an array of Google Analytics tracker IDs if you want to
 
 * analyze access to your slate_permutate installation.
 
 */
 
/* $ga_trackers = array(); */
 
/* $ga_trackers = array('UA-XXXXXXXX-1'); */
0 comments (0 inline, 0 general)