Skip to content

Instantly share code, notes, and snippets.

@atsu666
Created June 26, 2017 07:03
Show Gist options
  • Save atsu666/545b151d92be0b94910d437e089e13ae to your computer and use it in GitHub Desktop.
Save atsu666/545b151d92be0b94910d437e089e13ae to your computer and use it in GitHub Desktop.
php/ACMS/GET/Api/GoogleAnalytics/Ranking.php (Ver. 2.6.1.4)
<?php
class ACMS_GET_Api_GoogleAnalytics_Ranking extends ACMS_GET_Api_GoogleAnalytics
{
function get()
{
$Tpl = new Template($this->tpl, new ACMS_Corrector());
$email = config('google_api_app_service_email');
$key = config('google_api_client_id_key_location');
try {
$this->getService($email, $key);
$this->setStartDate(config('ga_ranking_start_date'));
$this->setEndDate(config('ga_ranking_end_date'));
$options = array(
"dimensions" => "ga:pageTitle, ga:pagePath",
"max-results" => config('ga_ranking_max_results', 30),
"sort" => "-ga:pageviews",
);
if ( config('ga_ranking_filters') ) {
// e.g. "ga:pagePath=~/(.*)\.html"
$options['filters'] = config('ga_ranking_filters');
}
$results = $this->getResults('ga:pageviews', $options);
if ( count($results->getRows()) === 0 ) {
$Tpl->add('notFound');
return $Tpl->get();
}
foreach ( $results->getRows() as $row ) {
$Tpl->add('ranking:loop', array(
'title' => $row[0],
'path' => $row[1],
'views' => $row[2],
));
}
} catch ( \Exception $e ) {
if ( DEBUG_MODE ) {
throw $e;
}
return '';
}
return $Tpl->get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment