Enhanced analytics package for WooCommerce stores with comprehensive frontend tracking for Automattic based projects.
- Comprehensive Event Tracking: 25+ predefined events covering e-commerce, navigation, and user interactions
- Session Management: Intelligent session tracking and user engagement metrics
- Proxy Tracking: Optional proxy-based tracking for enhanced privacy and performance
// Add to your plugin
use Automattic\Woocommerce_Analytics;
add_action(
'after_setup_theme',
function() {
Woocommerce_Analytics::init();
}
);The package only starts tracking when:
- WooCommerce 3.0 or higher is active and installed
- Jetpack is connected
- In site page context (not admin, ajax, xmlrpc, login, feed, cli, etc.)
- WordPress 5.0+
- WooCommerce 3.0+
- PHP 7.4+
If you plan on using this package in your WordPress plugin, we recommend using Jetpack Autoloader as your autoloader for maximum interoperability.
Enable advanced features using WordPress filters:
// Enable ClickHouse event tracking
add_filter( 'woocommerce_analytics_clickhouse_enabled', '__return_true' );// Enable proxy tracking for enhanced privacy and performance
add_filter( 'woocommerce_analytics_experimental_proxy_tracking_enabled', '__return_true' );The package integrates with WP Consent API to ensure GDPR and privacy regulation compliance. Tracking only occurs when users have granted consent for statistics collection.
When WP Consent API is not available, the package defaults to allowing all tracking to maintain backward compatibility.
| Event Name | Trigger | ClickHouse | Recording Method | Description |
|---|---|---|---|---|
session_started |
Page load | ✓ | JS | When user session begins |
session_engagement |
Page load (returning session) | ✓ | JS | When user visits site in existing session (engagement marker) |
| Event Name | Trigger | ClickHouse | Recording Method | Description |
|---|---|---|---|---|
page_view |
Page load | ✓ | JS | General page view tracking |
search |
Search action | ✓ | PHP → JS Queue | When site search is performed |
| Event Name | Trigger | ClickHouse | Recording Method | Description |
|---|---|---|---|---|
product_view |
Single product page | ✓ | PHP → JS Queue | When product page is viewed |
cart_view |
Cart page | ✓ | PHP → JS Queue | When cart page is viewed |
add_to_cart |
Add to cart action | ✓ | PHP (Immediate) | When products are added to cart |
remove_from_cart |
Remove from cart | ✓ | PHP (Immediate) | When products are removed from cart |
checkout_view |
Checkout page | ✓ | PHP → JS Queue | When checkout page is viewed |
product_checkout |
Checkout page | ✓ | PHP → JS Queue | When checkout page is viewed and cart is not empty |
product_purchase |
Order placed | ✓ | PHP (Immediate) | When purchase is completed |
order_confirmation_view |
Thank you page | ✓ | PHP → JS Queue | When order confirmation page is viewed |
post_account_creation |
Account creation | - | PHP → JS Queue | When new account is created during checkout |
| Event Name | Trigger | ClickHouse | Recording Method | Description |
|---|---|---|---|---|
my_account_tab_click |
Tab click | - | JS | When account navigation log out tab is clicked |
my_account_page_view |
Tab view | - | PHP → JS Queue | When account tabs/pages are viewed |
my_account_order_number_click |
Order number click | - | PHP → JS Queue | When order number link is clicked |
my_account_order_action_click |
Order action click | - | PHP → JS Queue | When order action buttons are clicked |
my_account_address_click |
Address link click | - | PHP → JS Queue | When address edit links are clicked |
my_account_address_save |
Address update | - | PHP (Immediate) | When user saves address information |
my_account_payment_add |
Payment method page | - | PHP → JS Queue | When add payment method page is viewed |
my_account_payment_save |
Payment method add | - | PHP (Immediate) | When payment method is added |
my_account_payment_delete |
Payment method delete | - | PHP (Immediate) | When payment method is deleted |
my_account_details_save |
Profile update | - | PHP (Immediate) | When account details are saved |
The Recording Method column shows how each event is processed:
JS- Pure client-side events recorded directly by JavaScript without server involvementPHP → JS Queue- Server-side events that are queued during page generation and passed to frontend for transmissionPHP (Immediate)- Server-side events sent immediately when triggered via WordPress hooks/actions
Each event includes contextual data such as:
- Product Information: ID, name, price, categories, SKU
- Cart Details: Item quantities, totals, currency
- User Data: Customer ID (when available and permitted)
- Session Information: Session ID, engagement metrics
- Page Context: URL, referrer, breadcrumbs
- Store Data: Order ID, payment method, shipping info
Woocommerce_Analytics- Main initialization classUniversal- Core tracking logic and WooCommerce hooksMy_Account- Account-specific event trackingWC_Analytics_Tracking- Event queuing and processingFeatures- Feature flag management
Analytics- Main client-side analytics classSessionManager- Session tracking and managementApiClient- REST API communication for proxy tracking- Event Listeners - Page-specific event handlers
PHP (Immediate) events:
- WooCommerce action/hook triggers PHP method
WC_Analytics_Tracking::record_event()called directly- Event sent immediately to Tracks and/or ClickHouse
PHP → JS Queue events:
- WooCommerce action/hook triggers PHP method
- Event queued via
enqueue_event()method - Queue injected into page via
window.wcAnalytics.eventQueue - Frontend JavaScript processes queue and sends to
_wcatracking pixel if proxy tracking is disabled, otherwise sent to Proxy API endpoint
JS events:
- Frontend JavaScript directly records events via
recordEvent() - Events sent to
_wcatracking pixel if proxy tracking is disabled, otherwise sent to Proxy API endpoint
The package uses a hierarchical approach to identify users for analytics:
Anonymous User Identification (in order of preference):
tk_aiCookie: Primary method using Tracks anonymous identifier cookie- IP-based ID (when proxy tracking enabled): Generates visitor ID from:
- Daily rotating salt (privacy-focused, changes daily)
- Domain name
- User IP address
- User agent string
- Creates SHA256 hash (16-char substring) for anonymous but consistent identification
- If no
tk_aicookie and proxy tracking disabled:null(no visitor tracking)
Session Management:
- Session cookies (
woocommerceanalytics_session) expire after 30 minutes or at midnight UTC (whichever comes first) - Used for tracking user journey within a session (separate from user identification)
- Contains session ID, landing page, and engagement status
# Build the client-side JavaScript
pnpm run build
# Development watch mode
pnpm run watchSee package.json for more commands.
When proxy tracking is enabled:
- Events are sent to a local WordPress REST API endpoint to improve event delivery reliability
- Server-side event validation and processing
- URL:
/wp-json/woocommerce-analytics/v1/track - Method: POST
- Permission: No authentication required
- Content-Type:
application/json
Client-Side Batching Logic:
- Events queued until batch size (10 events) or debounce delay (1s) reached
- Immediate flush on page unload (
beforeunload,pagehideevents) - Failed events automatically re-queued for retry
Server-Side Optimizations:
The package includes an optional MU plugin (woocommerce-analytics-proxy-speed-module.php) that significantly improves proxy performance by only loading WooCommerce, WooCommerce Analytics, and Jetpack for proxy requests
Enable debug mode for detailed logging:
// In browser console or add to page
localStorage.setItem( 'debug', 'wc-analytics:*' );Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.
woocommerce-analytics is licensed under GNU General Public License v2 (or later)