Drupal 8: Build "visitor history" using Flag/Rules I need to build a history for visitors so they can see which pages they've visited (ideally filtered by type).  To do this, it seems that the correct combo is to use Flag module and then Rules.

I'd anticipate that I'd create a new rule config where I'd ensure the content was of a certain type, ensure a flag existed, then automatically mark the flag each time the content of that type was visited.  I'd also have to update the time if an 'already-flagged' content was visited again (ie. so it appears at the top of a 'history' list).

I've messed around with Rules in Drupal 8 and I didn't get far at all.  I could obviously add a rule for 'node is viewed', and then condition of it being the right type.  But then I got stuck.

I need to be able to do things like see if there's a flag available, see the current value of the flag for that user, automatically set/update the flag, etc.  I couldn't figure out how to do any of this.

Help? :)
Honestly I gave up pretty quickly since it seemed unnecessarily complicated.  I created a very basic module that handles the marking/unmarking via the Flag API.  It has a single hook that looks like this:

function mymodule_node_view(array &amp;$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {

  //UPON VIEWING 'mytype' NODES  
  if($entity-&gt;getType() == 'mytype'){ 

    //CREATE HISTORY FLAGS
    $uid = \Drupal::currentUser()-&gt;id(); //current user
    $flag_id = 'history'; //flag type is named history
    $flag_service = \Drupal::service('flag');
    $flag = $flag_service-&gt;getFlagById($flag_id);

    if($flag-&gt;isFlagged($entity) == '1'){
        //unflag then reflag to update date
        $flag_service-&gt;unflag($flag, $entity);
        $flag_service-&gt;flag($flag, $entity);
    } else {
        //flag it for the first time
        $flag_service-&gt;flag($flag, $entity);
 }   
 }
}