Google Ads tracks user journeys through multiple ad interactions before a conversion.
The attribution model must allocate conversion credit across all touchpoints.
Tables:
ad_clicks (
click_id BIGINT PRIMARY KEY,
user_id BIGINT,
campaign_id VARCHAR(50),
click_timestamp TIMESTAMP
)
conversions (
conversion_id BIGINT PRIMARY KEY,
user_id BIGINT,
conversion_value REAL,
conversion_timestamp TIMESTAMP
)
Implement a first-touch and last-touch attribution model:
- First-touch: attribute 50% of conversion value to the first click (earliest timestamp)
- Last-touch: attribute 50% of conversion value to the last click (latest timestamp) before conversion
- A click counts only if it occurred within 30 days before the conversion
Write a SQL query that returns:
conversion_id, user_id, conversion_value, first_click_campaign, last_click_campaign,
first_touch_value (50% of conversion), last_touch_value (50% of conversion)
Expected Output:
| Column | Type |
|---|
| conversion_id | INTEGER |
| user_id | INTEGER |
| conversion_value | REAL |
| first_click_campaign | TEXT or NULL |
| last_click_campaign | TEXT or NULL |
| first_touch_value | REAL (2 decimal places) |
| last_touch_value | REAL (2 decimal places) |
Order by conversion_id ASC.
If a user has no clicks within 30 days, both attribution values split equally as unattributed.