tmpFolder)) $this->tmpFolder = 'analytics'.DS; if (!is_dir(TMP.'cache'.DS.$this->tmpFolder)) mkdir(TMP.'cache'.DS.$this->tmpFolder); } /** * This allows you to login to a Google Analytics Account via https Post. * In return you get a path to a cookie file that's like your ConnectionId * when working with a MySql Database -> You'll need to remember it * * If the Login fails, this function will return an Error constant. See * GA_ERROR_... for more Information. * * @param string $email The E-Mail Adress to be used for Login * @param string $pass The Password to be used for Login * @param string $language The language to use for the login (check GA_LANGUAGE_...). Right now this does not seem to have any effect so! * @param mixed $loginExpires Unix Timestamp or strtotime() compatible format stating when the Login expires * @return string Returns a path to a cookie file */ function login($email, $pass, $language = GA_LANGUAGE_ENGLISH_US, $loginExpires = '+2 hours') { $url = 'https://www.google.com/accounts/ServiceLoginBoxAuth'; $vars= array('continue' => 'http://www.google.com/analytics/home/?et=reset&hl='.$language, 'service' => 'analytics', 'nui' => 'hidden', 'hl' => $language, 'GA3T' => 'ouVrvynQwUs', 'Email' => $email, 'PersistentCookie'=> 'yes', 'Passwd' => $pass); $cookiePath = TMP.'cache'.DS.$this->__createCachePath('.cookies.txt', $url, $vars); $cachePath = $this->__createCachePath('.login-data.txt', $url, $vars); $this->__lastCachedFile = $cachePath; $loginData = cache($cachePath, null, $loginExpires); if (empty($loginData)) { if (file_exists($cookiePath)) unlink($cookiePath); $loginData = cache($cachePath, utf8_encode($this->httpPost($url, $vars, null, $cookiePath)), $loginExpires); } $this->language = $language; // Check if no data has been returned (most likely a Connection Timeout) if (empty($loginData)) { $cookiePath = GA_ERROR_TIMEOUT; return $cookiePath; } // Check if Access has been denied $regex = '/Username and password do not match/iUs'; if (preg_match($regex, $loginData)) { $cookiePath = GA_ERROR_ACCESS_DENIED; return $cookiePath; } return $cookiePath; } /** * Creates an array listing all Profiles available for this acccount * * @param string $cookiePath The file path where the Cookies for this Session are stored (returned by the Login function) * @param mixed $cacheExpires Unix timestamp or strtotime() compatible format for the time this Result cache expires. Set to 0 for no cache * @return array */ function listProfiles($cookiePath, $cacheExpires = '+2 hours') { $url = 'https://www.google.com/analytics/home/'; $vars = array('et' => 'reset', 'hl' => $this->language); $cachePath = $this->__createCachePath('.profiles.txt', $url, $vars, $cookiePath); $this->__lastCachedFile = $cachePath; $profilesData = cache($cachePath, null, $cacheExpires); if (empty($profilesData)) $profilesData = cache($cachePath, utf8_encode($this->httpGet($url, $vars, null, $cookiePath)), $cacheExpires); if (empty($profilesData)) // No Data - Propably a Connection timeout return GA_ERROR_TIMEOUT; $regex = '/\