Changeset - 63ce0636ad4a
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 14 years ago 2012-02-10 21:33:11
ohnobinki@ohnopublishing.net
Add hacky native support for Google AdWords Conversion pixel image tracker.
3 files changed with 72 insertions and 1 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -34,24 +34,25 @@ define('SP_PACKAGE_STRING', SP_PACKAGE_N
 
 * similar effect to dirname('a/b/c') . DIRECTORY_SEPARATOR . '..'.
 
 */
 
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'libs');
 

	
 
/**
 
 * 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();
 
$ga_conversions = array();
 
$feedback_emails = array('ez@ethanzonca.com, ngelderloos7@gmail.com, ohnobinki@ohnopublishing.net');
 
$use_captcha = FALSE;
 
$admin_enable_purge = FALSE;
 
$qtips_always = FALSE;
 
$input_warning_banner = FALSE;
 
$feedback_disk_log = FALSE;
 

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

	
 
@@ -71,24 +72,25 @@ class page
 
  private $base_title = 'SlatePermutate - Find the schedule that works for you!';
 
  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 $pageGenTime = 0;
 

	
 
  private $xhtml = FALSE;
 

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

	
 
  private $trackingcode = ''; // Tracking code
 
  private $ga_conversions_code = ''; // Conversion tracking code
 
  private $pagetitle = ''; // Title of page
 
  private $scripts = array(); // Scripts to include on page
 
  private $meta;
 

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

	
 
  private $semester;
 

	
 
  /*
 
   * Whether or not the user should be presented with the option to
 
   * change the school profile or semester.
 
@@ -235,24 +237,80 @@ class page
 
   *   Whether or not to enable this code while adding it.
 
   */
 
  public function headcode_add($key, $code, $enable = FALSE)
 
  {
 
    $this->headCode[$key] = $code;
 
    if ($enable) {
 
      $this->scripts[] = $key;
 
    }
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Declare that this page is a conversion point.
 
   *
 
   * Making a page a conversion point informs any ad services or
 
   * whatnot that the user made it this far in slate_permutate. If the
 
   * user was referred to slate_permutate via an advertisement, this
 
   * can be used to see whether a click actually resulted in the user
 
   * actually _using_ slate_permutate instead of just navigating away
 
   * upon reading the first page.
 
   */
 
  public function conversion()
 
  {
 
    global $ga_conversions;
 

	
 
    if (!empty($ga_conversions))
 
      {
 
	if (!empty($this->ga_conversions_code))
 
	  /* Function already called once. */
 
	  return;
 

	
 
	$conversion_base_href = 'http' . ($_SERVER['SERVER_PORT'] == 80 ? '' : 's') . '://www.googleadservices/pagead/conversion/';
 
	$conversion_hrefs = array();
 
	$conversion_referrer = empty($_SERVER['HTTP_REFERER']) ? '' : '&ref=' . rawurlencode(substr($_SERVER['HTTP_REFERER'], 0, 255));
 
	$js_Date_getTime = (1000 * time()) . sprintf("%03d", rand(0, 999));
 

	
 
	$i = 1;
 
	foreach ($ga_conversions as $conversion_id => $conversion_label)
 
	  /*
 
	   * For random, supplement time() with three numerals to look
 
	   * like milliseconds like JavaScript's Date.getTime()
 
	   * function. For some reason, `random' and `fst' (first
 
	   * conversion time?) are both set to the current time. I'm
 
	   * guessing that random is supposed to be a cachebreaker.
 
	   *
 
	   * `cv' is the `current version' of the Google conversion.js
 
	   * which is 7. This could be scraped from the .js by looking
 
	   * for `google_conversion_js_version="7"'.
 
	   *
 
	   * `fmt=3' must mean that we don't want the user-notification
 
	   * to appear, but we already don't show that.  `value=0'
 
	   * seems to have no meaning at all, maybe it is supposed to
 
	   * be the `priority' of this conversion point.
 
	   *
 
	   * Google's `hl' and `gl' language values should probably be
 
	   * appended.
 
	   */
 
	  $this->ga_conversions_code .= '<img style="width: 1px; height: 1px; border: none;" src="'
 
	  . htmlentities($conversion_base_href . $conversion_id . '/?random=' . $js_Date_getTime . '&cv=7&fst=' . $js_Date_getTime
 
			 . '&num=' . $i++ . '&fmt=3&value=0&label=' . $conversion_label . '&bg=ffffff'
 
			 . '&guid=ON&disvt=&is_call=' . $conversion_referrer,
 
			 ENT_QUOTES)
 
	  . '" ' . ($this->xhtml ? '/' : '') . '>';
 
      }
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Set a meta element value.
 
   * \param $name
 
   *   The name of the meta attribute.
 
   * \param $value
 
   *   The value.
 
   */
 
  public function meta($name, $value = '')
 
  {
 
    $this->meta[$name] = $value;
 
  }
 

	
 
  /**
 
@@ -374,24 +432,25 @@ class page
 
   * \brief
 
   *   Write out the foot of the page and closing divs
 
   */
 
  public function foot(){
 
    echo '      </div> <!-- id="content" -->'. PHP_EOL;
 
    echo '      <div id="footer">'. PHP_EOL .
 
  	 '        <div id="leftfoot">'. PHP_EOL .
 
	 '          <a href="feedback.php">Contact Us</a>'. PHP_EOL .
 
         '        </div>'. PHP_EOL .
 
         '        <div id="rightfoot">'. PHP_EOL .
 
         '          <h5>&copy; 2011 <a href="http://protofusion.org/~nathang/">Nathan Gelderloos</a><br /><a href="http://ethanzonca.com">Ethan Zonca</a><br /><a href="http://ohnopub.net">Nathan Phillip Brink</a><br /></h5>'. PHP_EOL .
 
	 '        </div>'. PHP_EOL .
 
      $this->ga_conversions_code . PHP_EOL .
 
         '      </div> <!-- id="footer" -->'. PHP_EOL .
 
         '    </div> <!-- id="page" -->'. PHP_EOL;
 
    echo $this->trackingcode;
 
    echo '  </body>'. PHP_EOL .
 
         '</html>' . PHP_EOL;
 
    $this->pageGenTime = round(microtime() - $this->pageGenTime,4);
 
    echo '<!-- Page generated in ' . $this->pageGenTime . ' seconds -->' . PHP_EOL;
 

	
 
  }
 

	
 
  /**
 
   * \brief
inc/class.schedule.php
Show inline comments
 
@@ -444,24 +444,25 @@ class Schedule
 
    $last_permutation = min($this->nPermutations, $first_permutation + SP_PERMUTATIONS_PER_PAGE);
 

	
 
    $footcloser = '';
 

	
 
    $headcode = array('jQuery', 'jQueryUI', 'uiTabsKeyboard', 'displayTables', 'outputStyle', 'jQuery.cuteTime', 'qTip2');
 
    if(!empty($_REQUEST['print']))
 
      array_push($headcode, 'outputPrintStyle');
 
    else
 
      array_push($headcode, 'jAddress');
 

	
 
    $outputPage = page::page_create(htmlentities($this->getName()), $headcode,
 
				    array('school' => $this->school_get(), 'semester' => $this->semester_get()));
 
    $outputPage->conversion();
 
    if (!empty($this->created))
 
      $outputPage->meta('dcterms.created', gmdate(DATE_W3C, $this->created));
 

	
 
      if ($schedule_store !== NULL
 
	  && $this->parent_get() !== NULL
 
	  && ($parent_schedule = schedule_store_retrieve($schedule_store, $this->parent_get())) !== NULL)
 
        {
 
          $parent_uri = $parent_schedule->my_url();
 
          $outputPage->meta('dcterms.relation', $parent_uri);
 
          $outputPage->meta('dcterms.replaces', $parent_uri);
 
        }
 

	
inc/config.inc.example
Show inline comments
 
<?php
 
<?php /* -*- mode: php; -*- */
 
/*
 
 * Copyright 2010 Nathan Phillip Brink <ohnobinki@ohnopublishing.net>
 
 *
 
 * 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
 
@@ -54,24 +54,35 @@
 
/**
 
 * \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-X'); */
 

	
 
/**
 
 * \brief
 
 *   An array of Google AdWords conversion ID and label value pairs.
 
 *
 
 * Set this so that the key of the array is the google_conversion_id
 
 * and the value is the google_conversion_label. The conversion code
 
 * is placed on the process.php page (the page that users visit when
 
 * viewing their schedules).
 
 */
 
/* $ga_conversions = array('ddddddddd' => 'XXXXXXXXXXXX-XXXXXX', 'ddddddddd' => 'XXXXXXXXXXXX-XXXXXX'); */
 

	
 
/**
 
 * \brief
 
 *   List of email addresses to send feedback form submissions to.
 
 *
 
 * Set this to a PHP array of email addresses to which feedback
 
 * submissions should be mailed.
 
 */ 
 
/* $feedback_emails = array('ethanzonca@gmail.com, ngelderloos7@gmail.com, ohnobinki@ohnopublishing.net'); */
 
/* $feedback_emails = array('user@example.org'); */
 

	
 
/**
 
 * \brief
 
 *   Whether or not to use SecureImage phpcaptcha.
 
 *
0 comments (0 inline, 0 general)