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

Aswathy/CRO-778/feat: Added the console error tracking for the virtual signup flow #17497

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Analytics } from '@deriv-com/analytics';

import { WS } from 'Services';
import { observer, useStore } from '@deriv/stores';

import { useGrowthbookGetFeatureValue } from '@deriv/hooks';
import CitizenshipForm from '../CitizenshipModal/set-citizenship-form.jsx';
import PasswordSelectionModal from '../PasswordSelectionModal/password-selection-modal.jsx';
import QuestionnaireModal from '../QuestionnaireModal';
Expand All @@ -34,12 +34,18 @@ const AccountSignup = ({
const history_value = React.useRef();
const [pw_input, setPWInput] = React.useState('');
const [is_password_modal, setIsPasswordModal] = React.useState(false);
const isCountryScreenLoggedOnceRef = React.useRef(false);
const [is_disclaimer_accepted, setIsDisclaimerAccepted] = React.useState(false);
const [is_questionnaire, setIsQuestionnaire] = React.useState(false);
const [ab_questionnaire, setABQuestionnaire] = React.useState();
const [modded_state, setModdedState] = React.useState({});
const language = getLanguage();

const [is_signup_flow_error] = useGrowthbookGetFeatureValue({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the expected behaviour of this feature flag?
I dont understand it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is also vague.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's like enable_signup_error_tracking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its like should we enable the signup_flow_error feature flag or not

featureFlag: 'signup_flow_error',
defaultValue: false,
});

const checkResidenceIsBrazil = selected_country =>
selected_country && residence_list[indexOfSelection(selected_country)]?.value?.toLowerCase() === 'br';

Expand Down Expand Up @@ -113,6 +119,42 @@ const AccountSignup = ({
setABQuestionnaire(fetchQuestionnarieData());
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const trackSignupErrorEvent = (action, errorMessage, screen_name) => {
const form_name = is_mobile ? 'virtual_signup_web_mobile_default' : 'virtual_signup_web_desktop_default';
cacheTrackEvents.loadEvent([
{
event: {
name: 'ce_virtual_signup_form',
properties: {
action,
form_name,
error_message: localize(errorMessage),
screen_name,
},
},
cache: true,
},
]);
};

React.useEffect(() => {
if (is_signup_flow_error) {
cacheTrackEvents.trackConsoleErrors(errorMessage => {
if (errorMessage) {
const screen_name = !is_password_modal ? 'country_selection_screen' : 'password_screen_opened';
// Check and set the logging state using the ref
if (screen_name === 'country_selection_screen' && !isCountryScreenLoggedOnceRef.current) {
trackSignupErrorEvent('signup_flow_error', errorMessage, screen_name);
// Update both the ref and state
isCountryScreenLoggedOnceRef.current = true;
} else if (screen_name === 'password_screen_opened') {
trackSignupErrorEvent('signup_flow_error', errorMessage, screen_name);
}
}
});
}
}, [is_password_modal]);

const validateSignupPassthrough = values => validateSignupFields(values, residence_list);

const indexOfSelection = selected_country =>
Expand Down Expand Up @@ -144,7 +186,7 @@ const AccountSignup = ({
Analytics.trackEvent('ce_virtual_signup_form', {
action: 'signup_flow_error',
form_name: is_mobile ? 'virtual_signup_web_mobile_default' : 'virtual_signup_web_desktop_default',
error_message: error,
error_message: localize(error),
});
} else {
setIsFromSignupAccount(true);
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/Utils/Analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,29 @@ const cacheTrackEvents = {
});
return cacheTrackEvents;
},
trackConsoleErrors: (callback?: (errorMessage: string) => void): void => {
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
const originalConsoleError = console.error;

console.error = function (...args: unknown[]): void {
// Log the error to the console as usual
originalConsoleError.apply(console, args);

// Create a clean error message without __trackjs_state__
const errorMessage = args
.map(arg =>
arg && typeof arg === 'object' && 'message' in arg
? (arg as Error).message
: typeof arg === 'object'
? JSON.stringify(arg, (key, value) => (key.startsWith('__trackjs') ? undefined : value))
: String(arg)
)
.join(' ');

if (typeof callback === 'function') {
callback(errorMessage);
}
};
},
};
export default cacheTrackEvents;
Loading