=== Factorize Analytics ===
Contributors: webyoungstown
Tags: woocommerce, analytics, statistics, reports, products
Requires at least: 6.2
Tested up to: 6.7
Stable tag: 1.0.1
Requires PHP: 7.4
License: Factorize License (proprietary)
License URI: https://factorize.webyoungstown.com/license/

Per-product view and add-to-cart counters for WooCommerce, plus a Store Stats dashboard that drills down from site to category to product.

== Description ==

WooCommerce tells you what sold. It does not tell you what *almost* sold — which products people keep opening and carting without buying, and which listings nobody ever looks at. Factorize Analytics fills that gap with small, self-contained counters: every product tracks its own views and add-to-carts (a lifetime total plus a rolling 7-day figure), stored as ordinary post meta in your own database, with no cron job, no JavaScript tracker, and no external analytics service. The Store Stats dashboard then rolls those numbers up so you can drill from site totals to category to individual product in two clicks.

It was built for and battle-tested on a real 950-product liquidation store, where knowing which items get looked at — and which never do — decides what gets restocked, discounted, or pulled.

= Features =

* **Per-product view counter** — every product page view increments a lifetime total and a rolling 7-day figure, stored as post meta right on the product.
* **Per-product add-to-cart counter** — the same lifetime + 7-day pair for add-to-carts, counted by quantity (adding 3 units counts 3).
* **Self-resetting weekly buckets** — the 7-day figure is keyed to the ISO week and resets itself the first time it is touched in a new week. No cron job, no scheduled task, nothing to babysit.
* **Honest numbers** — views from logged-in users who can edit products (administrators, shop managers) are skipped so merchandising work does not inflate the stats, and obvious bots and crawlers are filtered out by user agent.
* **Social-proof line on the product page** — a small "12 views this week · 3 added to carts" line prints under the price. Only metrics that actually have a number are shown, so a brand-new product shows nothing at all rather than a row of zeros.
* **Views / Carts / Sold columns in the Products list** — each admin column shows this week / all time at a glance, and Views and Carts sort by their lifetime totals.
* **Store Stats dashboard** — a dedicated admin page (under the Factorize menu, `manage_woocommerce` capability) with three levels: site totals (product views, add-to-carts, units sold, products tracked), a per-category table, and a per-product drill-down.
* **Category drill-down** — click any category to see its products ranked by views, each row showing week / all-time views, carts, and sold figures, with a link to edit the product and a link to view it live.
* **Popularity and stock at a glance** — the product-level table shows each product's 0–100 popularity score (written by the Factorize Catalog plugin; a dash when absent) and its stock status, with out-of-stock flagged in red.
* **Sales figures straight from WooCommerce** — lifetime "Sold" comes from each product's own WooCommerce total-sales counter; weekly "Sold" lights up when the Factorize Catalog plugin is active.
* **Plays nicely with your other reports** — Store Stats links out to WooCommerce → Analytics for revenue and orders and to WP Statistics for site-wide traffic, and covers the one thing neither does: product view/cart counters rolled up by category.
* **Clean dashboards** — other plugins' admin notices and promo banners are stripped from Factorize screens.
* **Private by design** — counters are aggregate numbers in post meta. No external service, no cookies, no per-visitor tracking, no personal data, and nothing ever leaves your server.
* **Respectful uninstall** — deleting the plugin removes only its own options; the accumulated counters are deliberately kept, because deleting a plugin should never delete store history.

= Works standalone, better together =

Factorize is a modular WooCommerce toolkit for liquidation, bin, discount, and open-box stores, built and battle-tested on a real 950-product store. Every plugin works completely standalone; any of them alone stands up the shared "Factorize" admin hub, and together they fill it with category tabs (Insights / Selling / Customers / Storefront).

Factorize Analytics registers itself under the Insights tab. Installed alone, you get the full hub with the Analytics card and the Store Stats screen. Add the Factorize Catalog plugin and two extra figures light up automatically: weekly "Sold" counts and the 0–100 popularity score. Without it, weekly sold simply reads 0 and popularity shows a dash — nothing breaks.

= Configuration =

Version 1.0.0 ships with no tunables — it works out of the box, and the configuration plumbing exists so future settings can be added without changing call sites. The plugin reads the `factorize-analytics_options` option (an array; set any subset of keys with `update_option`), merges it over the (currently empty) defaults, and passes the result through the `factorize-analytics_config` filter for code-level overrides. Sites upgrading from the earlier "Empire Product Analytics" name keep working: the legacy `empire-product-analytics_options` option is still read as a fallback.

The counters live in six post-meta keys per product: `_et_views_total`, `_et_views_week`, `_et_views_week_key`, `_et_carts_total`, `_et_carts_week`, and `_et_carts_week_key`. The storefront stats line is a plain `<p class="et-stats">` element with no styling of its own — style it from your theme.

= Roadmap =

The following features are planned and do **not** exist in this version yet:

* View → cart → purchase conversion funnel
* CSV export
* Weekly email digest
* Traffic-source attribution
* Dead-listing and low-stock alerts
* Dashboard widgets

== Installation ==

1. Upload the `factorize-analytics` folder to `/wp-content/plugins/`, or install the zip through Plugins → Add New, then activate.
2. Make sure WooCommerce is active. The plugin never fatals without it, but view counting, cart counting, and Store Stats all need WooCommerce to do anything useful.
3. On activation a **Factorize** menu appears in the admin sidebar with **Store Stats** as a submenu (visible to users with the `manage_woocommerce` capability). The hub page shows the Analytics card under the Insights tab with an Open button that leads to the same screen.
4. There is nothing to configure and no keys to enter — counting starts immediately. Visit a few product pages in a private/incognito window (views from logged-in users who can edit products are deliberately skipped), add something to the cart, then open **Factorize → Store Stats** to see the numbers.
5. Check **Products → All Products** for the new Views / Carts / Sold columns, and any single product page for the social-proof line under the price once a product has non-zero weekly numbers.

== Frequently Asked Questions ==

= Does it require WooCommerce? =

For anything useful, yes. View counting only runs on single product pages, cart counting hooks WooCommerce's add-to-cart event, and Store Stats reads the product post type and category taxonomy. Every WooCommerce call is guarded with `function_exists`, so the plugin never causes a fatal error if WooCommerce is missing — it simply does nothing.

= Does it work without the other Factorize plugins? =

Yes, completely. Exactly two figures come from the sibling Factorize Catalog plugin when it is active: the weekly "Sold" counts and the 0–100 popularity score. Without it, weekly sold reads 0 and popularity shows a dash; views, carts, lifetime sales, and the whole dashboard work on their own.

= Where does the data live? Does anything leave my server? =

Everything is stored as post meta on each product in your own WordPress database. No external service is contacted, no JavaScript tracker is loaded, no cookies are set, and no per-visitor or personal data is recorded — only aggregate counters.

= Why don't my own page views show up? =

By design. Views from logged-in users who can edit products (administrators and shop managers) are skipped so merchandising work does not inflate the numbers, and requests whose user agent looks like a bot or crawler are ignored. Test from a logged-out or private browser window.

= How does the 7-day figure reset without a cron job? =

Each weekly counter stores the ISO week it belongs to. The first time a counter is touched or read in a new week, the stale bucket counts as zero and starts fresh — no scheduled task required.

= What happens to my data if I uninstall? =

Uninstalling deletes the plugin's own options only. The per-product counters are deliberately left in place, so reinstalling later picks up your history exactly where it left off.

== Screenshots ==

1. Store Stats site view — the site totals table (product views, added to carts, units sold, products tracked) and the per-category table, every figure shown as this week / all time.
2. Category drill-down — per-product rows with views, carts, and sold figures, the 0–100 popularity score, stock status, and edit/view links.
3. The Products admin list with the sortable Views / Carts / Sold columns.
4. The social-proof stats line under the price on a single product page.
5. The Factorize admin hub with the Analytics card under the Insights tab.

== Changelog ==

= 1.0.0 =
* Initial release.
* Per-product view and add-to-cart counters: lifetime totals plus self-resetting 7-day figures, with no cron job and no external service.
* Store Stats drill-down dashboard: site totals → per-category → per-product, with popularity and stock columns.
* Sortable Views / Carts / Sold columns in the Products admin list.
* Social-proof stats line on the single product page, printing only non-zero metrics.
* Stands up the shared Factorize admin hub (Insights tab) — standalone or alongside other Factorize plugins.
