Unlock the power of Google Analytics with Big Query

Comparing Ecommerce Funnel Performance Across Campaigns and Product Categories in GA4 BigQuery

Yesterday’s post: How to Measure and Analyze Cart Abandonment with GA4 and BigQuery
Today, we’ll go beyond a single funnel view and break down performance by campaign and by product category — so you can quickly see what’s driving the best conversion rates.


Why This Matters

Not all campaigns or product lines pull their weight.
If you’re only looking at aggregate funnel metrics, underperforming campaigns can hide in the averages.
With GA4 + BigQuery, you can isolate funnel performance by:


SQL Walkthrough

We’ll calculate step-by-step conversion rates for each campaign and product category.


Step 1: Get Funnel Events with Campaign & Product Info

WITH funnel_events AS (
  SELECT
    user_pseudo_id,
    campaign,
    source,
    medium,
    item_category,
    event_name,
    event_timestamp
  FROM
    `your_project.analytics_123456789.events_*`
  WHERE
    _TABLE_SUFFIX BETWEEN '20250101' AND '20250131'
    AND event_name IN ('view_item', 'add_to_cart', 'begin_checkout', 'purchase')
)

How this SQL works:

📄 Docs: GA4 Event Parameters Reference


Step 2: Calculate Conversion Counts by Campaign & Category

, funnel_counts AS (
  SELECT
    campaign,
    source,
    medium,
    item_category,
    COUNT(DISTINCT CASE WHEN event_name = 'view_item' THEN user_pseudo_id END) AS view_item_users,
    COUNT(DISTINCT CASE WHEN event_name = 'add_to_cart' THEN user_pseudo_id END) AS add_to_cart_users,
    COUNT(DISTINCT CASE WHEN event_name = 'begin_checkout' THEN user_pseudo_id END) AS begin_checkout_users,
    COUNT(DISTINCT CASE WHEN event_name = 'purchase' THEN user_pseudo_id END) AS purchase_users
  FROM funnel_events
  GROUP BY campaign, source, medium, item_category
)

How this SQL works:


Step 3: Compute Step-by-Step Conversion Rates

SELECT
  campaign,
  source,
  medium,
  item_category,
  SAFE_DIVIDE(add_to_cart_users, view_item_users) AS view_to_cart_rate,
  SAFE_DIVIDE(begin_checkout_users, add_to_cart_users) AS cart_to_checkout_rate,
  SAFE_DIVIDE(purchase_users, begin_checkout_users) AS checkout_to_purchase_rate,
  SAFE_DIVIDE(purchase_users, view_item_users) AS overall_purchase_rate
FROM funnel_counts
ORDER BY overall_purchase_rate DESC

How this SQL works:


How to Use These Insights


TL;DR

Discover more from GA4 BigQuery

Subscribe now to keep reading and get access to the full archive.

Continue reading