Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add funnel complete event #1421

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/internal/analytics/components/analytics-funnel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useVisualRefresh } from '../../hooks/use-visual-mode';
import { PACKAGE_VERSION } from '../../environment';

import { FunnelMetrics } from '../';
import { FunnelProps, FunnelStepProps } from '../interfaces';
import { BaseFunnelProps, FunnelProps, FunnelStepProps } from '../interfaces';

import {
DATA_ATTR_FUNNEL_STEP,
Expand All @@ -44,6 +44,11 @@ export const AnalyticsFunnel = ({ children, ...props }: AnalyticsFunnelProps) =>
const errorCount = useRef<number>(0);
const loadingButtonCount = useRef<number>(0);
const latestFocusCleanupFunction = useRef<undefined | (() => void)>(undefined);
const funnelComplete = (props: BaseFunnelProps) => {
FunnelMetrics.funnelComplete(props);
const event = new Event('funnelComplete');
document.dispatchEvent(event);
};

// This useEffect hook is run once on component mount to initiate the funnel analytics.
// It first calls the 'funnelStart' method from FunnelMetrics, providing all necessary details
Expand Down Expand Up @@ -78,7 +83,7 @@ export const AnalyticsFunnel = ({ children, ...props }: AnalyticsFunnelProps) =>
return () => {
if (funnelState.current === 'validating') {
// Finish the validation phase early.
FunnelMetrics.funnelComplete({ funnelInteractionId });
funnelComplete({ funnelInteractionId });
funnelState.current = 'complete';
}

Expand Down Expand Up @@ -121,7 +126,7 @@ export const AnalyticsFunnel = ({ children, ...props }: AnalyticsFunnelProps) =>
/*
If no validation errors are rendered, we treat the funnel as complete.
*/
FunnelMetrics.funnelComplete({ funnelInteractionId });
funnelComplete({ funnelInteractionId });
funnelState.current = 'complete';
} else {
funnelState.current = 'default';
Expand Down
Loading