You can try this, use of custom meta field to do that.
In functions.php
put this:
// add the tracker in your header by using wp_footer hook
function is_viewed ($post_id) {
if ( !is_single() ) return;
/*
At times queries performed in other templates such as sidebar.php may corrupt certain conditional tags.
For instance, in header.php a conditional tag works properly but doesn't work in a theme's footer.php.
The trick is to put wp_reset_query before the conditional test in the footer.
https://codex.wordpress.org/Conditional_Tags#In_a_theme.27s_footer.php_file
*/
wp_reset_query();
if ( empty ( $post_id) ) {
global $post;
$post_id = $post->ID;
}
if ( !has_views($post_id) ){
// This post is visited for the first time
// add post meta to mark this post as viewed
add_post_meta($post_id,'viewed', "YES", true);
}
}
add_action( 'wp_footer', 'is_viewed');
function has_views($post_id){
if (!get_post_meta($post_id,'viewed',true)) return false;
else return true;
}
then you can use has_views($post_id)
anywhere you want to test if post is visited for the first time or not