SiamCafe.net Blog
Technology

WordPress WooCommerce Metric Collection

wordpress woocommerce metric collection
WordPress WooCommerce Metric Collection | SiamCafe Blog
2025-09-06· อ. บอม — SiamCafe.net· 9,702 คำ

WooCommerce Metrics

WordPress WooCommerce Metric Collection Sales Analytics Customer Product Google Analytics GA4 GTM Dashboard Looker Studio Revenue AOV CLV Conversion

MetricFormulaTargetFrequencySource
RevenueSum of order totalsGrowth 10%/monthDailyWooCommerce
AOVRevenue / Orders> 1,500 THBWeeklyWooCommerce
Conversion RateOrders / Visitors> 2%DailyGA4
Cart Abandon1 - (Purchases / Add to Cart)< 70%WeeklyGA4
CLVAOV × Purchase Freq × Lifespan> 10,000 THBMonthlyCustom Query
Repeat RateReturning Customers / Total> 30%MonthlyWooCommerce

WooCommerce REST API

# === WooCommerce REST API Metrics ===

# pip install woocommerce

# from woocommerce import API
#
# wcapi = API(
#     url="https://myshop.com",
#     consumer_key="ck_xxxx",
#     consumer_secret="cs_xxxx",
#     version="wc/v3"
# )
#
# # Get orders
# orders = wcapi.get("orders", params={
#     "per_page": 100,
#     "after": "2024-01-01T00:00:00",
#     "status": "completed"
# }).json()
#
# # Get products
# products = wcapi.get("products", params={
#     "per_page": 100,
#     "orderby": "popularity"
# }).json()
#
# # Get sales report
# sales = wcapi.get("reports/sales", params={
#     "date_min": "2024-01-01",
#     "date_max": "2024-12-31"
# }).json()

from dataclasses import dataclass
import numpy as np

@dataclass
class DailyMetric:
    date: str
    revenue: float
    orders: int
    visitors: int
    new_customers: int
    returning_customers: int

metrics = [
    DailyMetric("2024-01-01", 45000, 28, 1200, 22, 6),
    DailyMetric("2024-01-02", 38000, 22, 980, 18, 4),
    DailyMetric("2024-01-03", 52000, 35, 1500, 28, 7),
    DailyMetric("2024-01-04", 41000, 25, 1100, 20, 5),
    DailyMetric("2024-01-05", 68000, 42, 1800, 35, 7),
    DailyMetric("2024-01-06", 72000, 48, 2200, 38, 10),
    DailyMetric("2024-01-07", 55000, 33, 1400, 25, 8),
]

print("=== Daily Metrics ===")
total_rev = sum(m.revenue for m in metrics)
total_orders = sum(m.orders for m in metrics)
total_visitors = sum(m.visitors for m in metrics)
aov = total_rev / total_orders
conv_rate = (total_orders / total_visitors) * 100

for m in metrics:
    daily_aov = m.revenue / m.orders if m.orders > 0 else 0
    daily_conv = (m.orders / m.visitors) * 100 if m.visitors > 0 else 0
    print(f"  [{m.date}] Rev: {m.revenue:,.0f} | Orders: {m.orders} | AOV: {daily_aov:,.0f}")
    print(f"    Visitors: {m.visitors} | Conv: {daily_conv:.1f}% | New: {m.new_customers}")

print(f"\n  Weekly Summary:")
print(f"    Total Revenue: {total_rev:,.0f} THB")
print(f"    Total Orders: {total_orders}")
print(f"    AOV: {aov:,.0f} THB")
print(f"    Conversion Rate: {conv_rate:.1f}%")

GA4 E-commerce Tracking

# === Google Analytics 4 E-commerce Events ===

# GTM Data Layer — View Item
# window.dataLayer = window.dataLayer || [];
# dataLayer.push({
#   event: 'view_item',
#   ecommerce: {
#     currency: 'THB',
#     value: 1500,
#     items: [{
#       item_id: 'SKU001',
#       item_name: 'Product Name',
#       item_category: 'Electronics',
#       price: 1500,
#       quantity: 1
#     }]
#   }
# });
#
# // Add to Cart
# dataLayer.push({
#   event: 'add_to_cart',
#   ecommerce: {
#     currency: 'THB',
#     value: 1500,
#     items: [{ item_id: 'SKU001', item_name: 'Product', price: 1500, quantity: 1 }]
#   }
# });
#
# // Purchase
# dataLayer.push({
#   event: 'purchase',
#   ecommerce: {
#     transaction_id: 'T12345',
#     value: 3000,
#     currency: 'THB',
#     shipping: 50,
#     tax: 0,
#     items: [
#       { item_id: 'SKU001', item_name: 'Product A', price: 1500, quantity: 1 },
#       { item_id: 'SKU002', item_name: 'Product B', price: 1500, quantity: 1 }
#     ]
#   }
# });

# WooCommerce functions.php — Auto push dataLayer
# add_action('woocommerce_thankyou', function($order_id) {
#     $order = wc_get_order($order_id);
#     $items = [];
#     foreach ($order->get_items() as $item) {
#         $product = $item->get_product();
#         $items[] = [
#             'item_id' => $product->get_sku(),
#             'item_name' => $item->get_name(),
#             'price' => $item->get_total() / $item->get_quantity(),
#             'quantity' => $item->get_quantity(),
#         ];
#     }
#     echo "";
# });

@dataclass
class FunnelStep:
    step: str
    users: int
    drop_rate: str
    action: str

funnel = [
    FunnelStep("Page View", 10000, "-", "SEO, Ads bring traffic"),
    FunnelStep("Product View", 4500, "55% drop", "Improve landing page"),
    FunnelStep("Add to Cart", 1200, "73% drop", "Better CTA, reviews"),
    FunnelStep("Begin Checkout", 600, "50% drop", "Simplify checkout"),
    FunnelStep("Purchase", 280, "53% drop", "Trust badges, payment options"),
]

print("\n=== Purchase Funnel ===")
for f in funnel:
    conv = (f.users / 10000) * 100
    print(f"  [{f.step}] Users: {f.users:,} | Drop: {f.drop_rate} | Overall: {conv:.1f}%")
    print(f"    Improve: {f.action}")

Dashboard and Optimization

# === Custom Dashboard KPIs ===

@dataclass
class KPIDashboard:
    kpi: str
    current: str
    target: str
    trend: str
    action: str

kpis = [
    KPIDashboard("Monthly Revenue", "1.2M THB", "1.5M THB", "↑ +8%", "Increase AOV with bundles"),
    KPIDashboard("AOV", "1,420 THB", "1,600 THB", "↑ +3%", "Add upsell cross-sell"),
    KPIDashboard("Conversion Rate", "2.8%", "3.5%", "→ stable", "A/B test checkout flow"),
    KPIDashboard("Cart Abandonment", "72%", "< 65%", "↓ -2%", "Add exit-intent popup"),
    KPIDashboard("Repeat Purchase", "28%", "> 35%", "↑ +2%", "Email automation loyalty"),
    KPIDashboard("CLV", "8,500 THB", "> 12,000 THB", "↑ +5%", "Retention campaigns"),
    KPIDashboard("Page Speed", "3.2s", "< 2.5s", "→ stable", "Image optimization CDN"),
    KPIDashboard("SEO Organic", "45% traffic", "> 55%", "↑ +3%", "Content marketing blog"),
]

print("Dashboard KPIs:")
for k in kpis:
    print(f"  [{k.kpi}] Current: {k.current} | Target: {k.target} | Trend: {k.trend}")
    print(f"    Action: {k.action}")

# Optimization Priorities
priorities = {
    "P0 — This Week": "Fix slow checkout page (3.2s → 2s), add trust badges",
    "P1 — This Month": "Implement cart abandonment email sequence (3 emails)",
    "P1 — This Month": "Add product recommendation engine (upsell/cross-sell)",
    "P2 — Next Month": "Launch loyalty program (points system)",
    "P2 — Next Month": "SEO content plan (4 blog posts/month)",
    "P3 — Quarter": "Migrate to headless WooCommerce + Next.js frontend",
}

print(f"\n\nOptimization Roadmap:")
for k, v in priorities.items():
    print(f"  [{k}]: {v}")

เคล็ดลับ

WooCommerce Metrics สำคัญมีอะไรบ้าง

Revenue AOV Orders Customer CLV Repeat Rate Churn Product Conversion Cart Abandonment Traffic Source ROI Marketing Stock Level

เก็บ Metrics อย่างไร

WooCommerce Analytics GA4 E-commerce GTM Tags REST API Plugin Metorik MonsterInsights SQL Query BigQuery Looker Studio Dashboard

ตั้ง Google Analytics 4 อย่างไร

GA4 Property GTM Plugin GTM4WP MonsterInsights Enhanced E-commerce view_item add_to_cart purchase Custom Dimensions Conversion Goals Report

สร้าง Custom Dashboard อย่างไร

Looker Studio GA4 WooCommerce API KPI Revenue Orders AOV Conversion Sales Trend Top Products Funnel Cart Abandonment Auto-refresh Email Report

สรุป

WordPress WooCommerce Metric Collection GA4 GTM REST API Revenue AOV CLV Conversion Funnel Cart Abandonment Dashboard Looker Studio Production Optimization

📖 บทความที่เกี่ยวข้อง

Python Click CLI Metric Collectionอ่านบทความ → WordPress WooCommerce Cloud Migration Strategyอ่านบทความ → Supabase Realtime Metric Collectionอ่านบทความ → WordPress WooCommerce Load Testing Strategyอ่านบทความ → WordPress WooCommerce สำหรับมือใหม่ Step by Stepอ่านบทความ →

📚 ดูบทความทั้งหมด →