Menu

Calculate customer acquisition cost by channel from GA4 BigQuery data
📰

Calculate customer acquisition cost by channel from GA4 BigQuery data

DEV Community: sql·関聖矢·about 6 hours ago
#prorIIVU
#devtosql#devto#dev#purchase#first
Long article (1001 words) — no AI summary yet.
Reading 0:00
15s threshold

CAC by channel is a simple division — ad spend ÷ new customers — wrapped in two hard problems: defining "new customer" in event data, and getting ad spend into the same query as GA4. Both are solvable in BigQuery without a CDP.

The definition used here: a new customer is a user_pseudo_id whose first purchase in the reporting period is treated as their acquisition, and the traffic source on that first purchase event is the acquisition channel. It's an approximation (see the caveats), but it's consistent, reproducible, and good enough to rank channels.

Step 1: New customers by channel

Find each user's first purchase timestamp in the period, join back to that exact event to read its traffic source, then aggregate:

WITH first_purchase AS ( SELECT user_pseudo_id , MIN ( event_timestamp ) AS first_purchase_timestamp FROM `project.analytics_123456789.events_*` WHERE _TABLE_SUFFIX BETWEEN '20260101' AND '20260131' AND event_name = 'purchase' GROUP BY user_pseudo_id ) , first_purchase_detail AS ( SELECT e .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.