I wrote a custom module that records page views. So each time a user views a node, it creates an entry in a database table. Essentially I wanted my own custom statistics module.
The problem is, it's only called once. I would assume some kind of caching is applied to this function. I have this:
function hook_node_view( $node, $display, $view_mode, $langcode)
{
$nodeObject = $node['#node'];
$insert = array(
'created' => REQUEST_TIME,
'nid' => $nodeObject->id(),
'uid' => \Drupal::currentUser()->id(),
'ip' => \Drupal::request()->getClientIp(),
'session_id' => session_id(),
);
db_insert('node_view_log')
->fields($insert)
->execute();
}
But it is only called once per node, and not each time the node is viewed. Any idea as to why this is happening? Is there a way to turn of caching for this function only? Or is there perhaps a better place to log page views?