WP Lite Views
WP Lite Views is a lightweight first-party view counting plugin for WordPress.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/r-/wp-lite-views/archive/refs/heads/main.zipLightweight first-party view counting for WordPress content.
WP Lite Views stores aggregate view counts for public WordPress content and exposes helper functions so themes, templates, blocks, or other first-party code can build their own popular-content displays.
It is intentionally not a display plugin. It does not render widgets, shortcodes, or frontend lists by default.
It is not a full analytics system and should not be treated as a replacement for Google Analytics, server analytics, privacy review, or a professional analytics pipeline.
Why does this plugin exist?
WP Lite Views exists for WordPress sites that need a small local popularity signal without adopting a large analytics or statistics plugin.
Many sites only need simple data such as:
- which posts are most viewed
- which content was popular today
- which content was popular this week
- which content was popular this month
- recent daily history for a known post
This plugin stores that data locally in WordPress post meta and exposes helper functions for custom display code.
What it does
- Tracks public views through a REST request after page load.
- Tracks only configured public post types.
- Uses browser cooldown storage to limit repeated counts.
- Excludes logged-in editors/admins by default.
- Excludes obvious bots and synthetic testing agents by default.
- Stores flat numeric counters for sorting/querying.
- Stores compact JSON stats for per-post history/state.
- Supports lazy day/week/month reset logic.
- Provides helper functions for counts, history, and popular-content queries.
- Can wait for analytics consent before using browser storage.
What it does not do
- It does not render public "popular posts" widgets.
- It does not provide an admin dashboard.
- It does not provide exact analytics.
- It does not identify visitors.
- It does not track sessions.
- It does not store IP addresses.
- It does not replace Google Analytics or server logs.
- It does not provide proof-of-consent records.
- It does not create a custom database table in v0.1.
Good use cases
WP Lite Views is a good fit for:
- blogs
- small content sites
- documentation sites
- indie studio sites
- portfolio sites
- first-party tool sites
- custom popular-content sections
- lightweight local ranking signals
It is best when the site owner controls the frontend and wants to build their own displays.
Bad use cases
Do not use WP Lite Views as your analytics system if you need:
- exact pageview counts
- unique users
- sessions
- attribution
- campaign reporting
- detailed dashboards
- high-traffic precision
- long-term time-series analytics
- consent logs
- large-scale reporting
Use a proper analytics system or a custom table-based reporting system for those needs.
Default scope
Tracked by default:
post
No public output is rendered by default.
Storage model
View counters are stored in post meta:
_wp_lite_views_total
_wp_lite_views_day
_wp_lite_views_week
_wp_lite_views_month
_wp_lite_views_stats
Flat numeric fields are used for sorting and popular-content queries.
The JSON stats field stores period keys, recent daily history, and the last
viewed timestamp. Do not query inside _wp_lite_views_stats.
Counting model
The plugin enqueues a small frontend script on singular tracked content.
The script sends a POST request to:
/wp-json/wp-lite-views/v1/view
This avoids counting during PHP page render and remains compatible with cached HTML.
Configuration
Use the wp_lite_views_config filter.
add_filter( 'wp_lite_views_config', function ( $config ) {
$config['post_types'] = [ 'post' ];
$config['cooldown_hours'] = 6;
$config['history_days'] = 30;
$config['track_total'] = true;
$config['track_day'] = true;
$config['track_week'] = true;
$config['track_month'] = true;
$config['track_history'] = true;
$config['exclude_logged_in'] = true;
$config['excluded_caps'] = [ 'edit_posts', 'manage_options' ];
$config['exclude_bots'] = true;
return $config;
} );
Consent-aware counting
By default, WP Lite Views does not assume a consent plugin exists.
If a site needs analytics consent before browser storage or local view counting, enable:
$config['require_analytics_consent'] = true;
When enabled, the frontend script waits for a compatible consent API before it uses browser storage or sends the REST request.
Supported APIs/events:
window.wpLiteConsentGate.has('analytics');
window.wpLiteConsent.has('analytics');
wp-lite-consent-gate:update
wp-lite-consent:update
If consent is required and no compatible consent layer is present, counting stays disabled for that page view.
Helper functions
wp_lite_views_get_count( $post_id, 'total' );
wp_lite_views_get_count( $post_id, 'day' );
wp_lite_views_get_count( $post_id, 'week' );
wp_lite_views_get_count( $post_id, 'month' );
wp_lite_views_get_history( $post_id, 30 );
wp_lite_views_get_popular( [ 'post_type' => 'post', 'posts_per_page' => 5 ] );
day, week, and month helpers return 0 when the stored period key is
stale.
Privacy
The plugin adds suggested privacy policy text through
wp_add_privacy_policy_content().
It stores aggregate counters in WordPress post meta and does not send view data to third parties.
If require_analytics_consent is enabled, browser storage and frontend view
counting wait for analytics consent from a compatible consent layer.
Development checks
php -l wp-lite-views.php
php -l includes/helpers.php
php -l includes/counter.php
php -l includes/rest.php
php -l includes/frontend.php
php -l includes/privacy.php
node --check assets/view-counter.js
License
GPL-2.0-or-later.