/** * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as#123 * @param \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder $p * @return \UnitedPrototype\GoogleAnalytics\Internals\ParameterHolder */ protected function buildCookieParameters(ParameterHolder $p) { $domainHash = $this->generateDomainHash(); $p->__utma = $domainHash . '.'; $p->__utma .= $this->visitor->getUniqueId() . '.'; $p->__utma .= $this->visitor->getFirstVisitTime()->format('U') . '.'; $p->__utma .= $this->visitor->getPreviousVisitTime()->format('U') . '.'; $p->__utma .= $this->visitor->getCurrentVisitTime()->format('U') . '.'; $p->__utma .= $this->visitor->getVisitCount(); $p->__utmb = $domainHash . '.'; $p->__utmb .= $this->session->getTrackCount() . '.'; // FIXME: What does "token" mean? I only encountered a value of 10 in my tests. $p->__utmb .= 10 . '.'; $p->__utmb .= $this->session->getStartTime()->format('U'); $p->__utmc = $domainHash; $cookies = array(); $cookies[] = '__utma=' . $p->__utma . ';'; if ($p->__utmz) { $cookies[] = '__utmz=' . $p->__utmz . ';'; } if ($p->__utmv) { $cookies[] = '__utmv=' . $p->__utmv . ';'; } $p->utmcc = implode('+', $cookies); return $p; }
/** * Updates the "previousVisitTime", "currentVisitTime" and "visitCount" * fields based on the given session object. * * @param Session $session */ public function addSession(Session $session) { $startTime = $session->getStartTime(); if ($startTime != $this->currentVisitTime) { $this->previousVisitTime = $this->currentVisitTime; $this->currentVisitTime = $startTime; ++$this->visitCount; } }
/** * Get a GA Session, if one doesn't exist in on the object or in the session, then build a new one from the utmb cookie * @return GoogleAnalytics\Session The GA Session */ public function getGASession() { if (null == $this->gaSession) { $sessionRaw = SSSession::get('SSGA_Session'); $session = $sessionRaw ? unserialize(SSSession::get('SSGA_Session')) : false; if (!$session instanceof GoogleAnalytics\Session) { $session = new GoogleAnalytics\Session(); if (Cookie::get('__utmb')) { $session->fromUtmb(Cookie::get('__utmb')); } } $this->setGASession($session); } return $this->gaSession; }