=== SERVIT Analytics ===
Contributors: cservit
Tags: analytics, cookieless, statistics, privacy, gdpr
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Cookieless, privacy-friendly visitor analytics for WordPress — with dashboard, visitor flow, conversion and campaign tracking.

== Description ==

SERVIT Analytics records visits server-side without cookies, without external services and without storing personal data (IP addresses). All data stays in your own WordPress database.

= Dashboard features =

* KPI tiles: sessions today/total, pageviews, average duration, pages/session, online visitors (live)
* Conversions: orders, confirmed orders, confirmation rate, contact requests
* Visitor timeline (pageviews & sessions) as area chart
* Orders & contact requests as bar chart
* Traffic sources (Google, Bing, Direct, Referral, ...)
* Page types (freely configurable via regex)
* Devices (mobile/desktop/tablet) as donut chart
* Top pages today
* Visitor flow: entry page, the pages visited next and where sessions end, as a Sankey diagram
* Entry and exit pages with bounce rate and exit rate
* Daily details table
* Period switcher (week / month / quarter) and auto-refresh every 30 s

= Visitor flow =

The visitor flow shows the path visitors take through your site: which page they arrive on, which pages they open next and at which point they leave. It is drawn as a Sankey diagram over the first four steps of a session, with the most-used pages per step and everything else merged into one node.

Below it, two tables list the entry pages with their bounce rate and the exit pages with their exit rate, so you can see which pages bring visitors in and which ones end the visit.

This works on data you have already collected — no extra tracking and no additional data is stored for it. Pages imported from Statify are not included, because an imported row is a single view without a real session.

= Privacy (GDPR) =

* Cookieless — the session ID is stored only in the browser's sessionStorage and is cleared when the tab closes.
* No IP storage — a daily-rotating, non-reversible hash is used to count unique visitors.
* Optional: respect Do-Not-Track, exclude logged-in roles, bot filter.
* No external scripts, no CDN, no Chart.js — all charts are rendered locally as SVG.

= Conversions / Events =

Track conversions via PHP (e.g. after a contact form submission):

`do_action( 'servit_analytics_event', 'contact', array( 'label' => 'Contact Form' ) );`
`do_action( 'servit_analytics_event', 'order', array( 'value' => 49.90 ) );`
`do_action( 'servit_analytics_event', 'order_confirmed', array( 'value' => 49.90 ) );`

Or via JavaScript on the frontend:

`ServitAnalytics.track( 'contact', { label: 'Contact Form' } );`

The JavaScript helper is limited to non-monetary events (contact requests and tel/mailto/WhatsApp clicks) and is rate limited. Orders and their values are recorded server-side only — via the PHP hook above or the automatic shop integrations — so revenue figures cannot be forged from the browser.

**Automatic integrations** (individually toggleable under Analytics > Settings):

* Fluent Forms — each form submission counts as a contact request (optionally limited to specific form IDs).
* WooCommerce — new order = order event, completed = confirmed order.
* Easy Digital Downloads — purchase = order, completed = confirmed order.
* FluentBooking — booking = order, confirmed = confirmed order.

Hooks are only active when the respective plugin is installed. The status (detected / not found) is shown in the settings.

= Ads / Campaign Tracking =

Tag your ads with UTM parameters (e.g. `?utm_source=google&utm_medium=cpc&utm_campaign=summer_sale`) or rely on automatically detected click IDs (`gclid`, `gbraid`/`wbraid`, `fbclid`, `msclkid`, `ttclid`, `li_fat_id`).

* The campaign is stored cookieless in localStorage (last-touch) and attributed to a later order/contact within the attribution window — including server-side conversions (Fluent Forms, WooCommerce) via visitor-hash backfill.
* Paid clicks appear cleanly separated in the traffic sources (e.g. "Google Ads" instead of "Google").
* The dashboard shows a campaign table: sessions, orders, contacts, conversion rate, cost, revenue, ROAS and CPA.

Manage ad spend under **Analytics > Ads & Costs** — either manually per campaign/period or via CSV import (columns: date, campaign, cost, optional source; compatible with the daily export from Google Ads / Meta). The dashboard then calculates ROAS (revenue/cost) and CPA (cost/order).

Privacy note: click IDs and localStorage attribution may require consent in some jurisdictions. This implementation is deliberately cookieless and without a consent banner; legal classification is the responsibility of the site operator.

= Import from Statify =

Under **Analytics > Statify Import**, existing Statify data can be migrated. For each Statify row, the date, path (mapped to page type) and referrer (mapped to source) are imported. The import runs in batches (even for very large tables) and is repeatable without creating duplicates.

Important: Statify tracks neither devices nor sessions. Imported days therefore show no device breakdown; each historical pageview counts as one session. Sources and page types are fully preserved. Do not uninstall Statify before importing — otherwise the data is lost.

= Third-Party Services =

This plugin does **not** connect to any external service, API or CDN. All data is processed and stored locally in your WordPress database. No data is sent to or received from third-party servers. There are no remote requests of any kind.

= Data Storage =

The plugin creates three custom database tables (`{prefix}_servit_analytics_views`, `{prefix}_servit_analytics_events`, `{prefix}_servit_analytics_ad_costs`) to store pageviews, conversion events and ad spend data. No personal data (IP addresses, usernames) is stored. Visitor uniqueness is determined by a daily-rotating, non-reversible SHA-1 hash that cannot be traced back to an individual.

All data can be deleted by enabling "Delete all tables and data when the plugin is uninstalled" in the settings before uninstalling the plugin.

== Installation ==

1. Upload the `servit-analytics` folder to `/wp-content/plugins/` or install the ZIP via **Plugins > Add New > Upload**.
2. Activate the plugin. The database tables are created automatically.
3. Open the **Analytics** menu item in the admin sidebar.
4. Under **Analytics > Settings**, configure page-type rules, excluded roles and data retention.

== Frequently Asked Questions ==

= Does this plugin use cookies? =

No. The session ID is stored in `sessionStorage`, which is cleared automatically when the browser tab is closed. No cookies are set at any point.

= Does this plugin store IP addresses? =

No. A daily-rotating, salted SHA-1 hash is computed from the IP, user agent and a WordPress nonce salt. The hash is stored; the IP is never written to the database.

= Is this plugin GDPR compliant? =

The plugin is designed with GDPR in mind: no cookies, no IP storage, no external services. Whether consent is required depends on your specific use case and jurisdiction — consult your data protection officer or legal counsel.

= Does this plugin load external scripts or connect to remote servers? =

No. Everything runs locally. Charts are rendered as inline SVG. There is no CDN, no external JavaScript library and no remote API call.

= Can I use this alongside Google Analytics or other tracking tools? =

Yes. SERVIT Analytics operates independently and does not interfere with other analytics solutions.

= What happens to my data when I deactivate the plugin? =

Nothing. All data is preserved. The plugin only removes its cron jobs on deactivation. To permanently delete all data, enable "Delete all tables and data when the plugin is uninstalled" in the settings, then uninstall the plugin.

= How does the Statify import work? =

Go to Analytics > Statify Import. The plugin reads the Statify database table and imports date, path and referrer for each row. Since Statify does not track sessions or devices, each imported pageview is counted as a separate session. The import runs in batches and can be resumed safely.

= Which integrations are supported? =

Fluent Forms (contact requests), WooCommerce (orders), Easy Digital Downloads (orders) and FluentBooking (bookings). Each integration can be toggled individually in the settings and is only active when the respective plugin is installed.

== Screenshots ==

1. Dashboard overview with KPI tiles, visitor timeline and conversion charts.
2. Traffic sources and device breakdown.
3. Campaign / Ads table with ROAS and CPA.
4. Settings page with tracking options, integrations and page-type rules.
5. Ads & Costs management with manual entry and CSV import.

== Changelog ==

= 1.0.2 =
* New: Visitor flow — a Sankey diagram showing entry page, the pages visited next and where sessions end.
* New: Entry pages table with bounce rate, exit pages table with exit rate.
* Overall bounce rate for the selected period.

= 1.0.1 =
* All UI strings translated to English; German available via language files.
* Readme rewritten in English per WordPress.org guidelines.
* Plugin Check compatibility improvements.
* Added "Delete data on uninstall" setting to prevent accidental data loss.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.0.2 =
Adds the visitor flow view. No database changes — it is built from the pageviews you have already collected, so the history is there right after the update.

= 1.0.1 =
English is now the default language. Existing German data labels (e.g. "Direkt", "Startseite") are automatically migrated to English on upgrade. German translations are available via language files.
