Contensio logo

View Counter

Tracks post and page views in Contensio, surfaces a Popular Posts dashboard widget.

About this plugin

View Counter

Tracks views for every post and page in Contensio. Provides:

  • Per-content view counts - stored in a dedicated view_counts table
  • Throttled counting - each visitor IP is counted once per hour per content item (uses Laravel cache)
  • Popular Posts widget - a popular-posts widget type you can place in any widget area
  • Dashboard "Top Content" panel - top 10 most-viewed items with direct edit links, added to the dashboard widget area automatically

Requirements

  • Contensio 2.0 or later
  • Laravel 11+

Installation

Composer

composer require contensio/plugin-view-counter

Manual

Copy the plugin directory into your Contensio installation and register the service provider in your config/app.php or via the admin plugin manager.

Run migrations

php artisan migrate

This creates the view_counts table.


How it works

The plugin hooks into contensio/content/viewed, a core action that fires on every public post and page view:

Hook::doAction('contensio/content/viewed', $content);  // fired by FrontendController

The plugin's listener calls ViewCounter::increment($content->id), which:

  1. Checks a cache key vc_{contentId}_{ipHash} - skips if present (throttle active)
  2. Sets the cache key with a 1-hour TTL
  3. Does an updateOrCreate + increment('total') on the view_counts table

Popular Posts widget

After installing, a popular-posts widget type is available in Admin > Appearance > Widgets.

Config options:

Option Type Default Description
title text Popular Posts Widget heading
limit number 5 How many posts to show (max 20)
show_count checkbox true Show the view count next to each post

Place the widget in any area - sidebar, footer, after-post, etc.


Dashboard panel

A "Top Content" card is automatically injected into the admin dashboard widget area (priority 20). It shows the top 10 most-viewed content items with their view counts and links to the edit screen.

No configuration required.


Accessing view counts in your theme

use Contensio\Plugins\ViewCounter\Support\ViewCounter;

// Get the count for a single post
$views = ViewCounter::get($content->id);  // int

// Get top N most-viewed items
$popular = ViewCounter::popular(5);  // Collection of ViewCount models with ->content relation

Styling the Popular Posts widget

The widget outputs:

<div class="contensio-widget-popular-posts">
    <h3 class="contensio-widget-title">Popular Posts</h3>
    <ol class="popular-posts-list">
        <li class="popular-posts-item">
            <a class="popular-posts-link" href="...">Post title</a>
            <span class="popular-posts-count">1,234 views</span>
        </li>
    </ol>
</div>

Wrapped by the widget area renderer in:

<div class="contensio-widget contensio-widget--popular-posts">
    ...
</div>

Privacy note

This plugin stores view counts only - no personal data, no cookies, no user tracking. IP addresses are hashed and used only as a cache key to implement the 1-hour throttle; they are never persisted to the database.