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
 
@@ -40,12 +40,13 @@ set_include_path(get_include_path() . PA
 
 * 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;
 
@@ -77,12 +78,13 @@ class page
 
  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;
 
@@ -241,12 +243,68 @@ class page
 
      $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.
 
   */
 
@@ -380,12 +438,13 @@ class page
 
  	 '        <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);
inc/class.schedule.php
Show inline comments
 
@@ -450,12 +450,13 @@ class Schedule
 
      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)
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
 
@@ -60,12 +60,23 @@
 
 */
 
/* $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'); */
0 comments (0 inline, 0 general)