diff --git a/macros/cross-adapter-modeling/base/segment_web_page_views.sql b/macros/cross-adapter-modeling/base/segment_web_page_views.sql index 3003f46..3b74f18 100644 --- a/macros/cross-adapter-modeling/base/segment_web_page_views.sql +++ b/macros/cross-adapter-modeling/base/segment_web_page_views.sql @@ -7,7 +7,51 @@ {% macro default__segment_web_page_views() %} -{{ exceptions.raise_compiler_error("macro segment_web_page_views not implemented for this adapter") }} +with source as ( + + select * from {{var('segment_page_views_table')}} + +), + +renamed as ( + + select + + id as page_view_id, + anonymous_id, + user_id, + + received_at as received_at_tstamp, + sent_at as sent_at_tstamp, + timestamp as tstamp, + + url as page_url, + split_part(split_part(split_part(url, '//', 2),'/', 1),'?',1)::varchar + as page_url_host, + path as page_url_path, + title as page_title, + search as page_url_query, + + referrer, + ltrim(split_part(split_part(referrer, '.com', 1), '//',2),'www.')::varchar + as referrer_host, + + context_campaign_source as utm_source, + context_campaign_medium as utm_medium, + context_campaign_name as utm_campaign, + context_campaign_term as utm_term, + context_campaign_content as utm_content, + nullif(split_part(split_part(url, 'gclid=', 2),'&', 1)::varchar,'') + as gclid, + + context_ip as ip, + context_user_agent as user_agent + + from source + +) + +select * from renamed {% endmacro %} diff --git a/macros/cross-adapter-modeling/sessionization/segment_web_page_views__sessionized.sql b/macros/cross-adapter-modeling/sessionization/segment_web_page_views__sessionized.sql index 668063e..3fc0ff0 100644 --- a/macros/cross-adapter-modeling/sessionization/segment_web_page_views__sessionized.sql +++ b/macros/cross-adapter-modeling/sessionization/segment_web_page_views__sessionized.sql @@ -70,8 +70,7 @@ lagged as ( lag(tstamp) over ( partition by anonymous_id - order by page_view_number - rows between unbounded preceding and unbounded following + order by page_view_number ) as previous_tstamp from numbered diff --git a/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql b/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql index 926ac08..b805729 100644 --- a/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql +++ b/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql @@ -29,7 +29,6 @@ 'utm_medium' : 'utm_medium', 'utm_campaign' : 'utm_campaign', 'utm_term' : 'utm_term', - 'mkw_id' : 'mkw_id', 'gclid' : 'gclid', 'page_url' : 'first_page_url', 'page_url_host' : 'first_page_url_host', @@ -88,8 +87,26 @@ diffs as ( from agg +), + +tiers as ( + + select + + *, + + case + when duration_in_s between 0 and 9 then '0s to 9s' + when duration_in_s between 10 and 29 then '10s to 29s' + when duration_in_s between 30 and 59 then '30s to 59s' + when duration_in_s > 59 then '60s or more' + else null + end as duration_in_s_tier + + from diffs + ) -select * from diffs +select * from tiers {% endmacro %} \ No newline at end of file