=== Datalayer Tracking via DataReshape for WooCommerce ===
Contributors: rwky
Donate link: https://www.paypal.me/eduardvd
Tags: datareshape, first-party-tracking, datalayer-tracking, woocommerce-tracking
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 7.4
WC requires at least: 8.2
WC tested up to: 10.6
Stable tag: 0.5
Requires Plugins: woocommerce
WC HPOS compatible: yes
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Official WooCommerce integration for DataReshape, enabling structured ecommerce tracking through the DataReshape platform.

== Description ==

DataReshape for WooCommerce integrates seamlessly with your WooCommerce-powered store, providing a structured and reliable way to track ecommerce events using a modern dataLayer approach, built and tested specifically for DataReshape.

This plugin does not replace analytics tools like Google Analytics or Meta Pixel. Instead, it acts as a bridge between WooCommerce and DataReshape, which handles event processing, routing, and deduplication.

An active DataReshape plan is required to use this plugin. All tracking logic, integrations, and event delivery are managed through the DataReshape platform.

It supports browser-side tracking for the full ecommerce funnel, allowing seamless integration with advanced analytics setups.

== Features ==

= Core Features =
- Global enable/disable for the integration
- DataReshape library integration
- Subdomain tracking support
- Fully compatible with WooCommerce HPOS (High-Performance Order Storage)

= Browser Events =
- View Item
- Add to Cart (AJAX + fallback for redirects)
- View Cart
- Remove from Cart
- Begin Checkout
- Purchase
- Google Consent Mode support
- Plain user data in dataLayer (DataReshape hashes server-side)

= Advanced Tracking =
- Full GA4-style ecommerce structure
- Product-level and cart-level data
- Coupon tracking (cart-level injection)
- Tax, discount, and stock status support
- Works with both simple, variable products and bundled products

= Reliability Enhancements =
- Handles non-AJAX add-to-cart flows
- Handles redirect-based add-to-cart (?add-to-cart=)
- Handles WooCommerce notices fallback
- Safe execution timing for low overhead
- Logging support via WooCommerce logger (for debugging enabled flows)

== Installation ==

1. Upload the plugin to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' screen in WordPress
3. Ensure WooCommerce is installed and active
4. Go to WooCommerce → Settings → DataReshape (or plugin tab)
5. Configure your integration settings

== Configuration ==

= Integration Setup =
- Enable Integration
- Tracking Subdomain
- Library ID

= Browser Events =
- Enable/disable individual events
- Consent mode configuration

== Frequently Asked Questions ==

= Does this plugin support GA4? =
Not quite! The plugin exposes a GA4-compatible ecommerce dataLayer, but actual tracking, routing, and integrations are handled via DataReshape only!

= Does it work without AJAX add-to-cart? =
Yes. It includes fallback mechanisms for redirect-based add-to-cart flows (native WooCommerce redirect to cart after adding a product).

= Does it support server-side tracking? =
Not in this version. Server-side tracking is planned for a future release.

= Will this slow down my website? =
No. The plugin is designed with performance in mind and uses lightweight, conditional execution; if anything, your setup should see a boost in speed compared to clasic integrationg (Meta, TikTok and Google).

= Is deduplication handled? =
Deduplication is handled by DataReshape. The plugin focuses on exposing accurate and complete data for DataReshape to pickup and process onward.

== Screenshots ==

1. Initial dashboard with general settings (Integration setup tab)
2. Browser events configuration tab

== Changelog ==

= 0.5 =
- Added a one-shot DNS / health check that runs upon saving settings and surfaces the result as a dismissible admin notice.
- Added a "Check tracking endpoint" button on the Integration setup tab for re-running the check on demand via AJAX.
- Removed SHA256 hashing of user data in the browser dataLayer. All identity fields (email, phone, first / last name) are now pushed plain — DataReshape's infrastructure hashes them before forwarding to downstream destinations.
- Dropped the now-obsolete "Send plaintext user data" toggle.
- Library loader now appends `&wp={plugin_version}` to the `main.js` request so DataReshape can see the installed plugin version.
- Added a wordpress.org update check next to the version badge in the settings header. When a newer release is available, a pill links straight to the wordpress.org plugin page (cached for 12h).
- Fixed a PII leak under page-caching plugins (reproduced on LiteSpeed Cache): when an incognito buyer completed checkout, the rendered thankyou page (containing the buyer's email, phone and address inside `window.dataLayer`) could be served from cache to the next visitor on the same URL. The plugin now sets `DONOTCACHEPAGE`, sends `Cache-Control: no-cache` headers and triggers LSCache's explicit opt-out hooks on any request that emits user identity data or a purchase payload.

= 0.4 =
- All checkboxes on the settings screen now default to off on a fresh install ("Enable integration", "Enable browser-side tracking", every per-event toggle, and "Send plaintext user data"). Existing installs keep their current values - this only affects new installations.
- Added a WordPress admin warning notice when the plugin is active but is not collecting events - either because the integration is disabled or because the tracking subdomain / library ID is empty. The notice links straight to the DATA Reshape settings tab and is suppressed on that tab to avoid duplication.

= 0.3 =
- Add-to-cart tracking now watches WooCommerce's `wc-ajax=add_to_cart` XHR directly, reading product, variation and quantity from the request payload. This fixes missed or zero-product-id events on stores using third-party AJAX add-to-cart plugins (e.g. "Ajax add to cart for WooCommerce" by QuadLayers) or themes whose buttons do not expose `data-product_id`.
- Removed the in-page dataLayer debug panel (the `?datareshape=debug` admin overlay). Use the WooCommerce logger (WooCommerce → Status → Logs, source `datalayer-tracking-datareshape-woocommerce`) or your browser's devtools `window.dataLayer` instead.

= 0.1 =
- Initial release
- Browser-side ecommerce tracking
- Add-to-cart fallback handling
- View cart and remove from cart events
- Purchase tracking with order fallback
- WooCommerce logger integration

== Upgrade Notice ==

= 0.5 =
Fixes a PII leak under page-caching plugins (notably LiteSpeed Cache) where a previous buyer's identity data could be served from cache to the next visitor. Also adds an on-save tracking endpoint health check (with an on-demand re-check button), removes browser-side SHA256 hashing in favour of DataReshape's server-side hashing, tags the loader request with the plugin version, and surfaces an update-available badge in the settings header.

= 0.4 =
Defaults all settings checkboxes to off on fresh installs (existing sites are not affected) and adds an admin warning notice when the integration is active but not configured.

= 0.3 =
Improves AJAX add-to-cart detection compatibility (notably with QuadLayers Ajax-Add-to-Cart and themes that AJAX the single-product page) and removes the in-page debug overlay.

= 0.1 =
Initial release.