/** * Get the selected table id * * @return string */ public static function getTableId() { return (string) BackendAnalyticsHelper::getGoogleAnalyticsInstance()->getTableId(); }
/** * Gets all the needed parameters to link a google analytics account to fork */ private function getAnalyticsParameters() { $remove = SpoonFilter::getGetValue('remove', array('session_token', 'table_id'), null); // something has to be removed before proceeding if (!empty($remove)) { // the session token has te be removed if ($remove == 'session_token') { // remove all parameters from the module settings BackendModel::setModuleSetting($this->getModule(), 'session_token', null); } // remove all profile parameters from the module settings BackendModel::setModuleSetting($this->getModule(), 'account_name', null); BackendModel::setModuleSetting($this->getModule(), 'table_id', null); BackendModel::setModuleSetting($this->getModule(), 'profile_title', null); // remove cache files BackendAnalyticsModel::removeCacheFiles(); // clear tables BackendAnalyticsModel::clearTables(); } // get session token, account name, the profile's table id, the profile's title $this->sessionToken = BackendModel::getModuleSetting($this->getModule(), 'session_token', null); $this->accountName = BackendModel::getModuleSetting($this->getModule(), 'account_name', null); $this->tableId = BackendModel::getModuleSetting($this->getModule(), 'table_id', null); $this->profileTitle = BackendModel::getModuleSetting($this->getModule(), 'profile_title', null); // no session token if (!isset($this->sessionToken)) { $token = SpoonFilter::getGetValue('token', null, null); // a one time token is given in the get parameters if (!empty($token) && $token !== 'true') { // get google analytics instance $ga = BackendAnalyticsHelper::getGoogleAnalyticsInstance(); // get a session token $this->sessionToken = $ga->getSessionToken($token); // store the session token in the settings BackendModel::setModuleSetting($this->getModule(), 'session_token', $this->sessionToken); } } // session id is present but there is no table_id if (isset($this->sessionToken) && !isset($this->tableId)) { // get google analytics instance $ga = BackendAnalyticsHelper::getGoogleAnalyticsInstance(); // get all possible profiles in this account $this->profiles = $ga->getAnalyticsAccountList($this->sessionToken); // not authorized if ($this->profiles == 'UNAUTHORIZED') { // remove invalid session token BackendModel::setModuleSetting($this->getModule(), 'session_token', null); // redirect to the settings page without parameters $this->redirect(BackendModel::createURLForAction('settings')); } elseif (is_array($this->profiles)) { $tableId = SpoonFilter::getGetValue('table_id', null, null); // a table id is given in the get parameters if (!empty($tableId)) { $profiles = array(); // set the table ids as keys foreach ($this->profiles as $profile) { $profiles[$profile['tableId']] = $profile; } // correct table id if (isset($profiles[$tableId])) { // save table id and account title $this->tableId = $tableId; $this->accountName = $profiles[$this->tableId]['accountName']; $this->profileTitle = $profiles[$this->tableId]['title']; $webPropertyId = $profiles[$this->tableId]['webPropertyId']; // store the table id and account title in the settings BackendModel::setModuleSetting($this->getModule(), 'account_name', $this->accountName); BackendModel::setModuleSetting($this->getModule(), 'table_id', $this->tableId); BackendModel::setModuleSetting($this->getModule(), 'profile_title', $this->profileTitle); BackendModel::setModuleSetting($this->getModule(), 'web_property_id', $webPropertyId); } } } } }