Skip to content

Commit

Permalink
add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 19, 2024
1 parent 9e22abe commit c6cac44
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SaveResumeButton: React.FC = () => {

const handleClick = () => {
if (saveToEmail) {
trackEvent({ event: "saveClick", metadata: {} });
trackEvent({ event: "saveClick" });
trackEvent({
event: "flowDirectionChange",
metadata: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions editor.planx.uk/src/pages/FlowEditor/lib/analytics/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions editor.planx.uk/src/pages/FlowEditor/lib/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export type AllowListKey = (typeof ALLOW_LIST)[number];
*/
export type HelpClickMetadata = Record<string, string>;

export type SaveClickMetadata = Record<string, string>;

export type SelectedUrlsMetadata = Record<"selectedUrls", string[]>;

export type BackwardsNavigationInitiatorType = "change" | "back";
Expand Down Expand Up @@ -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;
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit c6cac44

Please sign in to comment.