Unlock the power of Google Analytics with Big Query

Attribution Modeling in Google Analytics 4 using Big Query Data: Last Click vs Data-Driven in GA4

Marketers often ask the big question: “Which channel really drives conversions?”
With GA4 and BigQuery, you can move beyond guesswork and analyze attribution models directly in your data warehouse. In this post, we’ll show how to implement last-click attribution using SQL and compare it with GA4’s data-driven attribution (DDA) tables. This helps you evaluate channels side by side and optimize campaign spend more effectively.


Step 1. Last-Click Attribution in BigQuery

Let’s start with a simple last-click model. This approach gives credit to the last touchpoint (source/medium or campaign) before conversion.

WITH user_paths AS (
  SELECT
    user_pseudo_id,
    event_timestamp,
    traffic_source.source AS source,
    traffic_source.medium AS medium,
    traffic_source.name AS campaign,
    event_name
  FROM
    `project.dataset.events_*`
  WHERE
    event_name IN ("session_start", "purchase")
)

, ordered_events AS (
  SELECT
    user_pseudo_id,
    event_timestamp,
    source,
    medium,
    campaign,
    event_name,
    ROW_NUMBER() OVER(PARTITION BY user_pseudo_id ORDER BY event_timestamp DESC) AS rn
  FROM user_paths
)

SELECT
  user_pseudo_id,
  source,
  medium,
  campaign
FROM ordered_events
WHERE event_name = "purchase"
  AND rn = 1

How this works

Reference: GA4 traffic_source documentation.


Step 2. Data-Driven Attribution (GA4 Exported Tables)

If you have Attribution Modeling enabled in GA4, BigQuery automatically exports model comparison tables (attribution_*).

You can query data-driven attribution (DDA) like this:

SELECT
  event_date,
  traffic_source.source,
  traffic_source.medium,
  traffic_source.name AS campaign,
  SUM(conversion_credit) AS credited_conversions
FROM
  `project.dataset.attribution_*`
WHERE
  attribution_model = "DATA_DRIVEN"
  AND event_name = "purchase"
GROUP BY
  event_date, source, medium, campaign
ORDER BY credited_conversions DESC

How this works

Reference: GA4 Attribution Models.


Step 3. Comparing Last Click vs Data-Driven

Once you have both queries, you can:

For example, social may rarely be last-click but contribute significantly in DDA.


Practical Applications


TL;DR:

Discover more from GA4 BigQuery

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

Continue reading