Skip to content
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
30 changes: 30 additions & 0 deletions app/components/UI/OptinMetrics/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ describe('OptinMetrics', () => {
await waitFor(() => {
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
location: 'onboarding_metametrics',
updated_after_onboarding: false,
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: 'Analytics Preference Selected',
properties: expect.objectContaining({
Expand Down Expand Up @@ -177,6 +187,16 @@ describe('OptinMetrics', () => {
await waitFor(() => {
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
location: 'onboarding_metametrics',
updated_after_onboarding: false,
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: 'Analytics Preference Selected',
properties: expect.objectContaining({
Expand Down Expand Up @@ -212,6 +232,16 @@ describe('OptinMetrics', () => {
);

await waitFor(() => {
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
location: 'onboarding_metametrics',
updated_after_onboarding: false,
account_type: AccountType.Imported,
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
name: 'Analytics Preference Selected',
Expand Down
28 changes: 15 additions & 13 deletions app/components/UI/OptinMetrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,21 @@ const OptinMetrics = () => {

dispatch(setDataCollectionForMarketing(isMarketingChecked));

// Track opt-out event if user opted out of metrics
if (!isBasicUsageChecked) {
metrics.trackEvent(
metrics
.createEventBuilder(MetaMetricsEvents.METRICS_OPT_OUT)
.addProperties({
updated_after_onboarding: false,
location: 'onboarding_metametrics',
...(accountType && { account_type: accountType }),
})
.build(),
);
}
// Track opt-in / opt-out for metrics
metrics.trackEvent(
metrics
.createEventBuilder(
isBasicUsageChecked
? MetaMetricsEvents.METRICS_OPT_IN
: MetaMetricsEvents.METRICS_OPT_OUT,
)
.addProperties({
updated_after_onboarding: false,
location: 'onboarding_metametrics',
...(accountType && { account_type: accountType }),
})
.build(),
);

metrics.trackEvent(
metrics
Expand Down
8 changes: 8 additions & 0 deletions app/components/Views/Onboarding/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { captureException } from '@sentry/react-native';
import Logger from '../../../util/Logger';
import { MIGRATION_ERROR_HAPPENED } from '../../../constants/storage';
import { AccountType } from '../../../constants/onboarding';
import { MetaMetricsEvents } from '../../../core/Analytics';

// Mock netinfo - using existing mock
jest.mock('@react-native-community/netinfo');
Expand Down Expand Up @@ -1990,6 +1991,13 @@ describe('Onboarding', () => {

await waitFor(() => {
expect(mockAnalytics.optIn).toHaveBeenCalled();
expect(
mockCreateEventBuilder.mock.calls.some(
(call) =>
(call[0] as { category: string }).category ===
MetaMetricsEvents.METRICS_OPT_IN.category,
),
).toBe(true);
});
});
});
Expand Down
13 changes: 12 additions & 1 deletion app/components/Views/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,25 @@ const Onboarding = () => {
discardBufferedTraces();
await setupSentry();

const accountType = getSocialAccountType(provider, !createWallet);
metrics.trackEvent(
metrics
.createEventBuilder(MetaMetricsEvents.METRICS_OPT_IN)
.addProperties({
updated_after_onboarding: false,
location: 'onboarding_social_login',
account_type: accountType,
})
.build(),
);

// use new trace instead of buffered trace for social login
onboardingTraceCtx.current = trace({
name: TraceName.OnboardingJourneyOverall,
op: TraceOperation.OnboardingUserJourney,
tags: getTraceTags(store.getState()),
});

const accountType = getSocialAccountType(provider, !createWallet);
if (createWallet) {
track(MetaMetricsEvents.WALLET_SETUP_STARTED, {
account_type: accountType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,18 @@ describe('MetaMetricsAndDataCollectionSection', () => {
deviceProp: 'Device value',
userProp: 'User value',
});
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
updated_after_onboarding: true,
location: 'settings',
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED.category,
properties: expect.objectContaining({
Expand Down Expand Up @@ -407,7 +418,18 @@ describe('MetaMetricsAndDataCollectionSection', () => {
fireEvent(metaMetricsSwitch, 'valueChange', true);

await waitFor(() => {
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
updated_after_onboarding: true,
location: 'onboarding_default_settings',
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED.category,
properties: expect.objectContaining({
Expand Down Expand Up @@ -467,6 +489,16 @@ describe('MetaMetricsAndDataCollectionSection', () => {
fireEvent(metaMetricsSwitch, 'valueChange', true);

await waitFor(() => {
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
updated_after_onboarding: true,
location: 'settings',
account_type: AccountType.MetamaskGoogle,
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
name: MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED.category,
Expand Down Expand Up @@ -808,6 +840,16 @@ describe('MetaMetricsAndDataCollectionSection', () => {
});
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: MetaMetricsEvents.METRICS_OPT_IN.category,
properties: expect.objectContaining({
location: 'settings',
updated_after_onboarding: true,
}),
}),
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED.category,
properties: expect.objectContaining({
Expand All @@ -827,8 +869,8 @@ describe('MetaMetricsAndDataCollectionSection', () => {
},
);
expect(mockAnalytics.trackEvent).toHaveBeenNthCalledWith(
// if MetaMetrics is initially disabled, trackEvent is called twice and this is 2nd call
!metaMetricsInitiallyEnabled ? 2 : 1,
// if MetaMetrics is initially disabled, marketing consent is the 3rd trackEvent
!metaMetricsInitiallyEnabled ? 3 : 1,
expect.objectContaining({
name: MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED.category,
properties: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ const MetaMetricsAndDataCollectionSection: React.FC<
setAnalyticsEnabled(true);

analytics.identify(consolidatedTraits);
analytics.trackEvent(
AnalyticsEventBuilder.createEventBuilder(
MetaMetricsEvents.METRICS_OPT_IN,
)
.addProperties({
updated_after_onboarding: true,
location: analyticsLocation,
...(accountType && { account_type: accountType }),
})
.build(),
);
analytics.trackEvent(
AnalyticsEventBuilder.createEventBuilder(
MetaMetricsEvents.ANALYTICS_PREFERENCE_SELECTED,
Expand Down
2 changes: 2 additions & 0 deletions app/core/Analytics/MetaMetrics.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ enum EVENT_NAME {

// Analytics
ANALYTICS_PREFERENCE_SELECTED = 'Analytics Preference Selected',
METRICS_OPT_IN = 'Metrics Opt In',
METRICS_OPT_OUT = 'Metrics Opt Out',
ANALYTICS_REQUEST_DATA_DELETION = 'Delete MetaMetrics Data Request Submitted',
EXPERIMENT_VIEWED = 'Experiment Viewed',
Expand Down Expand Up @@ -829,6 +830,7 @@ const events = {
ANALYTICS_PREFERENCE_SELECTED: generateOpt(
EVENT_NAME.ANALYTICS_PREFERENCE_SELECTED,
),
METRICS_OPT_IN: generateOpt(EVENT_NAME.METRICS_OPT_IN),
METRICS_OPT_OUT: generateOpt(EVENT_NAME.METRICS_OPT_OUT),
ANALYTICS_REQUEST_DATA_DELETION: generateOpt(
EVENT_NAME.ANALYTICS_REQUEST_DATA_DELETION,
Expand Down
Loading