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: use Segment (batch 1) #8067

Merged
merged 43 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c047917
feat: create Segment analytics implementation + use geo-localization …
NicolasMassart Dec 6, 2023
886a8b1
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 6, 2023
e6dcad4
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 6, 2023
e457b27
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 8, 2023
726fd80
feat: Use new Segment implementation in onboarding steps (Batch 3 of …
NicolasMassart Dec 8, 2023
92c5dc9
fix: rename Segment env vars and add in example file (#8059)
NicolasMassart Dec 11, 2023
6cac642
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 11, 2023
c2af79a
Merge branch 'feat/batch_1129_segment' of github.com:MetaMask/metamas…
NicolasMassart Dec 11, 2023
265d1a9
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 12, 2023
e34d62e
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 12, 2023
9197580
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 14, 2023
b43425f
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Dec 14, 2023
ad1022d
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 3, 2024
da3f72d
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 8, 2024
054b3b6
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 9, 2024
df791dd
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 10, 2024
8e795c6
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 16, 2024
88dfddd
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 22, 2024
f199acc
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 22, 2024
8419e09
feat: segment data deletion (4/4) (#8090)
NicolasMassart Jan 23, 2024
723ff5d
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 23, 2024
5e871ce
feat: Segment instance error handling (#8218)
NicolasMassart Jan 24, 2024
ad72be1
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 24, 2024
23b4675
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 29, 2024
e2440c3
update lockfile
NicolasMassart Jan 29, 2024
06a526e
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Jan 30, 2024
f6be241
feat: a hook to use Segment metrics (#8471)
NicolasMassart Feb 2, 2024
99194b0
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Feb 2, 2024
6b5cc4c
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Feb 13, 2024
80b9408
feat: migrate Segment core mechanism [split of 8387] (#8573)
NicolasMassart Feb 14, 2024
18106c2
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Feb 16, 2024
c9e1667
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Feb 16, 2024
780e6aa
fix import and getInstance call
NicolasMassart Feb 16, 2024
ed3dc7a
remove await
NicolasMassart Feb 16, 2024
f3feb39
use hook
NicolasMassart Feb 16, 2024
0ff5c5a
Merge branch 'main' into feat/batch_1129_segment
NicolasMassart Feb 16, 2024
729cbfa
use env var for endpoint
NicolasMassart Feb 19, 2024
8629533
add test env for metametrics
NicolasMassart Feb 19, 2024
61bbe56
make type for track consistent between class and hook
NicolasMassart Feb 19, 2024
bfaa528
fix configure
NicolasMassart Feb 20, 2024
00b0f3a
fix test
NicolasMassart Feb 20, 2024
af34152
fix type
NicolasMassart Feb 20, 2024
502a9ff
optimise metrics settings
NicolasMassart Feb 20, 2024
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 @@ -100,7 +100,7 @@ import AsyncStorage from '../../../store/async-storage-wrapper';
import ShowIpfsGatewaySheet from '../../Views/ShowIpfsGatewaySheet/ShowIpfsGatewaySheet';
import ShowDisplayNftMediaSheet from '../../Views/ShowDisplayMediaNFTSheet/ShowDisplayNFTMediaSheet';
import AmbiguousAddressSheet from '../../../../app/components/Views/Settings/Contacts/AmbiguousAddressSheet/AmbiguousAddressSheet';
import { useMetrics } from '../../hooks/useMetrics';
import { MetaMetrics } from '../../../core/Analytics';

const clearStackNavigatorOptions = {
headerShown: false,
Expand Down Expand Up @@ -230,7 +230,6 @@ const VaultRecoveryFlow = () => (
);

const App = ({ userLoggedIn }) => {
const { getMetaMetricsId } = useMetrics();
const animationRef = useRef(null);
const animationNameRef = useRef(null);
const opacity = useRef(new Animated.Value(1)).current;
Expand Down Expand Up @@ -370,15 +369,14 @@ const App = ({ userLoggedIn }) => {

useEffect(() => {
const initAnalytics = async () => {
const metaMetricsId = await getMetaMetricsId();
Logger.log(`MetaMetrics initialised with ID: ${metaMetricsId}`);
await MetaMetrics.getInstance().configure();
await Analytics.init();
};

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

useEffect(() => {
// Init SDKConnect only if the navigator is ready, user is onboarded, and SDK is not initialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const Settings: React.FC = () => {
setHintText(manualBackup);
}, []);

const checkAnalyticsEnabled = useCallback(async () => {
const checkAnalyticsEnabled = useCallback(() => {
trackEvent(MetaMetricsEvents.VIEW_SECURITY_SETTINGS, {});
setAnalyticsEnabled(isEnabled());
}, [trackEvent, isEnabled]);
Expand Down
4 changes: 2 additions & 2 deletions app/core/Analytics/MetaMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ class MetaMetrics implements IMetaMetrics {
} else {
this.metametricsId = metametricsId;
}

if (__DEV__) Logger.log(`Current MetaMatrics ID: ${this.metametricsId}`);
return this.metametricsId;
};

Expand Down Expand Up @@ -507,6 +505,8 @@ class MetaMetrics implements IMetaMetrics {
await this.#getDeleteRegulationDateFromPrefs();
this.dataRecorded = await this.#getIsDataRecordedFromPrefs();
this.#isConfigured = true;
if (__DEV__)
Logger.log(`MetaMetrics configured with ID: ${this.metametricsId}`);
tommasini marked this conversation as resolved.
Show resolved Hide resolved
} catch (error: any) {
Logger.error(error, 'Error initializing MetaMetrics');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import trackAfterInteractions from './trackAfterInteractions';
import { IMetaMetricsEvent } from '../../../core/Analytics';

const { InteractionManager } = jest.requireActual('react-native');
InteractionManager.runAfterInteractions = jest.fn(async (callback) =>
Expand All @@ -25,7 +26,7 @@ describe('trackAfterInteractions', () => {
});

it('calls saveOnboardingEvent when metrics is not enabled', async () => {
const mockEvent = { category: 'testEvent' };
const mockEvent: IMetaMetricsEvent = { category: 'testEvent' };
const mockProperties = { prop: 'testProp' };

mockEnabled.mockReturnValue(false);
Expand All @@ -36,37 +37,31 @@ describe('trackAfterInteractions', () => {
mockSaveOnboardingEvent,
);

expect(mockSaveOnboardingEvent).toHaveBeenCalledWith(mockEvent.category);
expect(mockSaveOnboardingEvent).toHaveBeenCalledWith(mockEvent);
expect(mockTrackEvent).not.toHaveBeenCalled();
});

it('call trackEvent when metrics is not enabled but saveOnboardingEvent is not defined', async () => {
const mockEvent = { category: 'testEvent' };
const mockEvent: IMetaMetricsEvent = { category: 'testEvent' };
const mockProperties = { prop: 'testProp' };

mockEnabled.mockReturnValue(true);

await trackAfterInteractions(mockEvent, mockProperties);

expect(mockSaveOnboardingEvent).not.toHaveBeenCalledWith();
expect(mockTrackEvent).toHaveBeenCalledWith(
mockEvent.category,
mockProperties,
);
expect(mockTrackEvent).toHaveBeenCalledWith(mockEvent, mockProperties);
});

it('call trackEvent when metrics is enabled', async () => {
const mockEvent = { category: 'testEvent' };
const mockEvent: IMetaMetricsEvent = { category: 'testEvent' };
const mockProperties = { prop: 'testProp' };

mockEnabled.mockReturnValue(true);

await trackAfterInteractions(mockEvent, mockProperties);

expect(mockSaveOnboardingEvent).not.toHaveBeenCalledWith();
expect(mockTrackEvent).toHaveBeenCalledWith(
mockEvent.category,
mockProperties,
);
expect(mockTrackEvent).toHaveBeenCalledWith(mockEvent, mockProperties);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { JsonMap } from '@segment/analytics-react-native';
const trackAfterInteractions = async (
event: IMetaMetricsEvent,
properties: JsonMap = {},
saveOnboardingEvent?: (event: string) => {
event: object;
saveOnboardingEvent?: (event: IMetaMetricsEvent) => {
event: IMetaMetricsEvent;
type: string;
},
): Promise<void> =>
Expand All @@ -21,7 +21,7 @@ const trackAfterInteractions = async (
const isOnboardingDelayedEvent =
!metrics.isEnabled() && saveOnboardingEvent;
if (isOnboardingDelayedEvent) {
saveOnboardingEvent(event.category);
saveOnboardingEvent(event);
} else {
metrics.trackEvent(event, properties);
}
Expand Down
Loading