=== Search Insights Dashboard ===
Contributors: egosaru
Tags: seo, google search console, ga4, analytics, dashboard
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Collect Google Search Console and GA4 data into your WordPress database and visualize it as an SEO insights dashboard.

== Description ==

Search Insights Dashboard automatically collects data from Google Search Console (GSC) and Google Analytics 4 (GA4) and displays it directly in your WordPress admin area.

**Key features:**

* **Overview tab** — Clicks, impressions, CTR, average position, sessions, and users for any date range. Daily line + bar chart included.
* **Groups tab** — Define category groups and see aggregated metrics per group.
* **Queries tab** — Top 200 search queries by clicks.
* **Pages tab** — Top 200 pages with both GSC and GA4 metrics side by side.
* **New posts tab** — Pages published within the last 90 days, showing post-index growth.
* **Outbound links tab** — Outbound click counts per domain, derived from GA4 outbound-click events.
* **Alerts tab** — Pages where clicks dropped 20 % or more compared to the previous 7-day period.
* **Events tab** — Log arbitrary events (publish, rewrite, etc.) with dates for annotation.

**How it works:**

* Data is collected via WP-Cron (no Python or external cron required)
* Service account JSON is encrypted with AES-256 before being stored
* Chart.js is bundled — no CDN dependency
* REST endpoints (`seodash/v1/map` and `seodash/v1/ingest`) maintain compatibility with external collectors
* Backfill runs in 31-day chunks, suitable for shared hosting

= External Services =

This plugin connects to the following Google APIs using the service account you configure:

* **Google Search Console API** — `https://searchconsole.googleapis.com/`
* **Google Analytics Data API** — `https://analyticsdata.googleapis.com/`
* **Google OAuth Token Endpoint** — `https://oauth2.googleapis.com/token` (JWT authentication)

Connections are made only during scheduled WP-Cron collection and when you click "Collect now" in the admin. No site content or personal data is transmitted — only the JWT signature for your service account.

For Google's data policies, see: https://cloud.google.com/terms/

= Setup =

1. Create a service account in Google Cloud Console.
2. Grant the service account Viewer access to Search Console and Analytics.
3. Download the JSON key.
4. Activate the plugin and go to **Settings → Search Insights** to upload the JSON.
5. Enter your GA4 Property ID and GSC Site URL, then save.
6. Optionally configure group definitions.
7. Go to **Data Collection → Start backfill** to fetch historical data.

== Installation ==

1. Upload the `search-insights-dashboard` folder to `/wp-content/plugins/`.
2. Activate the plugin under **Plugins → Installed Plugins**.
3. Go to **Settings → Search Insights** for initial setup.
4. Open **Search Insights** in the left admin menu to view the dashboard.

== Frequently Asked Questions ==

= How long does the PHP backfill take? =

It depends on your site's size. For 16 months of GSC data, dozens of WP-Cron runs are needed. On a site with regular traffic, WP-Cron fires automatically on page load, so the backfill typically completes within a few hours to a day.

= Is it compatible with the Python collector? =

Yes. The `seodash/v1/map` and `seodash/v1/ingest` REST endpoints are preserved, so existing `seo_dash_collect.py` scripts work without modification.

= Where is data stored? =

All data is stored in your WordPress database (`wp_sd_*` tables). The service account JSON is encrypted with AES-256-CBC before being saved to `wp_options`.

== Screenshots ==

1. Overview tab: daily click graph and KPI cards.
2. Groups tab: aggregated metrics by category group.
3. Settings page: service account JSON upload and group definitions.

== Changelog ==

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.0.0 =
Initial release.
