From e787e0eb68d4dba52660dd2c2ca8ecf839c31b16 Mon Sep 17 00:00:00 2001 From: Mike <36415632+Mike-Heneghan@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:59:56 +0000 Subject: [PATCH] feature: add analytics session lenght data to view (#2550) - Found that it wasn't possible to replicate the ["Average time spent"](https://metabase.editor.planx.uk/question/15-average-time-spent?flow_id=0e9d79ec-9cf3-497d-a1a1-8e70469bb52d) card without analytics session length data - Add analytics.ended_at to the view - Add time_spent_on_analytics_session_in_minutes to the view --- .../down.sql | 24 +++++++++++++++++++ .../up.sql | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/down.sql create mode 100644 hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/up.sql diff --git a/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/down.sql b/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/down.sql new file mode 100644 index 0000000000..f15af04ae4 --- /dev/null +++ b/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/down.sql @@ -0,0 +1,24 @@ +DROP VIEW public.analytics_summary CASCADE; + +CREATE OR REPLACE VIEW public.analytics_summary AS +select + a.id as analytics_id, + al.id as analytics_log_id, + f.slug as service_slug, + t.slug as team_slug, + a.type as analytics_type, + a.created_at as analytics_created_at, + user_agent, + referrer, + flow_direction, + metadata, + al.user_exit as is_user_exit, + node_type, + node_title, + has_clicked_help, + input_errors, + CAST(EXTRACT(EPOCH FROM (al.next_log_created_at - al.created_at)) as numeric (10, 1)) as time_spent_on_node_seconds +from analytics a + left join analytics_logs al on a.id = al.analytics_id + left join flows f on a.flow_id = f.id + left join teams t on t.id = f.team_id; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/up.sql b/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/up.sql new file mode 100644 index 0000000000..e9e4ee87d8 --- /dev/null +++ b/hasura.planx.uk/migrations/1702312905340_alter_view_analytics_summary_add_analytics_session_length_data/up.sql @@ -0,0 +1,24 @@ +CREATE OR REPLACE VIEW public.analytics_summary AS +select + a.id as analytics_id, + al.id as analytics_log_id, + f.slug as service_slug, + t.slug as team_slug, + a.type as analytics_type, + a.created_at as analytics_created_at, + user_agent, + referrer, + flow_direction, + metadata, + al.user_exit as is_user_exit, + node_type, + node_title, + has_clicked_help, + input_errors, + CAST(EXTRACT(EPOCH FROM (al.next_log_created_at - al.created_at)) as numeric (10, 1)) as time_spent_on_node_seconds, + a.ended_at as analytics_ended_at, + CAST(EXTRACT(EPOCH FROM (a.ended_at - a.created_at))/60 as numeric (10, 1)) as time_spent_on_analytics_session_minutes +from analytics a + left join analytics_logs al on a.id = al.analytics_id + left join flows f on a.flow_id = f.id + left join teams t on t.id = f.team_id; \ No newline at end of file