From 83dde0ebd305f6a477fea4bea185da2aec753b1f Mon Sep 17 00:00:00 2001 From: Erin Ogilvy Date: Tue, 23 Oct 2018 17:24:01 -0400 Subject: [PATCH 1/5] adding macro for redshift --- .../base/segment_web_page_views.sql | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) 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..2031a67 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,50 @@ {% 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, + ltrim(split_part(split_part(url, '.com', 1), '//',2),'www.')::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(url, 'gclid=', 2)::varchar,'') as gclid, + + context_ip as ip, + context_user_agent as user_agent + + from source + +) + +select * from renamed {% endmacro %} From f5ede5e2f0e44edbd70c001e4d395545703a427c Mon Sep 17 00:00:00 2001 From: Erin Ogilvy Date: Wed, 24 Oct 2018 15:33:42 -0400 Subject: [PATCH 2/5] small alterations to get successful run --- .../sessionization/segment_web_page_views__sessionized.sql | 3 +-- .../sessionization/segment_web_sessions__initial.sql | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) 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..04db40d 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', From 7c105be35e4bbc154d5eef6e64e453503b10b0cd Mon Sep 17 00:00:00 2001 From: Erin Ogilvy Date: Thu, 25 Oct 2018 10:28:58 -0400 Subject: [PATCH 3/5] updating split_parts --- .../cross-adapter-modeling/base/segment_web_page_views.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 2031a67..85dafcc 100644 --- a/macros/cross-adapter-modeling/base/segment_web_page_views.sql +++ b/macros/cross-adapter-modeling/base/segment_web_page_views.sql @@ -26,7 +26,7 @@ renamed as ( timestamp as tstamp, url as page_url, - ltrim(split_part(split_part(url, '.com', 1), '//',2),'www.')::varchar + split_part(split_part(url, '//', 2),'/', 1)::varchar as page_url_host, path as page_url_path, title as page_title, @@ -41,7 +41,8 @@ renamed as ( context_campaign_name as utm_campaign, context_campaign_term as utm_term, context_campaign_content as utm_content, - nullif(split_part(url, 'gclid=', 2)::varchar,'') as gclid, + nullif(split_part(split_part(url, 'gclid=', 2),'&', 1)::varchar,'') + as gclid, context_ip as ip, context_user_agent as user_agent From cf4188bcd00528ce013a225d6008e2921b5ee799 Mon Sep 17 00:00:00 2001 From: Erin Ogilvy Date: Thu, 25 Oct 2018 12:36:49 -0400 Subject: [PATCH 4/5] adding duration_in_s_tier --- .../segment_web_sessions__initial.sql | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 04db40d..b805729 100644 --- a/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql +++ b/macros/cross-adapter-modeling/sessionization/segment_web_sessions__initial.sql @@ -87,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 From c56f4f50591ce31f58a2c877d4d794a22fad93c3 Mon Sep 17 00:00:00 2001 From: Erin Ogilvy Date: Fri, 26 Oct 2018 10:40:03 -0400 Subject: [PATCH 5/5] expanding split url --- macros/cross-adapter-modeling/base/segment_web_page_views.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85dafcc..3b74f18 100644 --- a/macros/cross-adapter-modeling/base/segment_web_page_views.sql +++ b/macros/cross-adapter-modeling/base/segment_web_page_views.sql @@ -26,7 +26,7 @@ renamed as ( timestamp as tstamp, url as page_url, - split_part(split_part(url, '//', 2),'/', 1)::varchar + split_part(split_part(split_part(url, '//', 2),'/', 1),'?',1)::varchar as page_url_host, path as page_url_path, title as page_title,