YH_EventDataFactory.m
11.8 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//
// YH_EventDataFactory.m
// YHEventReport
//
// Created by John Tai on 6/9/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import "YH_EventDataFactory.h"
#import "YHEventReportMacros.h"
#import "NSString+ER_URL.h"
#import "YH_EventUtil.h"
@implementation YH_EventDataFactory
+(NSDictionary *)factoryTimeEventDataWithViewController:(UIViewController *)viewController ElapsedTime:(NSTimeInterval)elapsedTime{
NSString *className = NSStringFromClass([viewController class]);
NSString *controllerTitle = viewController.navigationItem.title;
if (IsStrEmpty(className)) {
return nil;
}
if (IsStrEmpty(controllerTitle)) {
controllerTitle=@"";
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[className er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[controllerTitle er_encodedString],kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithElapsedTime:(NSTimeInterval)elapsedTime status:(YHEventLoadStatus)status url:(NSString*)url
{
NSString *currentUrl = [[NSString alloc]initWithString:url];
if (IsStrEmpty(currentUrl)) {
currentUrl=@"";
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[currentUrl er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,@"",kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithUIControl:(UIControl *)control url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{
NSString *className = NSStringFromClass([control class]);
if (IsStrEmpty(className)) {
return nil;
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithUITableView:(UITableView*)tableView url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{
NSString *className = NSStringFromClass([tableView class]);
if (IsStrEmpty(className)) {
return nil;
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithUICollectionView:(UICollectionView*)tableView url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{
NSString *className = NSStringFromClass([tableView class]);
if (IsStrEmpty(className)) {
return nil;
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime {
NSString *className = NSStringFromClass([gestureRecognizer class]);
if (IsStrEmpty(className)) {
return nil;
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length ElapsedTime:(NSTimeInterval)elapsedTime postMethod:(NSString*)postMethod
{
if (IsStrEmpty(postMethod)) {
postMethod = @"";
}
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[requestUrl er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,statusCode,kYHEventReportTimeHttpCode,length,kYHEventReportTimeHttpLength,method,kYHEventReportTimeHttpMethod,postMethod,kYHEventReportTimeHttpEi,nil];
return dict;
}
+(NSString *)getPointName:(YHEventReportPointName)pointName{
NSString *str = @"";
switch (pointName) {
case YHPN_BUSINESS_UFO_SELL:
str = @"BUSINESS_UFO_SELL";
break;
case YHPN_BUSINESS_UFO_BUY:
str = @"BUSINESS_UFO_BUY";
break;
case YHPN_VIEWCONTROLLER:
str = @"PAGEMETRICS";
break;
case YHPH_HTTPMETRICS:
str = @"HTTPMETRICS";
break;
case YHPN_WEBVIEW:
str = @"WEBVIEW";
break;
case YHPN_IMAGEVIEW:
str = @"IMAGEMETRICS";
break;
case YHPN_BUTTON:
str = @"BUTTON";
break;
case YHPN_GESTURERECOGNIZER:
str = @"GESTURERECOGNIZER";
break;
case YHPN_TIMEOUT:
str = @"TIMEOUT";
break;
case YHPN_CODE_ERR:
str = @"CODE_ERR";
break;
case YHPN_H5_FEATURE_META_FAILED:
str = @"NO_WEBMETA";
break;
case YHPN_RN_EXCEPTION:
str = @"RN_EXCEPTION";
break;
case YHPN_CRASH:
str = @"CRASH";
break;
case YHPN_CUSTOM_EXCEPTION:
str = @"CUSTOM_EXCEPTION";
break;
case YHPN_CDN_CHOOSE:
str = @"CDN_CHOOSE";
break;
case YHPN_CDN_ALERT:
str = @"CDN_ALERT";
break;
case YHPN_CDN_BACKHOST:
str = @"CDN_BACKHOST";
break;
case YHPN_CENTER_CHOOSE:
str = @"CENTER_CHOOSE";
break;
case YHPN_APP_PATCHLOAD:
str = @"APP_PATCHLOAD";
break;
case YHPN_RN_PATCHLOAD:
str = @"RN_PATCHLOAD";
break;
case YHPN_START:
str = @"START";
break;
case YHPN_RESUME:
str = @"RESUME";
break;
case YHPN_STOP:
str = @"STOP";
break;
case YHPN_DESTROY:
str = @"DESTROY";
break;
case YHPN_PUSH_ACTIVE:
str = @"PUSH_ACTIVE";
break;
case YHPN_T3_ACTIVE:
str = @"T3_ACTIVE";
break;
case YHPN_UL_ACTIVE:
str = @"UL_ACTIVE";
break;
case YHPN_APP_ACTIVE:
str = @"APP_ACTIVE";
break;
case YHPN_BUSINESS_USER_LOGIN:
str = @"BUSINESS_USER_LOGIN";
break;
case YHPN_BUSINESS_USER_REGIST:
str = @"BUSINESS_USER_REGIST";
break;
case YHPN_BUSINESS_USER_REPASSWORD:
str = @"BUSINESS_USER_REPASSWORD";
break;
case YHPN_BUSINESS_ORDER_ADDSHOPPINGCARD:
str = @"BUSINESS_ORDER_ADDSHOPPINGCARD";
break;
case YHPN_BUSINESS_ORDER_ACCOUNT:
str = @"BUSINESS_ORDER_ACCOUNT";
break;
case YHPN_BUSINESS_ORDER_CONFIRM:
str = @"BUSINESS_ORDER_CONFIRM";
break;
case YHPN_BUSINESS_ORDER_PAY:
str = @"BUSINESS_ORDER_PAY";
break;
case YHPN_BUSINESS_RESPONSE_CHECKSUM:
str = @"BUSINESS_RESPONSE_CHECKSUM";
break;
case YHPN_BUSINESS_UNUSUAL_SERVICE_CODE:
str = @"BUSINESS_UNUSUAL_SERVICE_CODE";
break;
case YHPH_LAG:
str = @"LAG";
break;
case YHPN_NETWORK_API_TIMEOUT:
str = @"NETWORK_API_TIMEOUT";
break;
case YHPN_NETWORK_API_CODE_ERR:
str = @"NETWORK_API_CODE_ERR";
break;
case YHPN_NETWORK_IMAGE_TIMEOUT:
str = @"NETWORK_IMAGE_TIMEOUT";
break;
case YHPN_NETWORK_IMAGE_CODE_ERR:
str = @"NETWORK_IMAGE_CODE_ERR";
break;
case YHPN_NETWORK_API_JSONFORMATFAIL:
str = @"NETWORK_API_JSONFORMATFAIL";
break;
case YHPN_NETWORK_NO_ACTIVENET:
str = @"NO_ACTIVENET";
break;
case YHPN_NETWORK_FIRST_LAUNCH_ERR:
str = @"NETWORK_FIRST_LAUNCH_ERR";
break;
case YHPH_MEMORY:
str = @"MEMORYMETRICS";
break;
case YHPN_AD_UNION:
str = @"UNION";
break;
case YHPN_INFO_APPL:
str = @"APPL";
break;
case YHPN_APPCPU:
str = @"CPU";
break;
case YHPN_APPMEMORY:
str = @"MEMORY";
break;
case YHPN_APPTRAFFIC:
str = @"TRAFFIC";
break;
case YHPN_APPFPS:
str = @"FPS";
break;
case YHPN_BUSINESS_UFO_VIDEO_TRAFFIC:
str = @"UFO_BUSINESS_VIDEO_TRAFFIC";
break;
case YHPN_NETWORK_DETECT:
str = @"NETWORK_DETECT";
break;
default:
break;
}
NSParameterAssert(str.length > 0);
return str;
}
+(NSString *)getPointType:(YHPointType)pointType{
NSString *str = @"";
switch (pointType) {
case YHPT_NETWORK:
str = @"NETWORK";
break;
case YHPT_EXCEPTION:
str = @"EXCEPTION";
break;
case YHPT_CDN:
str = @"CDN";
break;
case YHPT_CENTER:
str = @"CENTER";
break;
case YHPT_PATCH:
str = @"PATCH";
break;
case YHPT_LIFECYCLE:
str = @"LIFECYCLE";
break;
case YHPT_BUSINESS:
str = @"BUSINESS";
break;
case YHPT_PERFORMANCE:
str = @"PERFORMANCE";
break;
case YHPT_AD:
str = @"AD";
break;
case YHPT_APPTARGET:
str = @"APPTARGET";
break;
case YHPT_UFOBUSINESS:
str = @"UFO_BUSINESS";
break;
case YHPT_INFO:
str = @"INFO";
break;
default:
break;
}
NSParameterAssert(str.length > 0);
return str;
}
+(NSString *)getDataType:(YHEventReportTrackDataType)type{
NSString *str = @"";
switch (type) {
case YHEventReportTrackDataTypeStart:
str = @"start";
break;
case YHEventReportTrackDataTypeDestory:
str = @"destory";
break;
case YHEventReportTrackDataTypeStop:
str = @"stop";
break;
case YHEventReportTrackDataTypeHeartbeat:
str = @"hb";
break;
case YHEventReportTrackDataTypeNONE:
str = @"realTime";
break;
default:
break;
}
return str;
}
+(NSDictionary *)getDeviceInfo:(YH_PerformanceAppInfo*)appInfo{
NSDictionary *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:
YOHOAppReportDefaultAPPKey,YOHOAppReportKeyAK,
IsStrEmpty(appInfo.udid)?@"":appInfo.udid,YOHOAppReportKeyUDID,
IsStrEmpty(appInfo.ch)?@"":appInfo.ch,YOHOAppReportKeyCH,
IsStrEmpty(appInfo.os)?@"":appInfo.os,YOHOAppReportKeyOS,
IsStrEmpty(appInfo.osv)?@"":appInfo.osv,YOHOAppReportKeyOSV,
IsStrEmpty(appInfo.dm)?@"":appInfo.dm,YOHOAppReportKeyDM,
// IsStrEmpty(appInfo.idfa)?@"":appInfo.idfa,YOHOAppReportKeyIDFA,
nil];
return deviceInfo;
}
@end