@@ -167,7 +167,6 @@ import type {
167
167
ExportableKeyEncryptor ,
168
168
KeyDerivationOptions ,
169
169
} from '../types' ;
170
- import type { MetaMetricsController } from '../utils' ;
171
170
import {
172
171
debouncePersistState ,
173
172
fetchSnap ,
@@ -777,9 +776,9 @@ type SnapControllerArgs = {
777
776
clientCryptography ?: CryptographicFunctions ;
778
777
779
778
/**
780
- * MetaMetrics controller instance. Used for event tracking.
779
+ * MetaMetrics event tracking hook .
781
780
*/
782
- metaMetricsController : MetaMetricsController ;
781
+ trackEvent : TrackEventHook ;
783
782
} ;
784
783
785
784
type AddSnapArgs = {
@@ -800,6 +799,14 @@ type SetSnapArgs = Omit<AddSnapArgs, 'location' | 'versionRange'> & {
800
799
hideSnapBranding ?: boolean ;
801
800
} ;
802
801
802
+ type TrackingEventPayload = {
803
+ event : string ;
804
+ category : string ;
805
+ properties : Record < string , Json > ;
806
+ } ;
807
+
808
+ type TrackEventHook = ( event : TrackingEventPayload ) => void ;
809
+
803
810
const defaultState : SnapControllerState = {
804
811
snaps : { } ,
805
812
snapStates : { } ,
@@ -885,31 +892,9 @@ export class SnapController extends BaseController<
885
892
886
893
readonly #preinstalledSnaps: PreinstalledSnap [ ] | null ;
887
894
888
- readonly #metaMetricsController: MetaMetricsController ;
895
+ readonly #trackEvent: TrackEventHook ;
889
896
890
- readonly #trackSnapExport = throttleTracking (
891
- async (
892
- snapId : SnapId ,
893
- handler : string ,
894
- success : boolean ,
895
- origin : string ,
896
- ) => {
897
- const snapMetadata = await this . getRegistryMetadata ( snapId ) ;
898
- this . #metaMetricsController. trackEvent ( {
899
- event : 'SnapExportUsed' ,
900
- category : 'Snaps' ,
901
- properties : {
902
- // eslint-disable-next-line @typescript-eslint/naming-convention
903
- snap_id : snapId ,
904
- export : handler ,
905
- // eslint-disable-next-line @typescript-eslint/naming-convention
906
- snap_category : snapMetadata ?. category ,
907
- success,
908
- origin,
909
- } ,
910
- } ) ;
911
- } ,
912
- ) ;
897
+ readonly #trackSnapExport: ReturnType < typeof throttleTracking > ;
913
898
914
899
constructor ( {
915
900
closeAllConnections,
@@ -929,7 +914,7 @@ export class SnapController extends BaseController<
929
914
getMnemonicSeed,
930
915
getFeatureFlags = ( ) => ( { } ) ,
931
916
clientCryptography,
932
- metaMetricsController ,
917
+ trackEvent ,
933
918
} : SnapControllerArgs ) {
934
919
super ( {
935
920
messenger,
@@ -992,7 +977,7 @@ export class SnapController extends BaseController<
992
977
this . _onOutboundResponse = this . _onOutboundResponse . bind ( this ) ;
993
978
this . #rollbackSnapshots = new Map ( ) ;
994
979
this . #snapsRuntimeData = new Map ( ) ;
995
- this . #metaMetricsController = metaMetricsController ;
980
+ this . #trackEvent = trackEvent ;
996
981
997
982
this . #pollForLastRequestStatus( ) ;
998
983
@@ -1058,6 +1043,30 @@ export class SnapController extends BaseController<
1058
1043
Object . values ( this . state ?. snaps ?? { } ) . forEach ( ( snap ) =>
1059
1044
this . #setupRuntime( snap . id ) ,
1060
1045
) ;
1046
+
1047
+ this . #trackSnapExport = throttleTracking (
1048
+ async (
1049
+ snapId : SnapId ,
1050
+ handler : string ,
1051
+ success : boolean ,
1052
+ origin : string ,
1053
+ ) => {
1054
+ const snapMetadata = await this . getRegistryMetadata ( snapId ) ;
1055
+ this . #trackEvent( {
1056
+ event : 'SnapExportUsed' ,
1057
+ category : 'Snaps' ,
1058
+ properties : {
1059
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1060
+ snap_id : snapId ,
1061
+ export : handler ,
1062
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1063
+ snap_category : snapMetadata ?. category ?? null ,
1064
+ success,
1065
+ origin,
1066
+ } ,
1067
+ } ) ;
1068
+ } ,
1069
+ ) ;
1061
1070
}
1062
1071
1063
1072
/**
0 commit comments