=== PineCount – Analytics, Page Views, Live Visitors, AdSense ===
Contributors: riteshx100
Tags: analytics, statistics, pageviews, privacy, adsense
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lightweight, self-hosted analytics. Pageviews, visitors and traffic sources, stored in your own database with no cookies.

== Description ==

PineCount records pageviews in your site's own database and shows them in a clean dashboard inside wp-admin. Nothing is sent to a third-party analytics service.

It works with full-page caching: a small script reports each pageview from the browser, so cached pages are counted too.

**What you get**

* Pageviews, visitors, sessions and views per visit, by hour, day, week or month.
* Top pages, entry pages, referrers, traffic sources, devices and on-site searches.
* Comparison with the previous period.
* A dashboard widget and an admin bar counter for today's numbers.
* Optional live visitors, using the Redis server your object cache already uses.
* Optional Google AdSense earnings, page views, RPM and CTR next to your traffic.
* A read-only REST API, protected by a key you generate, for pulling reports into other tools.
* Data retention from 30 days to 5 years, and excluded paths with wildcards.

**Privacy**

* No cookies and no persistent visitor ID. A visitor is identified only by a hash of their IP address and browser, mixed with a secret salt that changes every day, so nobody can be followed from one day to the next. The IP address itself is never stored.
* Sessions use the browser's per-tab session storage, which is cleared when the tab closes.
* Logged-in users are not tracked unless you turn that on.
* You can honour the browser's Do Not Track signal from the settings.
* All data stays in your WordPress database.

== Installation ==

1. Install the plugin from the Plugins screen, or upload the `pinecount` folder to `/wp-content/plugins/`.
2. Activate it. Tracking starts straight away.
3. Open **Analytics** in the admin menu to see your dashboard, and **Analytics → Settings** to adjust tracking, retention and the optional features.

**Live visitors (optional)**

Live visitors need a Redis server. The plugin reads the same `WP_REDIS_*` constants in `wp-config.php` that the Redis Object Cache plugin uses, so if your object cache already runs on Redis there is nothing else to set up.

**Google AdSense (optional)**

1. In Google Cloud, create an OAuth client of type "Web application" and enable the AdSense Management API.
2. Add the redirect URI shown in **Analytics → Settings → AdSense** to that client.
3. Paste the client ID and secret into the settings, save, and click **Connect with Google**.

== Frequently Asked Questions ==

= Does it work with page caching? =

Yes. Pageviews are reported from the browser, so pages served from a cache are still counted.

= Does it use cookies? =

No. See the Privacy section above.

= Where is the data stored? =

In five tables in your WordPress database, prefixed `pinecount_`. You choose how long raw pageviews are kept.

= What happens when I delete the plugin? =

By default, deleting the plugin removes its tables and settings. Turn off "Delete all data on uninstall" in the settings if you want to keep them.

= Is there an API? =

Yes. Generate a key in the settings, then send it in the `X-PineCount-Key` header. The full reference is under **Analytics → Settings → API**.

== Screenshots ==

1. Pageviews and visitors by hour, with AdSense earnings, RPM, CTR and clicks.
2. Top pages, referrers, traffic sources, devices, on-site searches and entry pages.
3. The full Top pages table, with entries, bounce rate and live users for each page.
4. Settings, one section at a time.
5. The last seven days on the WordPress dashboard.

== External services ==

This plugin connects to Google only if you choose to connect Google AdSense in its settings. Until you do, it makes no external requests.

**Google OAuth** (accounts.google.com, oauth2.googleapis.com) is used to authorise read-only access to your AdSense account.

* When you click "Connect with Google", your browser goes to Google's sign-in page with your OAuth client ID.
* After you approve, the plugin sends your OAuth client ID, client secret and the authorisation code to Google to get a refresh token. The token is stored encrypted in your database.
* Before each report request, the plugin sends the client ID, client secret and refresh token to get a short-lived access token.
* When you click "Disconnect", the refresh token is sent to Google to be revoked.

**Google AdSense Management API** (adsense.googleapis.com) is used to read your earnings.

* While connected, the plugin requests today's estimated earnings, page views and clicks for your site every 10 minutes, and the last 7 days once a day, so Google's later corrections are picked up.
* It also lists your AdSense accounts and sites once when you connect, to find the site that matches this website.
* Only your access token and the account and site IDs are sent. No visitor data is ever sent to Google.

Google's terms and privacy policy:

* Google Terms of Service: https://policies.google.com/terms
* Google APIs Terms of Service: https://developers.google.com/terms
* Google Privacy Policy: https://policies.google.com/privacy

== Changelog ==

= 1.1.0 =
* New: API endpoint /live, the number of visitors on the site right now.
* New: API endpoint /live/report, live visitors by page, entry page, referrer, source, device and search, all from one reading.
* New: /summary accepts compare=true, adding the previous period's figures and the change on each.
* Changed: /summary and /report no longer include live_users; request /live instead. /summary returns adsense_page_views in place of page_rpm, which /report still provides.
* Fix: The dashboard widget's axis numbers are no longer partly hidden at 10,000 views and above.
* Tweak: Clearer API documentation on currency, sessions, bounce rate and date handling.

= 1.0.2 =
* Renamed to PineCount.
* New: Settings link on the Plugins screen.
* New: Check connection button in the Live visitors settings, to test the Redis server.
* Tweak: The live visitors requirements notice is hidden once live visitors are switched on.
* Tweak: The API key header is now X-PineCount-Key.
* Tweak: The Analytics menu now sits below the core WordPress menus.
* Tweak: Stricter escaping of icons and the API documentation page, and stricter sanitizing of settings.

= 1.0.1 =
* Fix: Saving the settings page now works.
* Tweak: All admin and widget styles, IDs and data attributes now use the unique pinecount prefix, to avoid clashes with other plugins.
* Tweak: Removed leftover code for moving data from an earlier development version.

= 1.0.0 =
* First public release.

== Upgrade Notice ==

= 1.1.0 =
API change: /summary and /report no longer return live_users (use the new /live endpoint), and /summary returns adsense_page_views instead of page_rpm. The dashboard is unaffected.
