private function keepCurrentLocator(Request $request)
    {
        // Ensure a location is not already set, to avoid overwriting it.
        if (!@$_COOKIE[self::LOCATOR_COOKIE_NAME]) {
            $currentUrl = $request->getCurrentUrl();
            // Do not keep identity URLs.
            if (!preg_match('#/identity.+#', $currentUrl)) {
                setcookie(
                    self::LOCATOR_COOKIE_NAME,
                    $currentUrl,
                    time() + 300 // Keep it for 5 minutes.
                );
                Logger::get()->debug('Current locator stored: ' . $currentUrl);
            }
        }
    }