The documentation page for this module puts a request out for further examples of using the module to write custom code for a site. Here's one that I built that shows the top searches in a block. You have to drop this into a custom module for it to show up.

<?php
/**
 * Implements hook_block_info().
 */
function MODULENAME_block_info() {
 
$blocks['top_searches']['info'] = t('Top Searches');
  return
$blocks;
}

/**
 * Implements hook_block_view().
 */
function MODULENAME_block_view($delta = '') {
  switch (
$delta) {
    case
'top_searches':
     
$block['subject'] = t('Top Searches');
     
$block['content'] = MODULENAME_top_searches();
      return
$block;
  }
}

/**
 * Retrieves top searches for use in a Google Analytics Report block.
 * Built using the GA Query Explorer 2 app: http://ga-dev-tools.appspot.com/explorer/?csw=1
 */
function MODULENAME_top_searches() {
 
$params = array(
   
'metrics' => array('ga:searchUniques'),
   
'dimensions' => array('ga:searchKeyword'),
   
'sort_metric' => array('-ga:searchUniques'),
   
'start_date' => strtotime('-31 days'),
   
'end_date' => strtotime('-1 day'),
   
'max_results' => 30,
  );
 
$feed = google_analytics_api_report_data($params);
  if (
$feed->error) {
    return
FALSE;
  }

 
$output = '<div class="top-searches"><table>';
 
$count = 0;
  foreach (
$feed->results as $result) {
   
$zebra = ($count % 2) ? 'even' : 'odd';
   
$count++;
   
$output .= '<tr class="' . $zebra . '">
      <td width="50%">'
. $result['searchKeyword'] . '</td>
      <td width="50%">'
. $result['searchUniques'] . '</td>
    </tr>'
;
  }
 
$output .= '</table></div>';
  return
$output;
}
?>

Comments

protitude’s picture

I did something similiar to the above but created a page called 'top' and I'm just outputting a list of the top 'service' pages. You can change what pages or section you are focused on by changing the segment below, or you can remove it if you want the top pages sitewide.

<?php
/**
 * Implements hook_menu().
 */
function MODULENAME_menu() {
 
$items['top'] = array(
   
'page callback' => 'MODULENAME_callback',
   
'title' => t('Top Services'),
   
'access callback' => TRUE,
  );
  return
$items;
}

/**
 * Top Pages callback using google_analytics_api_report_data.
 */

function MODULENAME_callback() {
  
$params = array(
   
'metrics' => array('ga:pageviews'),
   
'dimensions' => array('ga:pageTitle', 'ga:hostname', 'ga:pagePath'),
   
'sort_metric' => array('-ga:pageviews'),
   
// The url or pagePath should contain 'services' in this example.
   
'segment' => array('dynamic::ga:pagePath=@services'),
   
'start_date' => strtotime('-1 days'),
   
'end_date' => strtotime('-1 day'),
   
'sort' => '-ga:pageviews',
   
'max_results' => 10,
  );
 
$feed = google_analytics_api_report_data($params);
  if (
$feed->error) {
    return
FALSE;
  }

 
$output = '<ul>';
  foreach (
$feed->results as $result) {
   
$output .= '<li><a href="' . $result['pagePath'] . '">' . $result['pageTitle'] . '</a> - views: ' . $result['pageviews'] . '</li>';
  }
 
$output .= '</ul>';

  return
$output;
}
?>
cthshabel’s picture

Can't wait to try something like this out. Thanks so much for sharing everyone!