PHPackages                             nelson-nguyen/craft-store-view - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. nelson-nguyen/craft-store-view

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

nelson-nguyen/craft-store-view
==============================

Craft CMS Track total/day/week/month views per element.

1.0.1(11mo ago)020proprietaryPHPPHP &gt;=8.0CI passing

Since Jun 8Pushed 11mo agoCompare

[ Source](https://github.com/nnuyit/store-view)[ Packagist](https://packagist.org/packages/nelson-nguyen/craft-store-view)[ RSS](/packages/nelson-nguyen-craft-store-view/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

📦 Store View Plugin for Craft CMS
---------------------------------

[](#-store-view-plugin-for-craft-cms)

Track total, daily, weekly, and monthly views for entries, categories, tags, and custom routes. Fully supports multi-site setups, Blitz static caching, and works with Craft CMS 4 and 5.

---

✨ Main Features
---------------

[](#-main-features)

- Track views of Entries, Categories, Tags, and custom routes
- Multi-site support
- View counting via AJAX/fetch for Blitz/static cache compatibility
- Compatible with Craft CMS 4 and 5

---

🛠 Installation
--------------

[](#-installation)

Install via the Craft Plugin Store or with Composer:

```
composer require nelson-nguyen/craft-store-view
```

Search for "Store View" in the [Craft Plugin Store](https://plugins.craftcms.com/search?q=view+store&tab=plugins) and install from the Control Panel.

---

🧹 Reset Views Command
---------------------

[](#-reset-views-command)

To clear all stored view counts (total, daily, weekly, monthly), run the following console command manually:

```
./craft store-view/reset-view
```

---

⏰ Automate with Cron Job
------------------------

[](#-automate-with-cron-job)

You can schedule this command to run automatically every day at midnight using cron.

1. Open your server's crontab editor:

```
crontab -e
```

2. Add this line to run the reset command daily at midnight:

```
0 0 * * * /path/to/craft store-view/reset-view >/dev/null 2>&1
```

Make sure to replace /path/to/craft with the full path to your Craft CMS craft executable.

3. Save and exit the editor.

This will reset your view counts daily at 00:00 server time.

---

🔢 Count Views
-------------

[](#-count-views)

Manually trigger a view count for any supported element or custom URI:

```
{# Entry #}
{% do craft.storeView.count(entry.id) %}

{# Category #}
{% do craft.storeView.count(category.id) %}

{# Tag #}
{% do craft.storeView.count(tag.id) %}

{# Custom route (e.g., static page) #}
{% do craft.storeView.count(craft.app.request.getPathInfo()) %}
```

### 🔁 AJAX View Tracking (For Blitz/Static Cache Support)

[](#-ajax-view-tracking-for-blitzstatic-cache-support)

Use the following code to send an AJAX request that registers a view:

```
{% js %}
fetch('/store-view/api/track-page-view' + window.location.search, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-CSRF-Token': '{{ craft.app.request.csrfToken }}'
  },
  body: JSON.stringify({
    elementId: {{ entry.id ?? 'null' }},
    siteId: {{ currentSite.id ?? 'null' }},
    uri: window.location.pathname
  }),
});
{% endjs %}
```

---

🔍 Querying Store Views
----------------------

[](#-querying-store-views)

Use `craft.storeView.entries()` to retrieve and filter view statistics with a fluent API.

### 🔧 Basic Usage

[](#-basic-usage)

```
{% set views = craft.storeView.entries().all() %}
```

### 🔍 Filter by Section

[](#-filter-by-section)

```
{% set blogViews = craft.storeView.entries().sections('blog').all() %}
```

Multiple sections:

```
{% set views = craft.storeView.entries().sections(['blog', 'news']).all() %}
```

### 🔍 Filter by Category Group

[](#-filter-by-category-group)

```
{% set views = craft.storeView.entries().categories('topics').all() %}
```

### 🔍 Filter by Tag Group

[](#-filter-by-tag-group)

```
{% set views = craft.storeView.entries().tags('labels').all() %}
```

### 🕒 Filter by Date Range

[](#-filter-by-date-range)

```
{% set todayViews = craft.storeView.entries().withRange('today').all() %}
{% set thisWeekViews = craft.storeView.entries().withRange('thisWeek').all() %}
{% set thisMonthViews = craft.storeView.entries().withRange('thisMonth').all() %}
```

### 🛠 Custom Filters

[](#-custom-filters)

```
{% set views = craft.storeView.entries()
    .where({ elementId: 123 })
    .limit(10)
    .offset(5)
    .orderBy('total DESC')
    .all() %}
```

### 📄 Get One Record

[](#-get-one-record)

```
{% set view = craft.storeView.entries().where({ elementId: 123 }).one() %}
```

### 🔢 Count Total

[](#-count-total)

```
{% set count = craft.storeView.entries().sections('blog').count() %}
```

---

🧱 Data Structure
----------------

[](#-data-structure)

Each result is an instance of `nelsonnguyen\craftstoreview\models\StoreViewModel`.

### Example Output:

[](#example-output)

```
nelsonnguyen\craftstoreview\models\StoreViewModel {
  id: 1,
  uri: "custom/custom",
  elementId: null,
  siteId: 1,
  total: 2,
  day: 2,
  week: 2,
  month: 2,
  lastUpdated: DateTimeImmutable('2025-06-08 07:10:33.0 UTC'),
  element: null,
}
```

Or with populated element:

```
nelsonnguyen\craftstoreview\models\StoreViewModel {
  id: 1,
  uri: "custom/custom",
  elementId: null,
  siteId: 1,
  total: 2,
  day: 2,
  week: 2,
  month: 2,
  lastUpdated: DateTimeImmutable('2025-06-08 07:10:33.0 UTC'),
  element: {
    id: 2,
    title: "test channel",
    slug: "test-channel",
    uri: "channel/test-channel",
    type: "Entry"
  }
}
```

---

📘 Notes
-------

[](#-notes)

- `.sections()`, `.categories()`, and `.tags()` accept a string or array of handles.
- `.withRange()` accepts: `'today'`, `'thisWeek'`, `'thisMonth'`
- All methods are chainable.

---

📄 License
---------

[](#-license)

This is a commercial plugin available via the [Craft CMS Plugin Store](https://plugins.craftcms.com).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance52

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

338d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/77473c5e50b5c1d85698f37b8aaf21534c214a48e88fab005153fcb89c1a40d7?d=identicon)[nnuyit](/maintainers/nnuyit)

---

Top Contributors

[![uynguyen92](https://avatars.githubusercontent.com/u/51895709?v=4)](https://github.com/uynguyen92 "uynguyen92 (9 commits)")

### Embed Badge

![Health badge](/badges/nelson-nguyen-craft-store-view/health.svg)

```
[![Health](https://phpackages.com/badges/nelson-nguyen-craft-store-view/health.svg)](https://phpackages.com/packages/nelson-nguyen-craft-store-view)
```

###  Alternatives

[spicyweb/craft-neo

A Matrix-like field type with block hierarchy

395798.1k10](/packages/spicyweb-craft-neo)[verbb/vizy

A flexible visual editor field for Craft.

4348.6k](/packages/verbb-vizy)[verbb/social-poster

Automatically post entries to social media.

918.5k](/packages/verbb-social-poster)[verbb/icon-picker

A slick field to pick icons from. Supports SVGs, Sprites, Webfonts, Font Awesome and more.

16162.4k4](/packages/verbb-icon-picker)[craftcms/shopify

Shopify for Craft CMS

549.2k1](/packages/craftcms-shopify)[nystudio107/craft-webperf

Webperf helps you build &amp; maintain high quality websites through Real User Measurement of your website's performance

2540.9k1](/packages/nystudio107-craft-webperf)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
