BlueWallet/blue_modules/analytics.ts

57 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-20 18:26:46 +02:00
import Bugsnag from '@bugsnag/react-native';
2024-05-20 11:54:13 +02:00
import { getUniqueId } from 'react-native-device-info';
2024-04-15 22:53:44 +02:00
import { BlueApp as BlueAppClass } from '../class';
const BlueApp = BlueAppClass.getInstance();
/**
* in case Bugsnag was started, but user decided to opt out while using the app, we have this
* flag `userHasOptedOut` and we forbid logging in `onError` handler
* @type {boolean}
*/
let userHasOptedOut: boolean = false;
2021-08-20 18:26:46 +02:00
2021-05-18 13:54:18 +02:00
if (process.env.NODE_ENV !== 'development') {
(async () => {
const uniqueID = await getUniqueId();
const doNotTrack = await BlueApp.isDoNotTrackEnabled();
if (doNotTrack) {
// dont start Bugsnag at all
return;
}
2023-10-20 16:27:26 +02:00
Bugsnag.start({
user: {
id: uniqueID,
},
onError: function (event) {
return !userHasOptedOut;
},
});
})();
2021-05-18 13:54:18 +02:00
}
const A = async (event: string) => {};
A.ENUM = {
INIT: 'INIT',
GOT_NONZERO_BALANCE: 'GOT_NONZERO_BALANCE',
2019-11-29 00:16:04 +01:00
GOT_ZERO_BALANCE: 'GOT_ZERO_BALANCE',
CREATED_WALLET: 'CREATED_WALLET',
CREATED_LIGHTNING_WALLET: 'CREATED_LIGHTNING_WALLET',
2019-11-29 00:16:04 +01:00
APP_UNSUSPENDED: 'APP_UNSUSPENDED',
};
A.setOptOut = (value: boolean) => {
2021-08-20 18:26:46 +02:00
if (value) userHasOptedOut = true;
};
A.logError = (errorString: string) => {
2021-09-13 15:08:49 +02:00
console.error(errorString);
Bugsnag.notify(new Error(String(errorString)));
};
export default A;