You are here

function ga_stats_get_client in Google Analytics Statistics 7.2

Same name and namespace in other branches
  1. 7 includes/ga.inc \ga_stats_get_client()

GA client library factory.

Parameters

$suppress: If set to TRUE, will not output error results to the UI.

Return value

gapi

3 calls to ga_stats_get_client()
ga_stats_admin_settings in ./ga_stats.admin.inc
Callback for the GA Stats admin form.
ga_stats_can_authenticate in ./ga_stats.install
Determine if the user credentials can successfully authenticate against Google.
_ga_stats_update_counts in includes/ga.inc
Goes through sources and metrics and updates databases

File

includes/ga.inc, line 195

Code

function ga_stats_get_client($suppress = FALSE) {
  require_once 'gapi.class.php';
  $client = NULL;
  $user = variable_get('ga_stats_email', '');
  $p12_key = variable_get('ga_stats_private_key_p12', NULL);
  if ($user && $p12_key) {
    try {
      $client = new gapi($user, $p12_key);
    } catch (Exception $e) {
      $error = t('Invalid Google Analytics App authentication attempt.');
      watchdog('ga_stats', $e
        ->getMessage(), array(), WATCHDOG_ERROR);
    }
  }
  else {
    $error = t('Google Analytics API Email and p12 key are not set.');
    watchdog('ga_stats', 'Google Analytics API Email and p12 key are not set.', array(), WATCHDOG_ERROR);
  }
  if (!$suppress && isset($error)) {
    drupal_set_message($error, 'error');
  }
  if (!isset($error)) {
    watchdog('ga_stats', 'Successfully authenticated client with Google Analytics App.');
  }
  return $client;
}