Skip to content

Commit da566de

Browse files
committed
moved func to provider
1 parent a3990c3 commit da566de

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

packages/compass-indexes/src/components/create-index-modal/create-index-modal.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ import type { RootState } from '../../modules';
2323
import {
2424
useTrackOnChange,
2525
type TrackFunction,
26+
useFireExperimentViewed,
27+
TestName,
2628
} from '@mongodb-js/compass-telemetry/provider';
2729
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
2830
import { usePreference } from 'compass-preferences-model/provider';
29-
import {
30-
useFireExperimentViewed,
31-
TestName,
32-
} from '@mongodb-js/compass-telemetry';
3331

3432
type CreateIndexModalProps = React.ComponentProps<typeof CreateIndexForm> & {
3533
isVisible: boolean;
@@ -78,14 +76,14 @@ function CreateIndexModal({
7876
);
7977

8078
// @experiment Early Journey Indexes Guidance & Awareness | Jira Epic: CLOUDP-239367
81-
const enableInIndexesGuidanceExp =
82-
usePreference('enableIndexesGuidanceExp') || true;
83-
const showIndexesGuidanceVariant =
84-
usePreference('showIndexesGuidanceVariant') || true;
79+
const enableInIndexesGuidanceExp = usePreference('enableIndexesGuidanceExp');
80+
const showIndexesGuidanceVariant = usePreference(
81+
'showIndexesGuidanceVariant'
82+
);
8583

8684
useFireExperimentViewed({
8785
testName: TestName.earlyJourneyIndexesGuidance,
88-
shouldFire: enableInIndexesGuidanceExp || true,
86+
shouldFire: enableInIndexesGuidanceExp,
8987
});
9088

9189
return (
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
import {
2-
useTrackOnChange,
3-
type TrackFunction,
4-
} from '@mongodb-js/compass-telemetry/provider';
5-
61
export enum TestName {
72
earlyJourneyIndexesGuidance = 'EARLY_JOURNEY_INDEXES_GUIDANCE_20250328',
83
}
9-
10-
export const useFireExperimentViewed = ({
11-
testName,
12-
shouldFire = true,
13-
}: {
14-
testName: TestName;
15-
shouldFire?: boolean;
16-
}) => {
17-
useTrackOnChange(
18-
(track: TrackFunction) => {
19-
if (!shouldFire) {
20-
return;
21-
}
22-
track('Experiment Viewed', {
23-
test_name: testName,
24-
});
25-
},
26-
[],
27-
undefined
28-
);
29-
};

packages/compass-telemetry/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ export type {
55
IdentifyTraits,
66
ExtraConnectionData,
77
} from './types';
8-
export { TestName, useFireExperimentViewed } from './growth-experiments';

packages/compass-telemetry/src/provider.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createServiceLocator } from 'hadron-app-registry';
33
import { createTrack, type TelemetryServiceOptions } from './generic-track';
44
import { useLogger } from '@mongodb-js/compass-logging/provider';
55
import type { TrackFunction } from './types';
6+
import { TestName } from './growth-experiments';
67

78
const noop = () => {
89
// noop
@@ -101,4 +102,38 @@ export function useTrackOnChange(
101102
}, [...dependencies, track, options.skipOnMount]);
102103
}
103104

105+
/**
106+
* Hook that fires Experiment Viewed if user is in an experiment
107+
*
108+
* @param testName - The name of the experiment to track.
109+
* @param shouldFire - A boolean indicating whether to fire the event. Defaults to true.
110+
*
111+
* @example
112+
* useFireExperimentViewed({
113+
* testName: TestName.earlyJourneyIndexesGuidance,
114+
* shouldFire: enableInIndexesGuidanceExp ,
115+
* });
116+
*/
117+
export const useFireExperimentViewed = ({
118+
testName,
119+
shouldFire = true,
120+
}: {
121+
testName: TestName;
122+
shouldFire?: boolean;
123+
}) => {
124+
useTrackOnChange(
125+
(track: TrackFunction) => {
126+
if (!shouldFire) {
127+
return;
128+
}
129+
track('Experiment Viewed', {
130+
test_name: testName,
131+
});
132+
},
133+
[shouldFire, testName],
134+
undefined
135+
);
136+
};
137+
104138
export type { TrackFunction };
139+
export { TestName };

0 commit comments

Comments
 (0)