<?php
add_action('wp', function() {
    if (is_singular()) {
        DS1_post_view_count_set(get_the_ID());
    }
});

function DS1_post_view_count_set($postID) {
    $key         = 'ds1_post_view_count';
    $cookie_name = $key . '_' . $postID;

    if (empty($_COOKIE[$cookie_name])) {
        $count = get_post_meta($postID, $key, true);
        $count = $count ? intval($count) : 0;
        $count++;

        update_post_meta($postID, $key, $count);
        setcookie($cookie_name, '1', time() + 86400 * 2, COOKIEPATH, COOKIE_DOMAIN);
    }
}

function DS1_post_view_count_get($postID) {
    $key = 'ds1_post_view_count';
    return intval(get_post_meta($postID, $key, true));
}