Reference → Recently Viewed — Reference

Recently Viewed — Reference

The Recently Viewed surface is the per-user history plane for items the visitor has interacted with on a public-facing SGEN site. It owns the capture of view events, the retention window that decides how long an item stays in the history, and the display rules that drive the storefront block that renders the list back to the visitor. Anything that answers "what did this visitor look at last" traces back to a record managed here.

This page is a reference for platform engineers and integrators who need to understand the surface before extending it, scripting against it, or wiring it into a custom storefront template. Customer-facing how-tos live in the customer docs set; this page describes the shape of the surface, not the steps to drive it.


Overview

Recently Viewed lives under the Recently Viewed module in SG-Admin. The module renders three primary views — the configuration page (retention window, capture rules, display rules), the per-content-type opt-in list, and the storefront block editor that controls the public-site rendering — and exposes a small set of write operations for capture-rule edit, retention change, display-rule edit, per-content-type opt-in, and per-user history clear.

The module is paired by convention with the public-site runtime. SG-Admin owns the configuration; the runtime captures view events as visitors navigate and writes them to the per-visitor history store. The storefront block reads from that store on every page request and renders the configured number of most-recent items back to the visitor.

A second surface — per-visitor identity bridging — lives adjacent to the main module. It resolves the anonymous browser session to a signed-in user when the visitor signs in, so that the anonymous browsing history merges into the signed-in user's record without losing the items viewed before sign-in.

Where it lives in SG-Admin:

  • Sidebar: SG-Admin → Recently Viewed
  • URL prefix: /sg-admin/recently-viewed/
  • View templates: application/views/Admin/RecentlyViewed/
The module is scoped to lightweight history tracking. Heavier behavior — wishlists, saved-for-later, recommendation engines, full session replay — lives in adjacent surfaces (Custom Objects, Analytics, Marketing) and is not part of Recently Viewed.
┌──────────────────────────────────────────────────────────────────────┐│ Storefront → Product page → Recently Viewed block │├──────────────────────────────────────────────────────────────────────┤│ Recently viewed ││ ││ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ││ │ │ │ │ │ │ │ │ │ │ ││ │ IMAGE │ │ IMAGE │ │ IMAGE │ │ IMAGE │ │ IMAGE │ ││ │ │ │ │ │ │ │ │ │ │ ││ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘ ││ Heritage Linen Shirt Field Bag Wool Throw Ceramic Mug ││ Tote Bag ││ $48 $89 $124 $78 $24 ││ ││ ← viewed 2m ← viewed 4m ← viewed 7m ← 1h ago ← 2h ago │└──────────────────────────────────────────────────────────────────────┘

Actions

The Recently Viewed surface exposes the following operations. Each is described by what it does to the data, not by its internal method name.

Capture a view (visitor-facing)

Records that a visitor (anonymous session or signed-in user) viewed a single content record. The action is idempotent within a configurable de-duplication window — repeated views within the window update the existing record's last-seen timestamp rather than creating a duplicate.

Read per-visitor history

Returns the most-recent items for a single visitor, ordered newest first, with content reference, viewed-at timestamp, and the count of distinct views. Supports filtering by content type and limiting to the storefront block's configured maximum.

Set retention window

Stores the per-content-type retention window — the duration after which a view event ages out of the history. Items older than the window are excluded from reads and eventually purged from storage.

Set capture rules

Stores the conditions under which a view event is captured. Rules cover whether to capture for anonymous sessions, whether to capture for signed-in users, the minimum dwell time before a view counts, and whether to count repeat views inside the de-duplication window.

Set display rules

Stores the configuration that drives the storefront block — maximum item count, sort order (most-recent first, most-viewed first), per-content-type filters, and the fallback behavior when the history is empty (hide the block, show a generic recommendation list, show top sellers).

Per-content-type opt-in

Toggles whether view events on a content type are captured. Off by default for any custom content type — the operator opts in explicitly. The opt-in is honored at both capture and display time.

Merge anonymous history into signed-in user

Called by the public-site runtime when an anonymous visitor signs in. The action moves view events from the anonymous session record to the signed-in user record, deduplicating against any items already in the signed-in history.

Clear per-user history

Clears the view history for a single user. Available as a self-service action from the user's profile and as an administrative action for operator-driven support. The clear is hard — cleared records are not recoverable.

Read aggregate view counts

Returns per-content view totals across all visitors over a configurable window. Used by adjacent surfaces (Analytics, recommendation engines) that need the rolled-up view counts.


Data model

A view event record carries the following fields. Field names below are the conceptual shape — the on-disk column names match closely but are not contractually stable across releases.

FieldTypeNotes
idintegerPrimary key.
visitor_idintegerForeign key to user when signed-in. NULL when anonymous.
visitor_sessionstringSession token when anonymous. Allows pre-signin merging.
content_idintegerForeign key into the content table for the type.
content_typestringThe content type slug.
first_viewed_attimestampSet on first capture.
last_viewed_attimestampUpdated on every capture within the de-duplication window.
view_countintegerTotal captures from this visitor on this content.
Per-content-type configuration:
FieldTypeNotes
content_typestringThe content type slug.
opted_inbooleanWhen false, capture and display are both suppressed.
retention_daysintegerView events older than this are aged out.
dedup_window_minutesintegerRepeat views within this window update the existing record.
min_dwell_secondsintegerMinimum visit time before a view counts.
Display configuration (storefront block):
FieldTypeNotes
max_itemsintegerLimit on items returned to the block.
sort_orderenumOne of recent, frequent.
content_type_filterarray of stringsContent type slugs to include.
fallback_behaviorenumOne of hide, generic_recommendations, top_sellers.
VIEW EVENT├── id integer primary key├── visitor_id integer NULL when anonymous├── visitor_session string for anonymous → signed-in merge├── content_id integer foreign key├── content_type string slug├── first_viewed_at timestamp├── last_viewed_at timestamp updated on dedup└── view_count integer captures from this visitorCONTENT-TYPE CONFIG├── content_type string slug├── opted_in boolean├── retention_days integer├── dedup_window_minutes integer└── min_dwell_seconds integerDISPLAY CONFIG (storefront block)├── max_items integer├── sort_order recent | frequent├── content_type_filter array└── fallback_behavior hide | generic_recommendations | top_sellers

Permissions

Access to the Recently Viewed surface is gated at two layers.

Layer 1 — admin gate. Every administrative action under SG-Admin passes through the platform's standard admin access check at request entry. The visitor-facing actions — capture a view, read own history, clear own history — pass through separate gates.

Layer 2 — per-action capability. Within SG-Admin, each Recently Viewed admin action checks a capability associated with the calling operator's role. The default role configuration ships with three roles — Administrator, Editor, Viewer — and the capability map is:

CapabilityAdministratorEditorViewer
Set retention window
Set capture rules
Set display rules
Per-content-type opt-in
Clear per-user history (administrative)
Read aggregate view counts
The visitor-facing actions — capture a view, read own history, clear own history — are available to every visitor (anonymous or signed-in) against their own record. No operator capability is required for a visitor to manage their own history.

Custom roles defined under Settings → Roles override the default map. The capability slugs are stable; the role slugs are configurable.

Privacy rules. The capture pipeline respects the site's Tracking Consent state. When tracking consent has not been granted, view events are not captured for the visitor. Existing history is preserved across consent changes — granting consent does not retroactively capture missed views, and revoking consent does not delete prior captured history.

Audit. Configuration writes — retention, capture rules, display rules, per-content-type opt-in — emit Activity Log entries. Per-visitor capture events are recorded in a separate stream rather than the Activity Log, to avoid flooding the log with high-volume events.

VISITOR LOADS A CONTENT PAGE│▼┌───────────────────────────┐│ Tracking Consent granted? │ no → skip└─────────────┬─────────────┘│ yes▼┌───────────────────────────┐│ Content type opted in? │ no → skip└─────────────┬─────────────┘│ yes▼┌───────────────────────────┐│ Min dwell met? │ no → skip└─────────────┬─────────────┘│ yes▼┌───────────────────────────┐│ Existing record in ││ dedup window? │└──────┬──────────────┬─────┘│ no │ yes▼ ▼write new update last_viewed_atrecord increment view_count│ │└──────┬───────┘▼VISITOR SIGNS IN LATER│▼merge anonymous → signed-in record

Related references

  • Tracking Consent — Reference. Owns the consent state that gates Recently Viewed capture. When consent is not granted, no view events are captured.
  • Custom Objects — Reference. Custom content types must be opted in to Recently Viewed before view events on them are captured.
  • Products — Reference. Product views are the highest-volume content type captured by this module on storefront sites.
  • Pages — Reference. Page views are captured when pages are opted in.
  • Posts — Reference. Blog post views are captured when posts are opted in.
  • Analytics — Reference. Reads the aggregate view counts and joins them against traffic, sessions, and conversion data.
  • Users — Reference. The anonymous-to-signed-in merge writes against the user record. Permanent user deletion cascades a clear-history on the way out.
  • Onboarding — Reference. Pairs with Recently Viewed for returning users — Onboarding surfaces uncompleted steps; Recently Viewed surfaces last-visited content.
For the corresponding customer-facing walkthrough — opting a content type in, choosing retention, theming the storefront block — see the Recently Viewed section of the customer docs at /docs/recently-viewed.
On this page