Function Reference: geodir_ga_get_analytics_accounts

Summary

This function has not been documented yet.

Source File

geodir_ga_get_analytics_accounts() is located in geodirectory-admin/admin_functions.php [Line: 6533]

Source Code

function geodir_ga_get_analytics_accounts()
{
    global $gd_ga_errors;
    $accounts = array();

    if(get_option('geodir_ga_auth_token')===false){update_option('geodir_ga_auth_token','');}


    if(get_option('geodir_gd_uids') && !isset($_POST['geodir_ga_auth_code'])){
      return get_option('geodir_gd_uids');
    }

    # Create a new Gdata call
    if ( trim(get_option('geodir_ga_auth_code')) != '' )
        $stats = new GDGoogleAnalyticsStats();
    else
        return false;

    # Check if Google sucessfully logged in
    if ( ! $stats->checkLogin() )
        return false;

    # Get a list of accounts
    try {
        $accounts = $stats->getAllProfiles();
    } catch (Exception $e) {
        $gd_ga_errors[] = $e->getMessage();
        return false;
    }


    natcasesort ($accounts);

    # Return the account array if there are accounts
    if ( count($accounts) > 0 ){
        update_option('geodir_gd_uids',$accounts);
        return $accounts;
    }
    else
        return false;
}