Question 2.4 is as follows:
How many last touches on the purchase page is each campaign responsible for?
I am missing this information in your code and presentation. Again I see how your query on a single user is being used, however, we wanted to see the COUNT for each campaign. I do not see this in your code or your presentation. The correct code should have looked like this:
WITH last_touch AS (
SELECT user_id,
MAX(timestamp) AS last_touch_at
FROM page_visits
WHERE page_name = '4 - purchase'
GROUP BY user_id),
lt_attr AS (
SELECT lt.user_id,
lt.last_touch_at,
pv.utm_source,
pv.utm_campaign,
pv.page_name
FROM last_touch lt
JOIN page_visits pv
ON lt.user_id = pv.user_id
AND lt.last_touch_at = pv.timestamp
)
SELECT lt_attr.utm_source,
lt_attr.utm_campaign,
lt_attr.page_name,
COUNT(*)
FROM lt_attr
GROUP BY 1, 2, 3
ORDER BY 4 DESC;
You seem to have the first part of the code figured out which is great! The only part you are missing in most of these more complex queries is after JOIN. You look at just one user, while the question is asking for much more than that.
Question 2.4 is as follows: How many last touches on the purchase page is each campaign responsible for?
I am missing this information in your code and presentation. Again I see how your query on a single user is being used, however, we wanted to see the
COUNT
for each campaign. I do not see this in your code or your presentation. The correct code should have looked like this:You seem to have the first part of the code figured out which is great! The only part you are missing in most of these more complex queries is after
JOIN
. You look at just one user, while the question is asking for much more than that.