Skip to content

Commit 594997b

Browse files
Aswathy/CRO-778/feat: Added the console error tracking for the virtual signup flow (deriv-com#17497)
* feat: added the console error tracking for the virtual signup flow * fix: removed the console errors * feat: added the console trackjs error for the user signup flow * fix: peer comments * fix: removed the localized error message * fix: removed the localize form analytics * fix: changed the naming of the feature f;ag variable * fix: added a condition inside the country selection screen for capturing multiple errors * fix: updated the ref with state of password model * fix: added the console * fix: added the feature condition inside trackconsole method * fix: changed the default value to true * fix: added the dependency for useeffect * fix: peer comments * fix: added the screen name for the signup button
1 parent ce9533d commit 594997b

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

packages/core/src/App/Containers/AccountSignupModal/account-signup-modal.jsx

+54-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Analytics } from '@deriv-com/analytics';
99

1010
import { WS } from 'Services';
1111
import { observer, useStore } from '@deriv/stores';
12-
12+
import { useGrowthbookGetFeatureValue } from '@deriv/hooks';
1313
import CitizenshipForm from '../CitizenshipModal/set-citizenship-form.jsx';
1414
import PasswordSelectionModal from '../PasswordSelectionModal/password-selection-modal.jsx';
1515
import QuestionnaireModal from '../QuestionnaireModal';
@@ -34,12 +34,19 @@ const AccountSignup = ({
3434
const history_value = React.useRef();
3535
const [pw_input, setPWInput] = React.useState('');
3636
const [is_password_modal, setIsPasswordModal] = React.useState(false);
37+
const isPasswordModalRef = React.useRef(false);
38+
const isCountryScreenLoggedOnceRef = React.useRef(false);
3739
const [is_disclaimer_accepted, setIsDisclaimerAccepted] = React.useState(false);
3840
const [is_questionnaire, setIsQuestionnaire] = React.useState(false);
3941
const [ab_questionnaire, setABQuestionnaire] = React.useState();
4042
const [modded_state, setModdedState] = React.useState({});
4143
const language = getLanguage();
4244

45+
const [is_tracking_signup_errors] = useGrowthbookGetFeatureValue({
46+
featureFlag: 'signup_flow_error',
47+
defaultValue: true,
48+
});
49+
4350
const checkResidenceIsBrazil = selected_country =>
4451
selected_country && residence_list[indexOfSelection(selected_country)]?.value?.toLowerCase() === 'br';
4552

@@ -113,6 +120,51 @@ const AccountSignup = ({
113120
setABQuestionnaire(fetchQuestionnarieData());
114121
}, []); // eslint-disable-line react-hooks/exhaustive-deps
115122

123+
const trackSignupErrorEvent = (action, errorMessage, screen_name) => {
124+
const form_name = is_mobile ? 'virtual_signup_web_mobile_default' : 'virtual_signup_web_desktop_default';
125+
cacheTrackEvents.loadEvent([
126+
{
127+
event: {
128+
name: 'ce_virtual_signup_form',
129+
properties: {
130+
action,
131+
form_name,
132+
error_message: errorMessage,
133+
screen_name,
134+
},
135+
},
136+
},
137+
]);
138+
};
139+
140+
React.useEffect(() => {
141+
isPasswordModalRef.current = is_password_modal; // Sync ref with state
142+
}, [is_password_modal]);
143+
144+
React.useEffect(() => {
145+
cacheTrackEvents.trackConsoleErrors(errorMessage => {
146+
if (is_tracking_signup_errors) {
147+
if (errorMessage) {
148+
const screen_name = !isPasswordModalRef.current
149+
? 'country_selection_screen'
150+
: 'password_screen_opened';
151+
152+
if (screen_name === 'country_selection_screen') {
153+
if (
154+
!isCountryScreenLoggedOnceRef.current ||
155+
isCountryScreenLoggedOnceRef.current !== errorMessage
156+
) {
157+
trackSignupErrorEvent('signup_flow_error', errorMessage, screen_name);
158+
isCountryScreenLoggedOnceRef.current = errorMessage;
159+
}
160+
} else if (screen_name === 'password_screen_opened') {
161+
trackSignupErrorEvent('signup_flow_error', errorMessage, screen_name);
162+
}
163+
}
164+
}
165+
});
166+
}, [is_tracking_signup_errors]);
167+
116168
const validateSignupPassthrough = values => validateSignupFields(values, residence_list);
117169

118170
const indexOfSelection = selected_country =>
@@ -145,6 +197,7 @@ const AccountSignup = ({
145197
action: 'signup_flow_error',
146198
form_name: is_mobile ? 'virtual_signup_web_mobile_default' : 'virtual_signup_web_desktop_default',
147199
error_message: error,
200+
screen_name: 'password_screen_opened',
148201
});
149202
} else {
150203
setIsFromSignupAccount(true);

packages/core/src/Utils/Analytics/analytics.ts

+24
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,29 @@ const cacheTrackEvents = {
162162
});
163163
return cacheTrackEvents;
164164
},
165+
trackConsoleErrors: (callback?: (errorMessage: string) => void): void => {
166+
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
167+
const originalConsoleError = console.error;
168+
169+
console.error = function (...args: unknown[]): void {
170+
// Log the error to the console as usual
171+
originalConsoleError.apply(console, args);
172+
173+
// Create a clean error message without __trackjs_state__
174+
const errorMessage = args
175+
.map(arg =>
176+
arg && typeof arg === 'object' && 'message' in arg
177+
? (arg as Error).message
178+
: typeof arg === 'object'
179+
? JSON.stringify(arg, (key, value) => (key.startsWith('__trackjs') ? undefined : value))
180+
: String(arg)
181+
)
182+
.join(' ');
183+
184+
if (typeof callback === 'function') {
185+
callback(errorMessage);
186+
}
187+
};
188+
},
165189
};
166190
export default cacheTrackEvents;

0 commit comments

Comments
 (0)