diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index 15aa383b6c..0975212613 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -64,6 +64,9 @@ - user_exit filter: {} check: null +- table: + schema: public + name: analytics_summary - table: schema: public name: blpu_codes diff --git a/hasura.planx.uk/migrations/1700308790539_alter_table_public_analytics_logs_add_column_input_errors/down.sql b/hasura.planx.uk/migrations/1700303790539_alter_table_public_analytics_logs_add_column_input_errors/down.sql similarity index 100% rename from hasura.planx.uk/migrations/1700308790539_alter_table_public_analytics_logs_add_column_input_errors/down.sql rename to hasura.planx.uk/migrations/1700303790539_alter_table_public_analytics_logs_add_column_input_errors/down.sql diff --git a/hasura.planx.uk/migrations/1700308790539_alter_table_public_analytics_logs_add_column_input_errors/up.sql b/hasura.planx.uk/migrations/1700303790539_alter_table_public_analytics_logs_add_column_input_errors/up.sql similarity index 100% rename from hasura.planx.uk/migrations/1700308790539_alter_table_public_analytics_logs_add_column_input_errors/up.sql rename to hasura.planx.uk/migrations/1700303790539_alter_table_public_analytics_logs_add_column_input_errors/up.sql diff --git a/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/down.sql b/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/down.sql new file mode 100644 index 0000000000..2960f20a82 --- /dev/null +++ b/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/down.sql @@ -0,0 +1 @@ +DROP VIEW public.analytics_summary; diff --git a/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/up.sql b/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/up.sql new file mode 100644 index 0000000000..693d10937b --- /dev/null +++ b/hasura.planx.uk/migrations/1700303840464_setup_analytics_summary_view/up.sql @@ -0,0 +1,22 @@ +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;