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

feat: segment migration update remaining files and remove legacy analytics #8748

Merged
merged 4 commits into from
Feb 28, 2024
Merged
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
8 changes: 3 additions & 5 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import branch from 'react-native-branch';
import AppConstants from '../../../core/AppConstants';
import Logger from '../../../util/Logger';
import { routingInstrumentation } from '../../../util/sentry/utils';
import Analytics from '../../../core/Analytics/Analytics';
import { connect, useDispatch } from 'react-redux';
import {
CURRENT_APP_VERSION,
Expand Down Expand Up @@ -370,13 +369,12 @@ const App = ({ userLoggedIn }) => {
}, [dispatch, handleDeeplink, navigator, queueOfHandleDeeplinkFunctions]);

useEffect(() => {
const initAnalytics = async () => {
const initMetrics = async () => {
await MetaMetrics.getInstance().configure();
await Analytics.init();
};

initAnalytics().catch((err) => {
Logger.error(err, 'Error initializing analytics');
initMetrics().catch((err) => {
Logger.error(err, 'Error initializing MetaMetrics');
});
}, []);

Expand Down
5 changes: 4 additions & 1 deletion app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@ export function getTransactionsNavbarOptions(
*
* @param {string} title - Title in string format
* @param {Object} navigation - Navigation object required to push new views
* @param isFullScreenModal
* @param themeColors
* @param {IMetaMetricsEvent} navigationPopEvent
* @returns {Object} - Corresponding navbar options containing title and headerTitleStyle
*/
export function getNavigationOptionsTitle(
title,
navigation,
isFullScreenModal,
themeColors,
navigationPopEvent = undefined,
navigationPopEvent = null,
) {
const innerStyles = StyleSheet.create({
headerStyle: {
Expand Down
7 changes: 4 additions & 3 deletions app/components/UI/OptinMetrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import { connect } from 'react-redux';
import { clearOnboardingEvents } from '../../../actions/onboarding';
import { ONBOARDING_WIZARD } from '../../../constants/storage';
import AppConstants from '../../../core/AppConstants';
import { Analytics, MetaMetricsEvents } from '../../../core/Analytics';
import { withMetricsAwareness } from '../../hooks/useMetrics';
import {
MetaMetricsEvents,
withMetricsAwareness,
} from '../../hooks/useMetrics';

import DefaultPreference from 'react-native-default-preference';
import { ThemeContext } from '../../../util/theme';
Expand Down Expand Up @@ -272,7 +274,6 @@ class OptinMetrics extends PureComponent {
// and disable analytics
clearOnboardingEvents();
await metrics.enable(false);
Analytics.disableInstance();
}, 200);
this.continue();
};
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/Quiz/SRPQuiz/SRPQuiz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const SRPQuiz = () => {
);

const goToRevealPrivateCredential = useCallback((): void => {
trackEvent(MetaMetricsEvents.REVEAL_SRP_INITIATED, {});
trackEvent(MetaMetricsEvents.REVEAL_SRP_CTA, {});
trackEvent(MetaMetricsEvents.REVEAL_SRP_INITIATED);
trackEvent(MetaMetricsEvents.REVEAL_SRP_CTA);
navigation.navigate(Routes.SETTINGS.REVEAL_PRIVATE_CREDENTIAL, {
credentialName: 'seed_phrase',
shouldUpdateNav: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import Button, {
ButtonWidthTypes,
} from '../../../../../component-library/components/Buttons/Button';
import AppConstants from '../../../../../core/AppConstants';
import { trackEventV2 as trackEvent } from '../../../../../util/analyticsV2';
import { MetaMetricsEvents } from '../../../../../core/Analytics';
import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics';
import generateTestId from '../../../../../../wdio/utils/generateTestId';
import {
TOGGLE_ETH_SIGN_CONTINUE_BUTTON,
Expand All @@ -47,6 +46,7 @@ import createStyles from './EthSignFriction.styles';
* - The second step is to ask the user to type a specific text to confirm that they understand the risk and allow them to enable eth_sign.
*/
const EthSignFriction = () => {
const { trackEvent } = useMetrics();
const { colors, themeAppearance } = useTheme();
const styles = createStyles(colors);
const sheetRef = useRef<BottomSheetRef>(null);
Expand All @@ -68,7 +68,7 @@ const EthSignFriction = () => {
{},
);
}
}, [firstFrictionPassed]);
}, [firstFrictionPassed, trackEvent]);

// friction element status checks.
const isApproveTextMatched = (text: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Logger from '../../../../util/Logger';
import { getNavigationOptionsTitle } from '../../../UI/Navbar';
import { setLockTime } from '../../../../actions/settings';
import { strings } from '../../../../../locales/i18n';
import Analytics from '../../../../core/Analytics/Analytics';
import { passwordSet } from '../../../../actions/user';
import Engine from '../../../../core/Engine';
import AppConstants from '../../../../core/AppConstants';
Expand Down Expand Up @@ -119,8 +118,8 @@ import Button, {
ButtonSize,
ButtonWidthTypes,
} from '../../../../component-library/components/Buttons/Button';
import { trackErrorAsAnalytics } from '../../../../util/analyticsV2';
import { isBlockaidFeatureEnabled } from '../../../../util/blockaid';
import trackErrorAsAnalytics from '../../../../util/metrics/TrackError/trackErrorAsAnalytics';

const Heading: React.FC<HeadingProps> = ({ children, first }) => {
const { colors } = useTheme();
Expand Down Expand Up @@ -450,8 +449,6 @@ const Settings: React.FC = () => {

const toggleMetricsOptIn = async (metricsEnabled: boolean) => {
if (metricsEnabled) {
Analytics.enable();

const consolidatedTraits = {
...generateDeviceAnalyticsMetaData(),
...generateUserSettingsAnalyticsMetaData(),
Expand All @@ -460,21 +457,14 @@ const Settings: React.FC = () => {
setAnalyticsEnabled(true);

InteractionManager.runAfterInteractions(async () => {
// Segment metrics optin tracking
await addTraitsToUser(consolidatedTraits);
trackEvent(MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED, {
analytics_option_selected: 'Metrics Opt in',
updated_after_onboarding: true,
});
// Legacy metrics optin tracking
trackEvent(MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED, {
analytics_option_selected: 'Metrics Opt in',
updated_after_onboarding: true,
});
});
} else {
await enable(false);
Analytics.disable();
setAnalyticsEnabled(false);
Alert.alert(
strings('app_settings.metametrics_opt_out'),
Expand Down
Loading
Loading