robole/last-visited-pages

1.0.0 2025-01-09 14:55 UTC

This package is auto-updated.

Last update: 2025-02-22 13:09:42 UTC


README

GitHub release Supports Statamic 5 or later

Last Visited Pages

A Statamic addon that saves the most recently visited pages of frontend users in the session.

Features

  • Save the most recently visited pages of users in their session.
  • Customizable limits for the number of saved pages.
  • Multisite compatibility to save and filter pages by site or across sites.
  • Flexible inclusion and exclusion of collections.
  • Provides the {{ last_visited_pages }} tag to display the saved pages in templates.

Installation

Install this addon via Composer:

composer require robole/last-visited-pages

Configuration

The addon includes several configuration options that allow you to tailor its behavior. To publish the configuration file, run:

php artisan vendor:publish --tag=last-visited-pages-config

Available Configuration Options

The published configuration file allows you to adjust the following settings:

Maximum Saved Pages

  • Key: max_saved_pages
  • Default: 5
  • Description: Defines how many of the most recently visited pages will be saved in the session. If site_sensitive is enabled, this number is applied per site.

Site Sensitivity

  • Key: site_sensitive
  • Default: true
  • Description: If enabled, only pages from the same site as the current one will be saved and displayed by the {{ last_visited_pages }} tag.

Collections

  • Keys: include_collections, exclude_collections
  • Default:
    'include_collections' => ['*'],
    'exclude_collections' => [],
  • Description: Use include_collections to specify which collections should be tracked. Set to ['*'] to include all collections. Use exclude_collections to define collections that should be ignored from tracking. Example:
    'include_collections' => ['blog', 'products'],
    'exclude_collections' => ['drafts'],

Templating

To display the last visited pages of the current fronted user, you can use the {{ last_visited_pages }} tag anywhere in your template:

{{ nocache }}
    {{ if {last_visited_pages:count} > 0 }}
        {{ last_visited_pages }}
            <a href="{{ url }}">    
                {{ title }}
            </a>
        {{ /last_visited_pages }}
    {{ /if }}
{{ /nocache }}

Support

If you encounter any issues or have questions, please open an issue in the GitHub repository.

License

This addon is open-source and available under the MIT license.