-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
189 lines (178 loc) · 5.48 KB
/
Copy pathindex.tsx
File metadata and controls
189 lines (178 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { AppRegistry } from 'react-native';
//import AsyncStorage from '@react-native-async-storage/async-storage'
import App from './src/App';
import { startReactNativeNavigation } from './src/RNNApp';
import { name as appName, navigation as navigationLib } from './app.json';
import { Navigation } from 'react-native-navigation';
import {
DetectFrequency,
DeviceMetricsMonitorType,
EnvType,
IOSCrashMonitoringType,
ErrorMonitorType,
FTLogConfig,
FTLogStatus,
FTMobileConfig,
FTMobileReactNative,
FTReactNativeLog,
FTReactNativeRUM,
FTReactNativeTrace,
FTRUMConfig,
FTTraceConfig,
TraceType,
FTDBCacheDiscard,
FTRUMCacheDiscard,
FTRumActionTracking,
FTRumErrorTracking
} from '@cloudcare/react-native-mobile';
import {
FTReactNativeSessionReplay,
FTSessionReplayConfig,
SessionReplayPrivacy,
} from '@cloudcare/react-native-session-replay';
import Config from 'react-native-config';
console.log('navigationLib library: ' + navigationLib);
//React Native development
reactNativeInitSDK();
// //Native development, some pages or business processes use React Native implementation
// //Initialize SDK in native project, no need to initialize configuration on React Native side
// //Enable configuration as needed
// hybridConfig();
function hybridConfig(){
//Enable automatic collection of react-native control clicks
FTRumActionTracking.startTracking();
//Enable automatic collection of react-native Error
FTRumErrorTracking.startTracking();
}
// SDK initialization
async function reactNativeInitSDK() {
//Basic configuration
let config: FTMobileConfig = {
datawayUrl:Config.DATAWAY_URL,
clientToken:Config.CLIENT_TOKEN,
debug: true,
env:'test',
enableLimitWithDbSize:true,
dbCacheLimit:50*1024*1024,
dbDiscardStrategy:FTDBCacheDiscard.discard,
remoteConfiguration:true,
// envType:EnvType.prod,
globalContext: { 'sdk_example': 'example1' },
remoteConfigOverrideRules: [
{
id: 'auto_rule1',
enabled: true,
match: {
customKeys: {
env: 'test'
}
},
override: {
rumSampleRate: 1.0,
traceSampleRate: 1.0,
logSampleRate: 1.0,
}
}
]
};
console.log('remote config override rules configured', config.remoteConfigOverrideRules);
await FTMobileReactNative.sdkConfig(config);
FTMobileReactNative.addRemoteConfigListener(
(result) => {
console.log('addRemoteConfigListener auto remote config callback', result);
}
);
// log settings
let logConfig: FTLogConfig = {
enableCustomLog: true,
enableLinkRumData: true,
logCacheLimitCount: 2000,
sampleRate:1,
globalContext: { 'log_example': 'example2' },
};
await FTReactNativeLog.logConfig(logConfig);
// trace settings
let traceConfig: FTTraceConfig = {
enableLinkRUMData: true,
enableNativeAutoTrace: true,
sampleRate:1.0,
traceType: TraceType.ddTrace,
};
await FTReactNativeTrace.setConfig(traceConfig);
FTMobileReactNative.appendBridgeContext({"wgt_id":"widget_id"});
// rum settings
let rumConfig: FTRUMConfig = {
androidAppId: Config.ANDROID_APP_ID,
iOSAppId:Config.IOS_APP_ID,
enableAutoTrackUserAction: true,
enableAutoTrackError: true,
enableNativeUserAction: true,
enableNativeUserView: false,
sampleRate:1,
enableTraceWebView: true,
iosCrashMonitoringType: IOSCrashMonitoringType.all,
enableNativeUserResource: true,
enableResourceHostIP:true,
enableTrackNativeAppANR:true,
enableTrackNativeCrash:true,
enableTrackNativeFreeze:true,
errorMonitorType:ErrorMonitorType.cpu | ErrorMonitorType.memory,
deviceMonitorType:DeviceMetricsMonitorType.all,
detectFrequency:DetectFrequency.rare,
rumCacheLimitCount:1000,
rumDiscardStrategy:FTRUMCacheDiscard.discardOldest,
};
// Static globalContext setting
//Set in environment files like .env.debug, .env.release, etc.
rumConfig.globalContext = { 'track_id': Config.TRACK_ID };
await FTReactNativeRUM.setConfig(rumConfig);
/** Dynamic globalContext setting
new Promise(function(resolve) {
AsyncStorage.getItem("track_id",(error,result)=>{
if (result === null){
console.log('Get failed: ' + error);
}else {
console.log('Get successful: ' + result);
if( result != undefined){
rumConfig.globalContext = {"track_id":result};
}
}
resolve(FTReactNativeRUM.setConfig(rumConfig));
})
})
*/
let sessionReplayConfig:FTSessionReplayConfig = {
sampleRate:1,
privacy:SessionReplayPrivacy.ALLOW
}
await FTReactNativeSessionReplay.sessionReplayConfig(sessionReplayConfig);
FTReactNativeLog.logging('config complete', FTLogStatus.info);
}
// Initialize corresponding navigation component based on navigationLib set in app.json, start APP
// Navigation component uses react-navigation
if (navigationLib == 'react-navigation') {
AppRegistry.registerComponent(appName, () => App);
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
root: {
stack: {
options: {
topBar: {
visible: false,
},
},
children: [
{
component: {
name: appName,
},
},
],
},
},
});
});
} else if (navigationLib == 'react-native-navigation') {
// Navigation component uses react-native-navigation
startReactNativeNavigation();
}