長岡生コンクリート
setApplicationName("Hello Analytics Reporting"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']); $analytics = new Google_Service_Analytics($client); return $analytics; } function getFirstProfileId($analytics) { $accounts = $analytics->management_accounts->listManagementAccounts(); if (count($accounts->getItems()) > 0) { $items = $accounts->getItems(); $firstAccountId = $items[0]->getId(); $properties = $analytics->management_webproperties ->listManagementWebproperties($firstAccountId); if (count($properties->getItems()) > 0) { $items = $properties->getItems(); $firstPropertyId = $items[0]->getId(); $profiles = $analytics->management_profiles ->listManagementProfiles($firstAccountId, $firstPropertyId); if (count($profiles->getItems()) > 0) { $items = $profiles->getItems(); return $items[0]->getId(); } else { throw new Exception('No views (profiles) found for this user.'); } } else { throw new Exception('No properties found for this user.'); } } else { throw new Exception('No accounts found for this user.'); } } function getWeeklyRanking($analytics, $profile){ $results = $analytics->data_ga->get( 'ga:' . $profile, '7daysAgo', 'yesterday', 'ga:pageviews', array( 'dimensions' => 'ga:pagePath,ga:pageTitle', 'sort' => '-ga:pageviews', 'max-results' => '30', ) ); // 取得したデータから必要な部分を抽出 $data = $results->rows; // 7日前と昨日の日付を取得 $start = date('n/d', strtotime('-1 week')); $end = date('n/d', strtotime('-1 day')); // 配列で取得したデータをループで回してランキングに $ranking = '

' . $start . '~' . $end . 'の記事ランキング' . "

\n"; $ranking .= '
    '; foreach ($data as $key => $row) { $ranking .= '
  1. ' . $row[1] ." $row[2]PV
  2. \n"; } $ranking .= '
'; return $ranking; } ?>
このページのトップへ

施工実績はこちら

お問い合わせはこちら