Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Heneghan committed Oct 4, 2023
1 parent 65f2218 commit 6198662
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions editor.planx.uk/src/@planx/components/NextSteps/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { NextSteps } from "./model";

export type Props = PublicProps<NextSteps>;

// How does the new trackNextStepsClick get tied into this component?

const NextStepsComponent: React.FC<Props> = (props) => {
return (
<Card>
Expand Down
22 changes: 22 additions & 0 deletions editor.planx.uk/src/pages/FlowEditor/lib/analyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export type AnalyticsType = "init" | "resume";
type AnalyticsLogDirection = AnalyticsType | "forwards" | "backwards";

export type HelpClickMetadata = Record<string, string>;
export type NextStepsMetadata = Record<string, string>


let lastAnalyticsLogId: number | undefined = undefined;

const analyticsContext = createContext<{
createAnalytics: (type: AnalyticsType) => Promise<void>;
trackHelpClick: (metadata?: HelpClickMetadata) => Promise<void>;
trackNextStepsClick: (metadata?: NextStepsMetadata) => Promise<void>;
node: Store.node | null;
}>({
createAnalytics: () => Promise.resolve(),
trackHelpClick: () => Promise.resolve(),
trackNextStepsClick: () => Promise.resolve(),
node: null,
});
const { Provider } = analyticsContext;
Expand Down Expand Up @@ -100,6 +104,7 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
value={{
createAnalytics,
trackHelpClick,
trackNextStepsClick,
node,
}}
>
Expand Down Expand Up @@ -171,6 +176,23 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
}
}

// Add a function to the provider which should capture when a next step is clicked?
// Ideally the metadata gathered should be the click but also the target of the URl?
// If they're clicking a new link will we need to use BeaconAPI to ensure we capture the data?
async function trackNextStepsClick(metadata? : NextStepsMetadata) {
if (shouldTrackAnalytics && lastAnalyticsLogId) {
await publicClient.mutate({
mutation: gql`
// The mutation generated via Hasura?
`,
variables: {
id: lastAnalyticsLogId,
metadata,
}
})
}
}

async function createAnalytics(type: AnalyticsType) {
if (shouldTrackAnalytics) {
const response = await publicClient.mutate({
Expand Down

0 comments on commit 6198662

Please sign in to comment.