# HG changeset patch # User Nathan Phillip Brink # Date 2012-02-10 21:33:11 # Node ID 63ce0636ad4a2e7d9495badef15d9826ccc1055c # Parent 5608907ef402d8382b2de299eb5f50b5ec2c0cdf Add hacky native support for Google AdWords Conversion pixel image tracker. diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -43,6 +43,7 @@ set_include_path(get_include_path() . PA /* 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; @@ -80,6 +81,7 @@ class page 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; @@ -244,6 +246,62 @@ class page /** * \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 .= 'xhtml ? '/' : '') . '>'; + } + } + + /** + * \brief * Set a meta element value. * \param $name * The name of the meta attribute. @@ -383,6 +441,7 @@ class page '
'. PHP_EOL . '
© 2011 Nathan Gelderloos
Ethan Zonca
Nathan Phillip Brink
'. PHP_EOL . '
'. PHP_EOL . + $this->ga_conversions_code . PHP_EOL . ' '. PHP_EOL . ' '. PHP_EOL; echo $this->trackingcode; diff --git a/inc/class.schedule.php b/inc/class.schedule.php --- a/inc/class.schedule.php +++ b/inc/class.schedule.php @@ -453,6 +453,7 @@ class Schedule $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)); diff --git a/inc/config.inc.example b/inc/config.inc.example --- a/inc/config.inc.example +++ b/inc/config.inc.example @@ -1,4 +1,4 @@ - * @@ -63,6 +63,17 @@ /** * \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