@@ -1423,6 +1423,10 @@ function getCurrentConnectionInfo(
1423
1423
return state . connections . byId [ connectionId ] ?. info ;
1424
1424
}
1425
1425
1426
+ function getCurrentConnectionStatus ( state : State , connectionId : ConnectionId ) {
1427
+ return state . connections . byId [ connectionId ] ?. status ;
1428
+ }
1429
+
1426
1430
/**
1427
1431
* Returns the number of active connections. We count in-progress connections
1428
1432
* as "active" to make sure that the maximum connection allowed check takes
@@ -1967,15 +1971,21 @@ const cleanupConnection = (
1967
1971
'Initiating disconnect attempt'
1968
1972
) ;
1969
1973
1974
+ const currentStatus = getCurrentConnectionStatus ( getState ( ) , connectionId ) ;
1975
+
1970
1976
// We specifically want to track Disconnected even when it's not really
1971
1977
// triggered by user at all, so we put it in the cleanup function that is
1972
1978
// called every time you disconnect, or remove a connection, or all of them,
1973
- // or close the app
1974
- track (
1975
- 'Connection Disconnected' ,
1976
- { } ,
1977
- getCurrentConnectionInfo ( getState ( ) , connectionId )
1978
- ) ;
1979
+ // or close the app. Only track when connection is either connected or
1980
+ // connecting, we might be calling this on something that was never
1981
+ // connected
1982
+ if ( currentStatus === 'connected' || currentStatus === 'connecting' ) {
1983
+ track (
1984
+ 'Connection Disconnected' ,
1985
+ { } ,
1986
+ getCurrentConnectionInfo ( getState ( ) , connectionId )
1987
+ ) ;
1988
+ }
1979
1989
1980
1990
const { closeConnectionStatusToast } = getNotificationTriggers (
1981
1991
preferences . getPreferences ( ) . enableMultipleConnectionSystem
0 commit comments