My guess is that the user must be logged in? If that is the case you can simply store the page hits as metadata doing something like this:
add_shortcode('pagehits', 'showPageHits');
function showPageHits($attributes)
{
/** @var \WP_Query $wp_query */
global $wp_query;
$page = $wp_query->get_queried_object_id();
if (is_user_logged_in()) {
$user = wp_get_current_user()->ID;
$meta = get_user_meta($user, 'pagehits', true) ?: [
'pages' => [
$page => 0,
],
];
$meta['pages'][$page]++;
update_user_meta($user, 'pagehits', $meta);
} else {
$address = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
$cacheKey = 'pagehits_' . $address;
$meta = get_transient($cacheKey) ?: [
'page' => [
$page => 0,
],
];
$meta['pages'][$page]++;
set_transient($cacheKey, $meta);
}
echo sprintf(_n('You have visited this page: %d time', 'You have visited this page: %s times', $meta['pages'][$page]), $meta['pages'][$page]);
}
If the user is not logged in the above will store a transient entry where the key is created based on the clients ip address e.g. pagehits_192.0.0.1
.