Author Page User id in functions.php for non login user

wp_loaded hook runs before WordPress has setup postdata so you won’t be able to get there the information you need.

The earliest hook you can use to have that information should be wp.

You can use is_author() to check if you’re on an author page and is_user_logged_in() to check if the user is logged in:

function zb_user_analyze() {
    if( is_author() && !is_user_logged_in() ) {
        $author_id = get_query_var( 'author' );
        // do something
    }
}
add_action('wp', 'zb_user_analyze');