npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medusa-plugin-recently-view

v0.0.1

Published

Track and display recently viewed products for Medusa v2. Improves conversion with product view history.

Readme

Medusa Recently Viewed Products Plugin

Track and display recently viewed products in your Medusa v2 store. This plugin helps improve conversion by showing customers products they've already shown interest in.

Features

  • Record product views – Track when customers view product pages (logged-in or anonymous)
  • Get recent products – Retrieve recently viewed product IDs for display in carousels, checkout, etc.
  • Session support – Works for both authenticated customers and anonymous visitors (via session_id)
  • Configurable – 20 products max, 30-day TTL (configurable in code)
  • Auto cleanup – Scheduled job removes records older than 30 days (daily at 3 AM)

Installation

npm install medusa-plugin-recently-view
# or
yarn add medusa-plugin-recently-view

Setup

  1. Register the plugin in medusa-config.ts:
import { defineConfig } from "@medusajs/framework/utils"

export default defineConfig({
  // ... your config
  plugins: [
    {
      resolve: "medusa-plugin-recently-view",
      options: {},
    },
  ],
})
  1. Run migrations:
npx medusa db:migrate

API Reference

POST /store/product-views

Record a product view. Call this when a customer views a product page.

Request body:

{
  "product_id": "prod_01ABC123",
  "session_id": "optional-for-anonymous"
}
  • product_id (required): The product ID that was viewed
  • session_id (optional): For anonymous users. Omit if customer is logged in (uses auth token)

Headers: Include Authorization: Bearer <token> for logged-in customers.

GET /store/product-views/recent

Get recently viewed product IDs.

Query params:

  • limit (optional): Max products to return (default: 20, max: 50)
  • session_id (optional): For anonymous users. Omit if customer is logged in

Response:

{
  "product_ids": ["prod_01ABC123", "prod_01DEF456", ...]
}

Storefront Integration

Recording a view (product page)

// When customer lands on product page
await fetch(`${MEDUSA_URL}/store/product-views`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    ...(token && { Authorization: `Bearer ${token}` }),
  },
  body: JSON.stringify({
    product_id: product.id,
    ...(!token && { session_id: getOrCreateSessionId() }),
  }),
})

Displaying recently viewed

const res = await fetch(
  `${MEDUSA_URL}/store/product-views/recent?limit=10` +
  (!token ? `&session_id=${getOrCreateSessionId()}` : ""),
  {
    headers: token ? { Authorization: `Bearer ${token}` } : {},
  }
)
const { product_ids } = await res.json()

// Fetch full product details via /store/products?ids=...

Publishing to npm

  1. Create an npm account at npmjs.com if you don't have one.

  2. Login from the terminal:

    npm login
  3. Build and publish:

    cd medusa-plugin-recently-view
    npm run build
    npm publish

    For a scoped package (e.g. @iulia_cyber/medusa-plugin-recently-view):

    npm publish --access public
  4. Version updates for future releases:

    npm version patch   # 0.0.1 -> 0.0.2
    npm version minor   # 0.0.1 -> 0.1.0
    npm publish

License

MIT