Skip to content

Commit

Permalink
Goals First: Prevent calypso_signup_start from firing multiple times (
Browse files Browse the repository at this point in the history
#98182)

* provide a memoized based that's not dependent on goals to prevent event from firing each time goals are selected

* stringify the goals

* use only the initial goal reference to trigger event

* add comment for clarity
  • Loading branch information
vykes-mac authored Jan 9, 2025
1 parent 4a1680e commit f898338
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions client/landing/stepper/declarative-flow/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OnboardSelect, Onboard, UserSelect } from '@automattic/data-stores';
import { ONBOARDING_FLOW, clearStepPersistedState } from '@automattic/onboarding';
import { useDispatch, useSelect } from '@wordpress/data';
import { addQueryArgs, getQueryArg, getQueryArgs, removeQueryArgs } from '@wordpress/url';
import { useState, useMemo, useEffect } from 'react';
import { useState, useMemo, useEffect, useRef } from 'react';
import { SIGNUP_DOMAIN_ORIGIN } from 'calypso/lib/analytics/signup';
import { pathToUrl } from 'calypso/lib/url';
import {
Expand Down Expand Up @@ -57,6 +57,9 @@ const onboarding: Flow = {
[]
);

// we are only interested in the initial goals value when the user enters the goals step
const initialGoals = useRef( goals );

return useMemo(
() => ( {
[ STEPPER_TRACKS_EVENT_SIGNUP_START ]: {
Expand All @@ -68,10 +71,12 @@ const onboarding: Flow = {
...( isGoalsAtFrontExperiment && {
is_goals_first: isGoalsAtFrontExperiment.toString(),
} ),
...( goals.length && { goals: goals.join( ',' ) } ),
...( initialGoals.current.length && {
goals: initialGoals.current.join( ',' ),
} ),
},
} ),
[ isGoalsAtFrontExperiment, userIsLoggedIn, goals ]
[ isGoalsAtFrontExperiment, userIsLoggedIn, initialGoals ]
);
},
useSteps() {
Expand Down

0 comments on commit f898338

Please sign in to comment.