Craft CMS plugin to find recently viewed elements of any type
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resources/img
src Limited history to max 99 elements, removed a var dump Jan 10, 2019
.gitignore Initial commit Jan 7, 2019
CHANGELOG.md Bump v1.0.3 Jan 10, 2019
LICENSE.md Initial commit Jan 7, 2019
README.md Updated craft slack name Jan 9, 2019
composer.json

README.md

Recently Viewed for Craft CMS 3

Track what your users view and resurface it as you please.

Easily create lists of recently viewed articles, commerce products or anything else that you've modeled as an Element in Craft, even custom Element types.

Contents

License

This plugin requires a commercial license which can be purchased through the Craft Plugin Store.
The license fee is $14 plus $5 per subsequent year for updates (optional).

Requirements

This plugin requires Craft CMS 3.0.0 or later.

Usage

Install the plugin from the Craft Plugin Store in your site's control panel or manually using composer:

composer require mattgrayisok/craft-recently-viewed

Filtering

Once the plugin is installed you'll have access to two additional functions on all of your fluent element queries:

  • recentlyViewed() - Filter by recently viewed elements only
  • orderByDateViewed() - Order recently viewed elements by view date/time, most recent first

E.G.

{% set recentBlogPosts = craft.entries.section('blogPosts').recentlyViewed().orderByDateViewed().all() %}
{% set recentProducts = craft.products.recentlyViewed().orderByDateViewed().all() %}

Tracking

By default any element which is linked to a specific URL will be auto tracked. I.E. if you visit /blog/article-slug and Craft has been configured to automatically inject the entry variable into the corresponding template the entry will be auto-tracked.

You can disable this auto tracking behaviour in the plugin settings.

You can also manually track views in your twig templates using:

{% do craft.recentlyViewed.track(element) %}

OR

{% do craft.recentlyViewed.trackId(elementId) %}

You can pass any element type into the former function as long as it implements craft\base\ElementInterface.

Clearing

If you would like to clear the recently viewed history for any reason you can call:

{% do craft.recentlyViewed.clear() %}

Support

If you encounter any issues during the use of this plugin please let me know by:

  • Creating an issue on GitHub
  • Dropping me an email: matt at mattgrayisok dot com
  • Finding me in the Craft Slack: @mattgrayisok
  • DMing me on Twitter: @mattgrayisok

I'll respond to critical issues as quickly as I can.

Credits

Created by mattgrayisok.


Icon made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY