Node hits getting cached for anonymous user
Ok i have resolved this using a database query and a custom block. Pre-req: Installing visitors module.
Then having this query in the custom clock
public function build() {
  $node = \Drupal::request()-&gt;attributes-&gt;get('node');
  $uidValue = $node-&gt;getOwnerId();
  $urlValue = $node-&gt;toUrl()-&gt;toString();
  $database = \Drupal::database();
  **$query = $database-&gt;query(&quot;SELECT COUNT(visitors_path) AS visitors_path FROM 
(visitors) WHERE visitors_path='$urlValue' &quot;);**
  $result = $query-&gt;fetchAll();
  $nodecounthit = $result{0}-&gt;visitors_path;
  echo &quot;Viewed &quot;.$nodecounthit.&quot; times&quot;;
//$nodeCount=MyBlock::test();
      }

this function ensured results were not cached.
 public function getCacheMaxAge() 
  {
    return 0;
  }