Attribution data for Woocommerce Orders

Step 1. Get the available keys.

SELECT DISTINCT(`meta_key`) as the_key
FROM `wp_wc_orders_meta`
WHERE `meta_key` LIKE '%_wc_order_attribution%'
ORDER BY `wp_wc_orders_meta`.`meta_value` DESC;

Step 2. Get the data for a selected key from the above

SELECT pm.meta_value AS attribution_source,
COUNT(p.ID) AS order_count
FROM wp_posts p
JOIN wp_wc_orders_meta pm ON p.ID = pm.order_id AND pm.meta_key = '_wc_order_attribution_utm_campaign'
WHERE p.post_type = 'shop_order'
AND p.post_status IN ('wc-completed', 'wc-processing')
AND p.post_date BETWEEN '2025-01-01' AND '2025-01-31'
GROUP BY pm.meta_value
ORDER BY order_count DESC;

Step 3. Loop step 2, choosing another key from step 1.