=== GEO Metrics AI Traffic Monitor ===
Contributors:      humantrends, abignu
Tags:              logs, llm, ai, bot-detection, monitoring
Requires at least: 6.0
Tested up to:      7.0
Requires PHP:      8.1
Stable tag:        2.4.2
License:           GPL-2.0+
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Know which AI crawlers visit your site, how often, and what they read. Zero-config bot detection from your existing WordPress logs.

== Description ==

**GEO Metrics AI Traffic Monitor** turns your raw server and WordPress logs into actionable intelligence about AI bot traffic. In a world where ChatGPT, Claude, Gemini, and Perplexity crawl billions of pages to power their answers, knowing whether those bots visit *your* site — and what they read — is a new SEO frontier.

The plugin works out of the box with zero configuration. It reads your existing `debug.log`, access logs, and PHP error logs, identifies AI crawlers by their User-Agent string, and displays a clean analytics dashboard inside your WordPress admin.

= What you get =

* **AI Bot Dashboard** — KPI cards for total requests, AI bot visits, distinct bots detected, and the active date range. Visual trend chart broken down per bot per day. Donut chart of bot share.
* **Bot Details tab** — per-bot breakdown with company grouping (OpenAI, Anthropic, Google, Meta…), bot type (crawler / agent / search / researcher), top pages visited, and HTTP status distribution.
* **Log Viewer tab** — raw log lines with syntax highlighting, live refresh via AJAX, and per-event type/severity filtering.
* **Live Traffic capture** — the plugin writes its own `live.log` (no server log access needed), capturing every frontend, REST API, and AJAX request in Combined Log Format, with automatic 5 MB rotation.
* **Date range filter** — filter all dashboard data by custom date range or quick presets (Last 7 days, Last 30 days, etc.).
* **WP-Cron sync** — automatic parsing on a configurable schedule (Hourly / Every 6 hours / Twice daily / Daily).
* **Data retention** — configurable retention period (default 30 days) with automatic purge.
* **Proxy-aware IP detection** — optional trust of `X-Forwarded-For` / `CF-Connecting-IP` headers for sites behind Cloudflare or a reverse proxy.
* **GEO Metrics** — visit [trygeometrics.com](https://trygeometrics.com) for cross-site AI traffic aggregation and visibility scoring across your entire brand.

= Detected bots (40+) =

Organized by company:

* **OpenAI** — GPTBot, ChatGPT-User, OAI-SearchBot, OAI-AdsBot
* **Anthropic** — ClaudeBot, Claude-Web, Claude-User, Claude-SearchBot, anthropic-ai
* **Google** — Googlebot, Google-Extended, Gemini, Google-Agent, Google-CloudVertexBot, GoogleOther, Google-NotebookLM
* **Microsoft** — bingbot
* **Perplexity** — PerplexityBot, Perplexity-User, DuckAssistBot
* **Meta** — Meta-ExternalAgent, Meta-ExternalFetcher, Meta-WebIndexer
* **xAI** — GrokBot
* **Mistral AI** — MistralAI-User
* **ByteDance** — Bytespider, TikTokSpider
* **Apple** — Applebot
* **Amazon** — Amazonbot
* **Cohere** — cohere-ai
* **You.com** — YouBot
* **DuckDuckGo** — DuckDuckBot
* **Common Crawl / Research** — CCBot, AI2Bot
* **SEO tools** — AhrefsBot, AhrefsSiteAudit, SemrushBot, DotBot, Barkrowler, DataForSeoBot, ScreamingFrog
* **Other search engines** — BaiduSpider, Yandexbot, Naverbot, ShapBot

= Privacy =

The plugin reads log files already stored on your server. It does **not** set cookies, collect personal data from visitors, or make any external HTTP requests. Raw log lines are never stored in the WordPress database — only aggregated counts and parsed metadata are persisted.

= Source log support =

* WordPress `debug.log` (WP_DEBUG_LOG)
* PHP `error_log` (auto-detected from `php.ini`)
* Plugin-owned live traffic log (zero-config, works on any host)
* Web server access log (optional path in Settings)
* Up to 3 custom log paths

== Installation ==

1. Upload the `geo-metrics-logs` directory to `/wp-content/plugins/`, or install via the WordPress Plugins screen.
2. Activate the plugin through the **Plugins** screen.
3. Go to **GEO AI Monitor** in the left admin menu.
4. *(Optional)* In the **Settings** tab, enter the path to your web server access log and any custom log paths.
5. Click **Manual Sync** to parse logs immediately, or wait for the next WP-Cron run.

== Frequently Asked Questions ==

= I don't have access to my server's access log. Can I still detect bots? =

Yes. The plugin's built-in Live Traffic Monitor captures every request through WordPress's hook system and writes its own Combined Log Format file inside `wp-content/uploads/geo-metrics-logs/`. No server log access or WP_DEBUG configuration is required.

= How much memory does reading large log files use? =

Log files are read using `SplFileObject` which streams lines without loading the entire file into memory. By default all available lines are read. If you have very large log files (hundreds of MB), you can set a **Lines per Source** limit in Settings to cap how many lines are parsed per sync.

= Where is the parsed data stored? =

Aggregated counts and bot lists are stored in WordPress options. Raw parsed events are cached in a WordPress transient with a 6-hour TTL. Raw log file content is never written to the database.

= Can I use this with Cloudflare? =

Yes. Enable **Trust Proxy Headers** in Settings to use `CF-Connecting-IP` (or `X-Forwarded-For`) for correct visitor IP detection. Only enable this if your site is actually behind a trusted proxy.

= How do I set the access log path on cPanel / shared hosting? =

Common paths are `/home/username/logs/access.log` or `/var/log/apache2/access.log`. Contact your host if unsure. The Settings page shows a **Readable** / **Not readable** indicator after you save the path.

= Does the plugin slow down my site? =

The Live Traffic Monitor hook fires at `template_redirect` (priority 99) and writes a single line to disk — negligible overhead. Log parsing runs on WP-Cron, not on page load.

== Screenshots ==

1. **Dashboard** — KPI cards, per-bot daily trend chart, and bot-share donut chart.
2. **Bot Details** — per-bot breakdown with company, type, page-level stats, and HTTP status distribution.
3. **Log Viewer** — raw log lines with type/severity badges and live refresh.
4. **Settings** — log source configuration, sync interval, and retention settings.

== Changelog ==

= 2.4.2 =
* Moved live monitor log storage from wp-content/ to the uploads directory (wp_upload_dir()).
* Chart data now injected via wp_add_inline_script() instead of a raw <script> tag.
* Updated bundled Chart.js from 4.4.4 to 4.5.1.
* Fixed plugin header description to accurately reflect that no external HTTP requests are made.

= 2.4.0 =
* Per-bot daily chart: the trend line chart now shows a separate colored line for each detected bot.
* Removed 500-line read cap — plugin now reads all available log lines by default (configurable limit for memory-constrained environments).
* Purple top-accent border applied to all KPI stat cards for visual consistency.
* Admin menu icon uses native WordPress dashicon rendering.
* Lazy-populate fallback: `daily_bot_counts` option is rebuilt from the transient cache on first load after upgrade, so the chart is populated immediately without waiting for the next sync.

= 2.3.0 =
* Added date-range filter bar with quick presets (Last 7 / 30 days, This month).
* Dashboard data updates via AJAX without page reload when a date filter is applied.

= 2.2.0 =
* Bot Details tab: per-bot pages visited table, HTTP status badge distribution.
* Bot type classification (crawler / agent / search / researcher) with color-coded badges.
* Company grouping for bots (OpenAI, Anthropic, Google, Meta, etc.).

= 2.1.0 =
* Live Traffic Monitor: plugin now writes its own access log — bot detection works without server log access.
* Automatic 5 MB log rotation.
* Proxy header support (X-Forwarded-For / CF-Connecting-IP).

= 2.0.0 =
* Added 20+ new bot signatures: GrokBot, MistralAI-User, Gemini, Google-Agent, TikTokSpider, CCBot, AI2Bot, SEO researcher bots, and more.
* Donut chart for bot share of voice.
* Configurable data retention (default 30 days).
* Configurable sync schedule.

= 1.0.0 =
* Initial release.
* Detects GPTBot, ClaudeBot, PerplexityBot, Googlebot, bingbot, and 10 additional LLM bots.
* Dashboard with KPI cards and daily trend chart.
* Log Viewer with raw line display.
* WP-Cron sync with configurable interval.
* Zero-config bot detection from WordPress logs.

== Upgrade Notice ==

= 2.4.0 =
Recommended update. Removes the 500-line read cap that caused incomplete data on the initial dashboard load. Existing transient data is used automatically — no manual sync required after upgrading.
