mattermost-mobile/app/telemetry/telemetry_utils.js
Elias Nahum d3a6e166ad
MM-15758 Update dependencies including Fastlane (#4272)
* Update dependencies including Fastlane and disable Flipper on iOS

* Remove EventEmitter for previous doc-viewer

* Fix android crash when setting more channels buttons

* Downgrade fuse.js

* Upgrade deps to latest

* Update Podfile.lock

* Downgrade RNN to 6.4.0

* QA Review #2

* Upgrade fuse.js to 6.0.0
2020-05-18 11:24:47 -07:00

102 lines
2.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Dimensions} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import * as RNLocalize from 'react-native-localize';
import LocalConfig from '@assets/config';
export function saveToTelemetryServer(data) {
const {
TelemetryEnabled,
TelemetryUrl,
TelemetryApiKey,
} = LocalConfig;
if (TelemetryEnabled && TelemetryUrl) {
fetch(TelemetryUrl, {
method: 'post',
body: JSON.stringify({data}),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'x-api-key': TelemetryApiKey,
},
});
}
}
const presetTID = {
'start:overall': 0,
'start:process_packages': 1,
'start:content_appeared': 2,
'start:select_server_screen': 3,
'start:channel_screen': 4,
'team:switch': 5,
'channel:loading': 6,
'channel:switch_loaded': 7,
'channel:switch_initial': 8,
'channel:close_drawer': 9,
'channel:open_drawer': 10,
'posts:loading': 11,
'post_list:thread': 12,
'post_list:permalink': 13,
};
export function setTraceRecord({
name,
time: ts,
dur = 0,
instanceKey = 0,
pid = 0,
}) {
const tid = presetTID[name];
return {
cat: 'react-native',
ph: 'X',
name,
ts,
dur,
pid,
tid,
args: {
instanceKey,
tag: name,
},
};
}
export async function getDeviceInfo() {
const {height, width} = Dimensions.get('window');
return {
api_level: await DeviceInfo.getAPILevel(),
build_number: DeviceInfo.getBuildNumber(),
bundle_id: DeviceInfo.getBundleId(),
brand: DeviceInfo.getBrand(),
country: RNLocalize.getCountry(),
device_id: DeviceInfo.getDeviceId(),
device_locale: RNLocalize.getLocales()[0].languageCode,
device_type: DeviceInfo.getDeviceType(),
device_unique_id: DeviceInfo.getUniqueID(),
height: height ? Math.floor(height) : 0,
is_emulator: await DeviceInfo.isEmulator(),
is_tablet: DeviceInfo.isTablet(),
manufacturer: await DeviceInfo.getManufacturer(),
max_memory: await DeviceInfo.getMaxMemory(),
model: DeviceInfo.getModel(),
system_name: DeviceInfo.getSystemName(),
system_version: DeviceInfo.getSystemVersion(),
timezone: RNLocalize.getTimeZone(),
app_version: DeviceInfo.getVersion(),
width: width ? Math.floor(width) : 0,
};
}
export default {
getDeviceInfo,
setTraceRecord,
};