Skip to content

Commit

Permalink
chore: Lazy evaluate funnel name selectors (#3137)
Browse files Browse the repository at this point in the history
Co-authored-by: Boris Serdiuk <[email protected]>
  • Loading branch information
michaeldowseza and just-boris authored Dec 20, 2024
1 parent c461af5 commit d0ecb9a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function Form({ variant = 'full-page', ...props }: FormProps) {
funnelType="single-page"
optionalStepNumbers={[]}
totalFunnelSteps={1}
funnelNameSelectors={[funnelNameSelector, `.${analyticsSelectors.header}`]}
funnelNameSelectors={() => [funnelNameSelector, `.${analyticsSelectors.header}`]}
>
<AnalyticsFunnelStep
stepIdentifier={analyticsMetadata?.instanceIdentifier}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/analytics/components/analytics-funnel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface AnalyticsFunnelProps {
mounted?: boolean;
children?: React.ReactNode;
stepConfiguration?: StepConfiguration[];
funnelNameSelectors?: string[];
funnelNameSelectors?: () => string[];
funnelType: FunnelStartProps['funnelType'];
optionalStepNumbers: FunnelStartProps['optionalStepNumbers'];
totalFunnelSteps: FunnelStartProps['totalFunnelSteps'];
Expand Down Expand Up @@ -139,7 +139,7 @@ const InnerAnalyticsFunnel = ({ mounted = true, children, stepConfiguration, ...
*/
let funnelInteractionId: string;
const handle = setTimeout(() => {
funnelNameSelector.current = evaluateSelectors(props.funnelNameSelectors || [], getFunnelNameSelector());
funnelNameSelector.current = evaluateSelectors(props.funnelNameSelectors?.() || [], getFunnelNameSelector());
if (props.funnelType === 'single-page' && wizardCount.current > 0) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function ModalWithAnalyticsFunnel({
funnelType="modal"
optionalStepNumbers={[]}
totalFunnelSteps={1}
funnelNameSelectors={[`[${DATA_ATTR_MODAL_ID}="${window?.CSS?.escape(modalId)}"] .${styles['header--text']}`]}
funnelNameSelectors={() => [
`[${DATA_ATTR_MODAL_ID}="${window?.CSS?.escape(modalId)}"] .${styles['header--text']}`,
]}
>
<AnalyticsFunnelStep
mounted={props.visible}
Expand Down

0 comments on commit d0ecb9a

Please sign in to comment.