/** * Get a GA visitor, if one doesn't exist build one and set it from the utma cookie * @return GoogleAnalytics\Visitor The visitor */ public function getGAVisitor() { if (null == $this->gaVisitor) { $visitor = new GoogleAnalytics\Visitor(); if (SSCookie::get('__utma')) { $visitor->fromUtma(SSCookie::get('__utma')); } $visitor->fromServerVar($_SERVER); $visitor->addSession($this->getGASession()); $this->setGAVisitor($visitor); } return $this->gaVisitor; }
function leechgate_track_ga($config) { try { // prepare GA structures $tracker = new GoogleAnalytics\Tracker($config['gaid'], $config['normalized_host']); $visitor = new GoogleAnalytics\Visitor(); $visitor->fromServerVar($_SERVER); if ($config['utma_cookie']) { $visitor->fromUtma($config['utma_cookie']); } $session = new GoogleAnalytics\Session(); $event = new GoogleAnalytics\Event($config['normalized_host'], $config['product'], $config['product_version']); $event->setNoninteraction(true); // track it! $tracker->trackEvent($event, $session, $visitor); } catch (Exception $e) { $fe = fopen('php://stderr', 'w'); fwrite($fe, "Caught exception in leechgate_track_ga: " . $e->getMessage() . "\n"); fclose($fe); } }