/** * Returns profile id for website * * @return string|FALSE */ public function getProfileId() { $profileId = FALSE; $accountId = FALSE; $gaAccountName = Fox::getPreference('admin/analytics/ga_account_name'); $gaEmail = Fox::getPreference('admin/analytics/ga_email'); $gaPassword = Fox::getPreference('admin/analytics/ga_password'); $service = Zend_Gdata_Analytics::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($gaEmail, $gaPassword, $service); $this->_analytics = new Zend_Gdata_Analytics($client); $accounts = $this->_analytics->getAccountFeed(); foreach ($accounts as $account) { if ($account->accountName == $gaAccountName) { $accountId = $account->accountId; } } if (!$accountId) { throw new Exception('Google Ananlytics Account with name "' . $gaAccountName . '" does not exist.'); } $profileResult = $this->_analytics->getDataFeed($this->_analytics->newAccountQuery()->profiles('~all', $accountId)); foreach ($profileResult as $dataBit) { foreach ($dataBit->getExtensionElements() as $element) { $attributes = $element->getExtensionAttributes(); if ($attributes['name']['value'] == 'ga:profileId') { $profileId = $attributes['value']['value']; break; } } } if (!$profileId) { throw new Exception('Google Ananlytics Profile not found for "' . $gaAccountName . '".'); } return $profileId; }
public function getAnalyticsProfilesAction() { $credentials = $this->getAnalyticsCredentials(); if ($credentials) { $username = $credentials["username"]; $password = $credentials["password"]; } if ($this->_getParam("username") && $this->_getParam("password")) { $username = $this->_getParam("username"); $password = $this->_getParam("password"); } try { $client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, Zend_Gdata_Analytics::AUTH_SERVICE_NAME, Pimcore_Tool::getHttpClient("Zend_Gdata_HttpClient")); $service = new Zend_Gdata_Analytics($client); $result = $service->getAccountFeed(); $data = array("data" => array()); foreach ($result as $entry) { $data["data"][] = array("id" => (string) $entry->profileId, "name" => (string) $entry->accountName . " | " . $entry->title, "trackid" => (string) $entry->webPropertyId, "accountid" => (string) $entry->accountId); } $this->_helper->json($data); } catch (Exception $e) { $this->_helper->json(false); } }