Track logged in users’ visits

As it’s a small site, you can do some “real” tracking:

// Update the visit time on *every* request
function wpse32258_update_usertracking(){
    if ( is_user_logged_in() ) {
        $user_ID = get_current_user_id();

        $data = get_user_meta( $user_ID, 'user_tracking' );
        $data[] = current_time( 'timestamp', true );

        update_user_meta( $user_ID, 'user_tracking', $data );
    }
}
add_action( 'init', 'wpse32258_update_usertracking' );

// Output the user visit dates below the footer for admin
function wpse32258_get_usertracking(){
    if ( ! current_user_can( 'manage_options' ) )
        return;

    $data = array();
    foreach ( get_users() as $user ){
        $dates = get_user_meta( $user->ID, 'user_tracking' );
        echo "<h3>{$user->first_name} {$user->last_name}</h3><hr />";
        foreach ( $dates as $date )
            echo "{$date}\n";
        echo '<hr />';
    }
}
add_action( 'shutdown', 'wpse32258_get_usertracking' );

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)