From c6cac444598fb1f1aa32847e86fec7a05607ff9e Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 19 Nov 2024 15:29:34 +0000 Subject: [PATCH] add changes --- .../components/shared/Preview/SaveResumeButton.tsx | 2 +- .../src/pages/FlowEditor/lib/analytics/mutations.ts | 4 ++-- .../src/pages/FlowEditor/lib/analytics/provider.tsx | 12 ++++++------ .../src/pages/FlowEditor/lib/analytics/types.ts | 9 ++++++--- .../up.sql | 4 ++-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/shared/Preview/SaveResumeButton.tsx b/editor.planx.uk/src/@planx/components/shared/Preview/SaveResumeButton.tsx index 840a7666e8..4dc35d8c4e 100644 --- a/editor.planx.uk/src/@planx/components/shared/Preview/SaveResumeButton.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Preview/SaveResumeButton.tsx @@ -21,7 +21,7 @@ const SaveResumeButton: React.FC = () => { const handleClick = () => { if (saveToEmail) { - trackEvent({ event: "saveClick", metadata: {} }); + trackEvent({ event: "saveClick" }); trackEvent({ event: "flowDirectionChange", metadata: null, diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/mutations.ts b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/mutations.ts index 8f6f3178d3..22eb5a966f 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/mutations.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/mutations.ts @@ -52,11 +52,11 @@ export const UPDATE_HAS_CLICKED_HELP = gql` } `; -export const UPDATE_HAS_USER_CLICKED_SAVE = gql` +export const UPDATE_HAS_CLICKED_SAVE = gql` mutation UpdateHasClickedSave($id: bigint!, $metadata: jsonb = {}) { update_analytics_logs_by_pk( pk_columns: { id: $id } - _set: { has_user_clicked_save: true } + _set: { has_clicked_save: true } _append: { metadata: $metadata } ) { id diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/provider.tsx b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/provider.tsx index e193e2b769..f2e875ff0e 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/provider.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/provider.tsx @@ -14,7 +14,7 @@ import { UPDATE_ANALYTICS_LOG_METADATA, UPDATE_FLOW_DIRECTION, UPDATE_HAS_CLICKED_HELP, - UPDATE_HAS_USER_CLICKED_SAVE, + UPDATE_HAS_CLICKED_SAVE, UPDATE_NEXT_LOG_CREATED_AT, } from "./mutations"; import { @@ -254,7 +254,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({ return !shouldTrackAnalytics || !lastVisibleNodeAnalyticsLogId; } - async function updateMetadata(mutation: DocumentNode, metadata: Metadata) { + async function updateMetadata(mutation: DocumentNode, metadata?: Metadata) { await publicClient.mutate({ mutation: mutation, variables: { @@ -266,17 +266,17 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({ async function trackEvent(eventData: EventData) { if (shouldSkipTracking()) return; - const { event, metadata } = eventData; + const { event } = eventData; switch (event) { case "helpClick": - updateMetadata(UPDATE_HAS_CLICKED_HELP, metadata); + updateMetadata(UPDATE_HAS_CLICKED_HELP, eventData.metadata); return; case "saveClick": - updateMetadata(UPDATE_HAS_USER_CLICKED_SAVE, metadata); + updateMetadata(UPDATE_HAS_CLICKED_SAVE); return; case "nextStepsClick": case "helpTextFeedback": - updateMetadata(UPDATE_ANALYTICS_LOG_METADATA, metadata); + updateMetadata(UPDATE_ANALYTICS_LOG_METADATA, eventData.metadata); return; case "backwardsNavigation": { const { initiator, nodeId } = eventData; diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/types.ts b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/types.ts index bd9a435443..9d6e3c9b5a 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/analytics/types.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/analytics/types.ts @@ -32,8 +32,6 @@ export type AllowListKey = (typeof ALLOW_LIST)[number]; */ export type HelpClickMetadata = Record; -export type SaveClickMetadata = Record; - export type SelectedUrlsMetadata = Record<"selectedUrls", string[]>; export type BackwardsNavigationInitiatorType = "change" | "back"; @@ -111,9 +109,14 @@ type HelpClick = { metadata: HelpClickMetadata; }; +/** + * Captured when a user clicks Save and Return. + * The mutation sets the "has_clicked_help: true" when Save and + * Return button is clicked + */ + type SaveClick = { event: "saveClick"; - metadata: SaveClickMetadata; }; /** diff --git a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql index 8b08cca965..e03de6c548 100644 --- a/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql +++ b/hasura.planx.uk/migrations/1732016907414_alter_table_public_analytics_logs_add_column_has_user_clicked_save/up.sql @@ -1,4 +1,4 @@ -alter table "public"."analytics_logs" add column "has_user_clicked_save" boolean +alter table "public"."analytics_logs" add column "has_clicked_save" boolean null default 'false'; CREATE OR REPLACE VIEW "public"."analytics_summary" AS @@ -52,7 +52,7 @@ CREATE OR REPLACE VIEW "public"."analytics_summary" AS ((al.allow_list_answers -> 'application.information.harmful'::text))::text AS pre_app_harmful_info, ((al.allow_list_answers -> 'application.information.sensitive'::text))::text AS pre_app_sensitive_info, (((al.allow_list_answers -> 'application.type'::text) -> 0))::text AS application_type, - al.has_user_clicked_save + al.has_clicked_save FROM (((analytics a LEFT JOIN analytics_logs al ON ((a.id = al.analytics_id))) LEFT JOIN flows f ON ((a.flow_id = f.id)))