First and last touch attribution(Analyse advertisements) (LAST TOUCH AND FIRST TOUCH)
- UTM parameters are a way of tracking visits to a website. Developers, marketers, and analysts use them to capture information like the time, attribution source, and attribution medium for each user visit.
- First-touch attribution only considers the first source for each customer. This is a good way of knowing how visitors initially discover a website.
- Last-touch attribution only considers the last source for each customer. This is a good way of knowing how visitors are drawn back to a website, especially for making a final purchase.
- Find first and last touches by grouping
page_visits
byuser_id
and finding theMIN
andMAX
oftimestamp
. - To find first- and last-touch attribution, join that table back with the original
page_visits
table onuser_id
andtimestamp
.
WITH last_touch AS (
SELECT user_id,
MAX(timestamp) as last_touch_at
FROM page_visits
GROUP BY user_id)
SELECT lt.user_id,
lt.last_touch_at,
pv.utm_source
FROM last_touch lt
JOIN page_visits pv
ON lt.user_id = pv.user_id
AND lt.last_touch_at = pv.timestamp
WHERE lt.user_id = 10069;
WITH first_touch AS (
SELECT user_id,
MIN(timestamp) AS 'first_touch_at'
FROM page_visits
GROUP BY user_id)
SELECT ft.user_id,
ft.first_touch_at,
pv.utm_source
FROM first_touch AS 'ft'
JOIN page_visits AS 'pv'
ON ft.user_id = pv.user_id
AND ft.first_touch_at = pv.timestamp;
Comments
Post a Comment