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 by user_id and finding the MIN and MAX of timestamp.
  • To find first- and last-touch attribution, join that table back with the original page_visits table on user_id and timestamp.





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

Popular posts from this blog

Binomial Test in Python

Python Syntax and Functions Part2 (Summary Statistics)

Slicing and Indexing in Python Pandas