Skip to content

Commit

Permalink
feat: add & populate column analytics_logs.node_id (#2576)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Dec 18, 2023
1 parent fc08523 commit 507dd50
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,15 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
node?.type === TYPES.Content
? getContentTitle(node)
: node?.data?.title ?? node?.data?.text ?? node?.data?.flagSet;
const nodeId = node?.id || null;

// On component transition create the new analytics log
const result = await insertNewAnalyticsLog(
direction,
analyticsId,
metadata,
nodeTitle,
nodeId,
);
const id = result?.data.insert_analytics_logs_one?.id;
const newLogCreatedAt = result?.data.insert_analytics_logs_one?.created_at;
Expand All @@ -179,6 +182,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
analyticsId: number,
metadata: NodeMetadata,
nodeTitle: string,
nodeId: string | null,
) {
const result = await publicClient.mutate({
mutation: gql`
Expand All @@ -188,7 +192,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
$metadata: jsonb
$node_type: Int
$node_title: String
$user_agent: jsonb
$node_id: String
) {
insert_analytics_logs_one(
object: {
Expand All @@ -198,6 +202,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
metadata: $metadata
node_type: $node_type
node_title: $node_title
node_id: $node_id
}
) {
id
Expand All @@ -211,6 +216,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
metadata: metadata,
node_type: node?.type,
node_title: nodeTitle,
node_id: nodeId,
},
});
return result;
Expand Down
1 change: 1 addition & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- id
- input_errors
- metadata
- node_id
- node_title
- node_type
- user_exit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."analytics_logs" drop column "node_id";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."analytics_logs" add column "node_id" text null;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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,
node_id
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;

0 comments on commit 507dd50

Please sign in to comment.