Skip to content

Commit

Permalink
Merge pull request #2 from fishtown-analytics/feature/redshift
Browse files Browse the repository at this point in the history
Feature/redshift
  • Loading branch information
eogilvy12 authored Oct 26, 2018
2 parents e384ffd + c56f4f5 commit 9304fd6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
46 changes: 45 additions & 1 deletion macros/cross-adapter-modeling/base/segment_web_page_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 %}

0 comments on commit 9304fd6

Please sign in to comment.