$setting->set('value', trim($profileId)); $setting->save(); $setting = $modx->getObject('modSystemSetting', 'analytics_accountId'); $settings['accountId'] = trim($accountId); $setting->set('value', trim($accountId)); $setting->save(); $setting = $modx->getObject('modSystemSetting', 'analytics_webPropertyId'); $settings['webPropertyId'] = trim($webPropertyId); $setting->set('value', trim($webPropertyId)); $setting->save(); $modx->cacheManager->delete($days . '-analytics'); unset($_POST['siteSelect']); //echo '<META HTTP-EQUIV=Refresh CONTENT="1; URL='.$modx->getOption('manager_url').'">'; } //retrieve profiles $profilesxml = $ga->callApi($settings['sessionToken'], 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles'); $profiles = $ga->parseAccountList($profilesxml); $modx->smarty->assign('profiles', $profiles); //check if profile isset if (empty($settings['profileId']) || empty($settings['accountId']) || empty($settings['webPropertyId'])) { $modx->smarty->assign('managerUrl', $modx->getOption('manager_url')); return $modx->smarty->fetch($ga->config['elementsPath'] . 'tpl/widget.profile.tpl'); } //load header scripts $modx->regClientCSS($ga->config['assetsUrl'] . 'css/analytics.panel.widget.css'); $modx->regClientStartupScript($ga->config['assetsUrl'] . 'js/analytics.panel.widget.js'); $modx->regClientStartupScript('<script type="text/javascript">var days = ' . $days . ';</script>'); $modx->getCacheManager(); $analytics = $modx->cacheManager->get($days . '-analytics'); if (empty($analytics)) { //Retrieve all the data as xml