=== Weblix Analytics ===
Contributors: vahidbehnam
Tags: analytics, statistics, real-time, visitors, online-users
Requires at least: 5.3
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 2.0.1
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Real-time, lightweight and privacy-first analytics for WordPress. Powerful insights without slowing down your site.

== Description ==

### 🚀 Real-Time Lightweight Analytics for WordPress

**Weblix Analytics** is a fast, privacy-focused analytics plugin that delivers powerful real-time insights directly inside your WordPress dashboard — with zero impact on site speed.

**No external services. No heavy scripts. All data stays on your server.**

From live online users to detailed historical comparisons, Weblix Analytics gives you everything you need in a clean, fast, and developer-friendly package.

### ❓ Why Weblix?

Unlike cloud analytics services, Weblix Analytics keeps your data inside WordPress.

* No Google account required
* No third-party tracking cookies
* No external tracking scripts or pixels
* Real-time instant statistics
* Lightweight and fully self-hosted architecture

### 🌟 Key Features

**Live Real-Time Monitoring**
* Online users right now with device breakdown
* Active pages and recent visitors list
* 5-minute interval bar chart showing visitor flow
* Automatic dashboard refresh

**Powerful Analytics**
* Today statistics with hourly bar chart
* Advanced comparison: Today vs Yesterday, Last 7/30 days, custom date ranges
* Hour-by-hour comparison (Today vs Yesterday)
* Top Pages, Traffic Sources, Referrers
* Devices, Browsers, Operating Systems breakdown
* Percentage share column on all data tables
* Separate Bot statistics tab

**Smart Insights**
* Same-time traffic comparison (e.g. "Traffic up 23% vs yesterday at this time")
* Top traffic source of the day
* Most visited page highlight
* Hourly traffic spike detection

**Privacy & Protection**
* Optional IP hashing (GDPR friendly)
* Exclude logged-in users, roles, IPs, and URL patterns
* Advanced bot detection with server-side tracking
* Configurable data retention
* Rate limiting on all tracking endpoints

**Tools & Diagnostics**
* Full Diagnostics page: system health, REST API, cron, database status
* Manual run buttons for cleanup and aggregate
* CSV Export for daily metrics
* WordPress Dashboard widget with live stats, top pages and 5-min chart

**Cache Plugin Compatibility**
* Works with WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache
* Custom hourly rotating token system (no nonce dependency)
* REST API endpoints excluded from caching automatically

### ⚡ Built for Performance

* Lightweight tracker: one deferred POST per page view
* Dual-table database: live table for real-time, daily table for history
* Batch cleanup with LIMIT to prevent MySQL table locks
* 48-hour data retention in live table ensures nightly aggregation always works
* All queries use indexes and prepared statements

== Installation ==

**From WordPress Dashboard:**
1. Go to Plugins > Add New
2. Search for "Weblix Analytics"
3. Click Install Now and then Activate

**Manual Installation:**
1. Download the plugin archive
2. Upload the `weblix` folder to `/wp-content/plugins/`
3. Activate the plugin through the Plugins menu in WordPress

After activation, go to **Weblix** in the admin menu.

== Frequently Asked Questions ==

= Does Weblix Analytics slow down my website? =
No. The tracker sends one small deferred request per page view and has zero impact on page load time.

= Is it compatible with caching plugins? =
Yes. Weblix uses a custom hourly security token instead of WordPress nonces, making it fully compatible with all major caching solutions including WP Rocket and LiteSpeed Cache.

= Does Weblix use cookies? =
No. Weblix does not use tracking cookies.

= Does it respect user privacy? =
Yes. IP hashing is available. No personal data is stored or transmitted externally.

= How long is data kept? =
Live visit data is kept for 48 hours. Daily summaries can be kept forever or up to 10 years depending on your retention setting.

= Can I export my data? =
Yes. CSV export is available in the Settings page.

= What changed from version 1.x to 2.0? =
Version 2.0 is a complete rewrite. See the Changelog section for full details.

== Screenshots ==

1. WordPress Dashboard widget showing live online users, today's views, visitors, bots, and top active pages with a link to the full dashboard.
2. Realtime tab showing online users by device, bot count, smart insights bar, and the 5-minute interval visitor chart with auto-refresh countdown.
3. Today tab displaying total visitors, page views, bot visits, and an hourly bar chart of traffic throughout the day.
4. Compare tab with today vs yesterday same-time comparison, difference card with percentage, and a dual-line hourly chart.
5. Pages tab showing top pages with view count and percentage share, filterable by Today, Yesterday, Last 7/30/90 Days, or a custom date range.
6. Sources tab with a traffic type donut chart and top referrers table showing visit count, percentage share, type, and source domain.
7. Devices tab displaying device breakdown donut chart alongside browser and operating system tables with user counts and percentage share.
8. Bots tab showing top crawlers with visit count and percentage share, alongside a horizontal bar chart for quick visual comparison.
9. The plugin settings page showing general configurations, user/role exclusions, IP blocking, and URL filtering options.
10. The full Diagnostics dashboard displaying system status, database table metrics, row counts, and manual actions control panel.

== Changelog ==

= 2.0.1 =
* Improved bot detection logic
* Fixed duplicate check for bots (better counting)
* Updated Chart.js handling for better compatibility
* Minor UI and performance improvements

= 2.0 =
**Major rewrite — complete rebuild from the ground up.**

This version transforms Weblix from a simple online-user counter into a full real-time analytics suite.

**New: Dual-Table Database Architecture**
* Introduced a separate `weblix_daily` table for storing aggregated daily summaries
* Live `weblix` table now holds only the last 48 hours of raw visit data
* Nightly cron job aggregates yesterday's data into the daily table at 00:05 (WP timezone)
* Batch DELETE with LIMIT prevents MySQL table locks on high-traffic sites
* Previous version stored only raw visits with no historical summary

**New: Full Analytics Dashboard**
* Today tab: hourly bar chart, visitor/view/bot cards, top pages, traffic sources donut chart
* Compare tab: period-over-period comparison with line charts, quick presets (Today vs Yesterday, Last 7/30 days, This Month, custom ranges)
* Hour-by-hour comparison: Today vs Yesterday with per-hour line chart
* Pages tab: top pages with view count and percentage share, custom date range picker
* Sources tab: referrers with type classification, traffic source donut chart, percentage share
* Devices tab: device/browser/OS breakdown with charts and percentage share
* Bots tab: top bots with visit count and percentage share, bar chart
* Previous version: showed only a simple online users count and page list

**New: Real-Time Improvements**
* 5-minute interval bar chart in Realtime tab showing visitor flow over the last 60 minutes
* Bots Now card alongside Desktop/Mobile/Tablet breakdown
* Recent Visitors list with time, page, source, and device
* Previous version: showed only total online count with a basic page list

**New: Server-Side Bot Tracking**
* Bots are now tracked server-side via `template_redirect` hook — no JavaScript required
* Bot visits are stored separately with bot name detection
* Previous version: bot detection only worked if the bot executed JavaScript (most don't)

**New: Smart Insights Bar**
* Compares traffic today so far vs yesterday at the exact same time of day
* Highlights top traffic source and most visited page
* Detects hourly traffic spikes (2.5x above daily average)
* Previous version: no insights feature

**New: Cache-Proof Tracker**
* Replaced WordPress nonces with a custom hourly rotating HMAC token
* Token is valid for current hour and previous hour, surviving page cache
* Previous version: nonce-based tracking failed on cached pages

**New: WordPress Dashboard Widget Redesign**
* Shows Online Now, Views Today, Visitors Today, Desktop/Mobile/Tablet breakdown
* Top 5 active pages with progress bars and view counts
* 5-minute live chart embedded in widget
* Previous version: showed only online count and a simple number

**New: Diagnostics Page**
* System health table: DB connection, table status, row counts, DB size
* REST API connectivity test
* Cron job schedule status
* Manual "Run Now" buttons for cleanup and aggregate
* Plugin info: WP timezone, PHP version, MySQL version
* Previous version: no diagnostics

**New: Settings Improvements**
* Exclude specific roles, IPs, and URL patterns from tracking
* Optional IP hashing for GDPR compliance
* Configurable data retention period (1–10 years or forever)
* Cache plugin compatibility filters for WP Rocket, LiteSpeed, W3TC
* Previous version: only online window duration setting

**New: CSV Export**
* Export daily analytics data as CSV from the Settings page
* Previous version: no export

= 1.4.1 =
* Fix: Resolved nonce validation conflicts for logged-in users
* Optimization: Improved REST API request handling for smoother tracking

= 1.4 =
* Improved user identification method for more accurate online user tracking
* Enhanced cron job scheduling for better performance and efficiency

= 1.3 =
* Improved resource usage efficiency
* Added compatibility with caching plugins
* Enhanced online user tracking accuracy

= 1.2 =
* Optimized and improved the retrieval of page titles
* Enhanced resource usage efficiency for better performance
* Improved bot detection
* Fixed minor bugs related to cron scheduling
* Updated dashboard widget refresh interval from 5 seconds to 30 seconds

= 1.1 =
* Added weekly cleanup schedule for old records
* Improved database query performance
* Fixed minor bugs related to cron scheduling

= 1.0 =
* Initial release

== Upgrade Notice ==

= 2.0 =
**Major milestone update.** Complete rewrite introducing full analytics suite, historical data, smart insights, server-side bot tracking, cache-proof token system, and diagnostics. All existing data is preserved on upgrade.
