/** * Build out tracking scripts for head, body or specific trackers * @return string */ public function __call($method, $options) { // Build block sections if ($method === 'head' or $method === 'body') { $position = ($options[0] == 'prepend' or $options[0] == 'append') ? $options[0] : false; if ($position) { if (!empty($this->_sections["{$position}_{$method}"]) && ($section = $this->_sections["{$position}_{$method}"])) { foreach ($section as $tracker) { echo "\n{$this->_track($tracker['tracker'], $tracker['view'])}\n"; $this->_trackers[$tracker['tracker']->name()][] = "{$position}_{$method}"; } } } return; } // Build specific tracker $tracker = Trackers::get($method); $views = $tracker->views(); // Get view if (isset($options[0])) { $view = $views[$options[0]]; } else { // Use first view $keys = array_keys($views); $view = $views[$keys[0]]; } if (!empty($tracker)) { return $this->_track($tracker, $view); } }
function test_getFromSession() { Session::write(Trackers::$name, array(array('_trackPageview'), array('_setDomainName', 'example.org')), array('name' => 'default')); Trackers::add('test', array('account' => 'test', 'adapter' => 'GoogleAnalytics', 'commands' => array(array('_setDomainName', 'example.org')))); $expected = array(array('_setAccount', 'test'), array('_trackPageview'), array('_setDomainName', 'example.org')); $tracking = Trackers::get('test'); $this->assertEqual($expected, $tracking->commands()); }
function setup() { // Route $this->_routes = Router::get(); Router::reset(); Router::connect('/{:controller}/{:action}/{:id}.{:type}'); Router::connect('/{:controller}/{:action}.{:type}'); // Info $this->account = sprintf('UA-%05d-X', rand(1, 99999)); // Tracking Trackers::add('test', array('account' => $this->account, 'adapter' => 'GoogleAnalytics')); // Context $this->context = new MockHtmlRenderer(array('request' => new Request(array('base' => '', 'env' => array('HTTP_HOST' => 'foo.local'))), 'response' => new Response())); // Analytics $this->analytics = new Analytics(array('context' => &$this->context)); }