コード例 #1
0
    $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
    $toplandingspagesxml = $ga->callApi($settings['sessionToken'], 'https://www.google.com/analytics/feeds/data?ids=' . $settings['profileId'] . '&start-date=' . $settings['start_date'] . '&end-date=' . $settings['end_date'] . '&dimensions=ga%3ApagePath&metrics=ga%3Aentrances%2Cga%3Abounces%2Cga%3AentranceBounceRate%2Cga%3Aexits&sort=-ga:entrances');
コード例 #2
0
// generate new access token with the refresh token
$token = $client->getAccessToken();
$client->setAccessToken($token);
$gsaCls = new Google_Service_Analytics($client);
//retrieve profiles
try {
    $accounts = $gsaCls->management_accountSummaries->listManagementAccountSummaries();
} catch (Exception $e) {
    $modx->smarty->assign('_langs', $lexicon);
    $modx->smarty->assign('authUrl', $client->createAuthUrl());
    $modx->smarty->assign('redirect_url', $client->createAuthUrl());
    $modx->smarty->assign('error', $e->getMessage());
    return $modx->smarty->fetch($ga->config['elementsPath'] . 'tpl/widget.auth.tpl');
}
//print_r($accounts);
$profiles = $ga->parseAccountList($accounts);
//print_r($profiles);exit;
$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