How to detect first visit of a user?

No, there’s nothing in the core like that.

You can set a cookie and do it simply enough (warning: untested code follows).

<?php
function is_first_time()
{
    if (isset($_COOKIE['_wp_first_time']) || is_user_logged_in()) {
        return false;
    }

    $domain = COOKIE_DOMAIN ? COOKIE_DOMAIN : $_SERVER['HTTP_HOST'];

    // expires in 30 days.
    setcookie('_wp_first_time', '1', time() + (WEEK_IN_SECONDS * 4), "https://wordpress.stackexchange.com/", $domain);

    return true;
}

if (is_first_time()) {
     // it's the user's first time, do stuff!
}

Just make sure you have output buffering turned on or use that before anything gets sent to the screen to make sure the cookie gets set.