You are here

function ga_stats_get_client in Google Analytics Statistics 7

Same name and namespace in other branches
  1. 7.2 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 196

Code

function ga_stats_get_client($suppress = FALSE) {
  require_once 'gapi.class.php';
  $email = variable_get('ga_stats_email', '');
  $password = variable_get('ga_stats_password', '');
  $type = variable_get('ga_stats_acct_type', NULL);
  $client = NULL;
  if (ga_stats_is_ready()) {
    try {
      $client = new gapi($email, $password, NULL, $type);
    } catch (Exception $e) {
      $error = t('Invalid Google Analytics authentication attempt.');
      watchdog('ga_stats', $e
        ->getMessage(), array(), WATCHDOG_ERROR);
    }
  }
  else {
    $error = t('Google Analytics Email and password not set.');
    watchdog('ga_stats', 'Google Analytics email and password 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.');
  }
  return $client;
}