Cache in hook preprocess page I'm trying to get a value of GET variable in hook_preprocess_page(), but I'm having problems with the cache. Only the first time the code is executed, I can get the value of the variable to put it in a cookie; if I try to load the same page with different values, the code doesn't execute.

I need to put this value in cookie to identify the source of leads.
If your preprocess doesn't affect the result of the page, and needs to execute even when the page is served from the page cache, you should move your logic to a Kernel Event subscriber, which replaces hook_boot() and hook_exit() from Drupal 7.

DrupalizeMe has an article on Event Subscribers, but the basic components are creating a class that implements EventSubscriberInterface, and then registering it as a service.

MYMODULE/EventSubscriber/MyEventSubscriber.php

class MyEventSubscriber implements EventSubscriberInterface {
  static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = ['onResponse'];
    return $events;
  }
  public function onResponse(FilterResponseEvent $event) {
    $request = $event-&gt;getRequest();
    $response = $event-&gt;getResponse();

    $parameter_value = $request-&gt;query-&gt;get('parameter_name');
    $response-&gt;headers-&gt;setCookie(new Cookie('cookie_name', 'cookie_value'));
  }
}


MYMODULE/MYMODULE.services.yml

MYMODULE.my_event_subscriber:
  class: Drupal\MYMODULE\EventSubscriber\MyEventSubscriber
  arguments: []
  tags:
    - { name: event_subscriber }


The request event can modify the request before other components receive it, but cannot affect the response.  The response event cannot modify the request, but is able to alter the response after it has been composed.
If you need to do both, your service object can store some state during the request event, and then alter the response based on that state during the response event.