@rk911/tracker-sdk 1.7.15 → 1.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -6
- package/native/android/AndroidTracker.java +115 -17
- package/native/harmony/HarmonyTracker.ets +434 -0
- package/native/ios/RKTrackerSDK.swift +944 -168
- package/package.json +1 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { http } from '@kit.NetworkKit';
|
|
2
|
+
import { preferences } from '@kit.ArkData';
|
|
3
|
+
import { deviceInfo } from '@kit.BasicServicesKit';
|
|
4
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
5
|
+
import { connection } from '@kit.NetworkKit';
|
|
6
|
+
import { PreferencesUtil } from '../../PreferencesUtil';
|
|
7
|
+
import { CommonConstants } from '../http/CommonConstants';
|
|
8
|
+
|
|
9
|
+
export interface TrackerEvent {
|
|
10
|
+
eventId: string;
|
|
11
|
+
eventType: string;
|
|
12
|
+
eventName: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
sequence: number;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
pageRoute?: string;
|
|
18
|
+
pageTitle?: string;
|
|
19
|
+
referrer?: string;
|
|
20
|
+
os: string;
|
|
21
|
+
deviceBrand: string;
|
|
22
|
+
deviceModel: string;
|
|
23
|
+
osVersion: string;
|
|
24
|
+
networkType?: string;
|
|
25
|
+
duration?: number;
|
|
26
|
+
elementId?: string;
|
|
27
|
+
elementText?: string;
|
|
28
|
+
frontUrl?: string;
|
|
29
|
+
postParam?: string;
|
|
30
|
+
extraData?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class HarmonyTracker {
|
|
34
|
+
private static instance: HarmonyTracker | null = null;
|
|
35
|
+
private serverUrl: string = 'https://state.renruikeji.cn/api/point/task/trackBatch';
|
|
36
|
+
private appId: string = '22';
|
|
37
|
+
private sessionId: string = '';
|
|
38
|
+
private deviceId: string = '';
|
|
39
|
+
private userId: string = '';
|
|
40
|
+
private phone: string = '';
|
|
41
|
+
private storeName: string = '';
|
|
42
|
+
private userName: string = '';
|
|
43
|
+
private pflag: number = -1;
|
|
44
|
+
private platformName: string = '鸿蒙';
|
|
45
|
+
private sequence: number = 0;
|
|
46
|
+
private currentPageRoute: string = '';
|
|
47
|
+
private referrerPageRoute: string = '';
|
|
48
|
+
private lastPageStartTime: number = 0;
|
|
49
|
+
private eventQueue: Array<TrackerEvent> = [];
|
|
50
|
+
private isFlushing: boolean = false;
|
|
51
|
+
private flushTimerId: number = -1;
|
|
52
|
+
|
|
53
|
+
private static readonly LOG_TAG: string = 'HarmonyTracker';
|
|
54
|
+
private static readonly LOG_DOMAIN: number = 0xFF01;
|
|
55
|
+
private static readonly CACHE_KEY: string = 'rk_tracker_events_cache';
|
|
56
|
+
private static readonly MAX_QUEUE_SIZE: number = 1000;
|
|
57
|
+
private static readonly BATCH_SIZE: number = 20;
|
|
58
|
+
private static readonly FLUSH_INTERVAL_MS: number = 3000;
|
|
59
|
+
|
|
60
|
+
private static readonly friendlyTitles: Record<string, string> = {
|
|
61
|
+
'HomeMainPage': 'APP主页/首页Tab',
|
|
62
|
+
'CircleMainPage': '圈子/健康圈',
|
|
63
|
+
'MallMainPage': '商城/商城首页',
|
|
64
|
+
'VideoMainPage': '小视频推荐',
|
|
65
|
+
'MemberMainPage': '个人中心/我的',
|
|
66
|
+
'WebViewApp': '通用Web容器',
|
|
67
|
+
'Login': '登录页',
|
|
68
|
+
'VoicePunchIn': '语音打卡',
|
|
69
|
+
'HealthMascot': '健康助手'
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
private constructor() {
|
|
73
|
+
this.sessionId = 'harmony_' + Date.now() + '_' + Math.floor(Math.random() * 9000 + 1000);
|
|
74
|
+
this.deviceId = 'harmony_dev_' + Math.floor(Math.random() * 1000000000);
|
|
75
|
+
this.loadCachedEvents();
|
|
76
|
+
this.startTimer();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static getInstance(): HarmonyTracker {
|
|
80
|
+
if (!HarmonyTracker.instance) {
|
|
81
|
+
HarmonyTracker.instance = new HarmonyTracker();
|
|
82
|
+
}
|
|
83
|
+
return HarmonyTracker.instance;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public init(serverUrl?: string, deviceId?: string, userId?: string, phone?: string, storeName?: string, userName?: string): void {
|
|
87
|
+
if (serverUrl) {
|
|
88
|
+
if (!serverUrl.includes('/api/point/task/trackBatch')) {
|
|
89
|
+
this.serverUrl = serverUrl.endsWith('/') ? serverUrl + 'api/point/task/trackBatch' : serverUrl + '/api/point/task/trackBatch';
|
|
90
|
+
} else {
|
|
91
|
+
this.serverUrl = serverUrl;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (deviceId) this.deviceId = deviceId;
|
|
95
|
+
if (userId) this.userId = userId;
|
|
96
|
+
if (phone) this.phone = phone;
|
|
97
|
+
if (storeName) this.storeName = storeName;
|
|
98
|
+
if (userName) this.userName = userName;
|
|
99
|
+
this.flushAsync();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public updateUser(userId?: string, phone?: string, storeName?: string, userName?: string): void {
|
|
103
|
+
if (userId !== undefined) this.userId = userId;
|
|
104
|
+
if (phone !== undefined) this.phone = phone;
|
|
105
|
+
if (storeName !== undefined) this.storeName = storeName;
|
|
106
|
+
if (userName !== undefined) this.userName = userName;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public setPlatform(pflag: number, platformName?: string): void {
|
|
110
|
+
this.pflag = pflag;
|
|
111
|
+
if (platformName) this.platformName = platformName;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public resetSession(): void {
|
|
115
|
+
this.sequence = 0;
|
|
116
|
+
this.sessionId = 'harmony_' + Date.now() + '_' + Math.floor(Math.random() * 9000 + 1000);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public getSessionId(): string { return this.sessionId; }
|
|
120
|
+
public getDeviceId(): string { return this.deviceId; }
|
|
121
|
+
public getUserId(): string { return this.userId; }
|
|
122
|
+
public getPhone(): string { return this.phone; }
|
|
123
|
+
public getStoreName(): string { return this.storeName; }
|
|
124
|
+
public getUserName(): string { return this.userName; }
|
|
125
|
+
public getPflag(): number { return this.pflag; }
|
|
126
|
+
public getPlatformName(): string { return this.platformName; }
|
|
127
|
+
public getCurrentSequence(): number { return this.sequence; }
|
|
128
|
+
|
|
129
|
+
public getFriendlyTitle(route: string): string {
|
|
130
|
+
if (HarmonyTracker.friendlyTitles[route]) return HarmonyTracker.friendlyTitles[route];
|
|
131
|
+
for (const key in HarmonyTracker.friendlyTitles) {
|
|
132
|
+
if (route.includes(key)) return HarmonyTracker.friendlyTitles[key];
|
|
133
|
+
}
|
|
134
|
+
return route;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public getNativeContextJson(): string {
|
|
138
|
+
const ctx: Record<string, Object> = {
|
|
139
|
+
'appId': this.appId,
|
|
140
|
+
'deviceId': this.deviceId,
|
|
141
|
+
'userId': this.userId,
|
|
142
|
+
'phone': this.phone,
|
|
143
|
+
'sessionId': this.sessionId,
|
|
144
|
+
'appVersion': '1.0.0',
|
|
145
|
+
'platform': 'harmony',
|
|
146
|
+
'os': 'HarmonyOS',
|
|
147
|
+
'brand': deviceInfo.brand || 'HUAWEI',
|
|
148
|
+
'deviceBrand': deviceInfo.brand || 'HUAWEI',
|
|
149
|
+
'model': deviceInfo.productModel || '',
|
|
150
|
+
'deviceModel': deviceInfo.productModel || '',
|
|
151
|
+
'osVersion': deviceInfo.osFullName || '',
|
|
152
|
+
'currentSequence': this.sequence,
|
|
153
|
+
'pflag': this.pflag,
|
|
154
|
+
'pFlagName': this.platformName
|
|
155
|
+
};
|
|
156
|
+
return JSON.stringify(ctx);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public track(eventName: string, properties?: Record<string, Object>): void {
|
|
160
|
+
this.trackCustom(eventName, '', properties);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
public trackCustom(eventName: string, elementText?: string, properties?: Record<string, Object>): void {
|
|
164
|
+
const event = this.createBaseEvent('custom', eventName);
|
|
165
|
+
if (elementText) event.elementText = elementText;
|
|
166
|
+
if (properties) {
|
|
167
|
+
const extra = this.buildBaseExtra();
|
|
168
|
+
for (const k in properties) extra[k] = properties[k];
|
|
169
|
+
event.extraData = JSON.stringify(extra);
|
|
170
|
+
}
|
|
171
|
+
this.enqueueEvent(event);
|
|
172
|
+
this.flushAsync();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public trackPageView(pageRoute: string, pageTitle?: string): void {
|
|
176
|
+
if (pageRoute === this.currentPageRoute && (Date.now() - this.lastPageStartTime < 500)) return;
|
|
177
|
+
this.referrerPageRoute = this.currentPageRoute;
|
|
178
|
+
this.currentPageRoute = pageRoute;
|
|
179
|
+
this.lastPageStartTime = Date.now();
|
|
180
|
+
|
|
181
|
+
const title = pageTitle && pageTitle.length > 0 ? pageTitle : this.getFriendlyTitle(pageRoute);
|
|
182
|
+
const event = this.createBaseEvent('page_view', 'page_view');
|
|
183
|
+
event.pageRoute = pageRoute;
|
|
184
|
+
event.pageTitle = title;
|
|
185
|
+
this.enqueueEvent(event);
|
|
186
|
+
this.flushAsync();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public trackPageStay(pageRoute: string, pageTitle?: string, durationMs?: number): void {
|
|
190
|
+
const dur = durationMs ? durationMs : (Date.now() - this.lastPageStartTime);
|
|
191
|
+
if (dur < 500) return;
|
|
192
|
+
const title = pageTitle && pageTitle.length > 0 ? pageTitle : this.getFriendlyTitle(pageRoute);
|
|
193
|
+
const event = this.createBaseEvent('page_stay', 'page_stay');
|
|
194
|
+
event.pageRoute = pageRoute;
|
|
195
|
+
event.pageTitle = title;
|
|
196
|
+
event.duration = dur;
|
|
197
|
+
this.enqueueEvent(event);
|
|
198
|
+
this.flushAsync();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public trackVideo(eventName: string, videoId: number, videoTitle?: string, customProperties?: Record<string, Object>): void {
|
|
202
|
+
const event = this.createBaseEvent('video', eventName);
|
|
203
|
+
event.elementId = 'video_' + videoId;
|
|
204
|
+
if (videoTitle) event.elementText = videoTitle;
|
|
205
|
+
const extra = this.buildBaseExtra();
|
|
206
|
+
extra['videoId'] = videoId;
|
|
207
|
+
if (videoTitle) extra['videoTitle'] = videoTitle;
|
|
208
|
+
if (customProperties) {
|
|
209
|
+
for (const k in customProperties) extra[k] = customProperties[k];
|
|
210
|
+
if (typeof customProperties['playDurationMs'] === 'number') {
|
|
211
|
+
event.duration = customProperties['playDurationMs'] as number;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
event.extraData = JSON.stringify(extra);
|
|
215
|
+
this.enqueueEvent(event);
|
|
216
|
+
this.flushAsync();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public trackApi(url: string, method: string, statusCode: number, duration: number, reqParam?: string, respData?: string, error?: string): void {
|
|
220
|
+
if (!url || url.includes('/api/point/task/trackBatch')) return;
|
|
221
|
+
const isError = statusCode >= 400 || (error !== undefined && error !== null && error.length > 0);
|
|
222
|
+
const eventType = isError ? 'api_error' : 'api_request';
|
|
223
|
+
const apiPath = this.extractApiPath(url);
|
|
224
|
+
const event = this.createBaseEvent(eventType, apiPath);
|
|
225
|
+
|
|
226
|
+
const extra = this.buildBaseExtra();
|
|
227
|
+
extra['url'] = url;
|
|
228
|
+
extra['apiPath'] = apiPath;
|
|
229
|
+
extra['method'] = (method || 'GET').toUpperCase();
|
|
230
|
+
extra['statusCode'] = statusCode;
|
|
231
|
+
extra['duration'] = duration;
|
|
232
|
+
if (reqParam) extra['requestParams'] = reqParam.substring(0, 2048);
|
|
233
|
+
if (respData) extra['responseData'] = respData.substring(0, 2048);
|
|
234
|
+
if (error) extra['error'] = error.substring(0, 512);
|
|
235
|
+
|
|
236
|
+
event.extraData = JSON.stringify(extra);
|
|
237
|
+
this.enqueueEvent(event);
|
|
238
|
+
if (isError) this.flushAsync();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public trackFrontUrl(frontUrl: string, elementId?: string, postParam?: string): void {
|
|
242
|
+
let eventType = 'click';
|
|
243
|
+
if (elementId && (elementId.startsWith('look') || elementId.startsWith('show') || elementId.includes('Exposure'))) {
|
|
244
|
+
eventType = 'exposure';
|
|
245
|
+
}
|
|
246
|
+
const event = this.createBaseEvent(eventType, 'legacy_dadian');
|
|
247
|
+
event.frontUrl = frontUrl;
|
|
248
|
+
if (elementId) event.elementId = elementId;
|
|
249
|
+
if (postParam) event.postParam = postParam;
|
|
250
|
+
this.enqueueEvent(event);
|
|
251
|
+
this.flushAsync();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private createBaseEvent(eventType: string, eventName: string): TrackerEvent {
|
|
255
|
+
this.sequence++;
|
|
256
|
+
const evt: TrackerEvent = {
|
|
257
|
+
eventId: 'e_' + Date.now() + '_' + Math.floor(Math.random() * 1000),
|
|
258
|
+
eventType: eventType,
|
|
259
|
+
eventName: eventName,
|
|
260
|
+
timestamp: Date.now(),
|
|
261
|
+
sequence: this.sequence,
|
|
262
|
+
sessionId: this.sessionId,
|
|
263
|
+
os: 'HarmonyOS',
|
|
264
|
+
deviceBrand: deviceInfo.brand || 'HUAWEI',
|
|
265
|
+
deviceModel: deviceInfo.productModel || '',
|
|
266
|
+
osVersion: deviceInfo.osFullName || '',
|
|
267
|
+
networkType: this.getNetworkType()
|
|
268
|
+
};
|
|
269
|
+
if (this.userId) evt.userId = this.userId;
|
|
270
|
+
if (this.currentPageRoute) {
|
|
271
|
+
evt.pageRoute = this.currentPageRoute;
|
|
272
|
+
evt.pageTitle = this.getFriendlyTitle(this.currentPageRoute);
|
|
273
|
+
}
|
|
274
|
+
if (this.referrerPageRoute) evt.referrer = this.referrerPageRoute;
|
|
275
|
+
|
|
276
|
+
const baseExtra = this.buildBaseExtra();
|
|
277
|
+
evt.extraData = JSON.stringify(baseExtra);
|
|
278
|
+
return evt;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private buildBaseExtra(): Record<string, Object> {
|
|
282
|
+
const extra: Record<string, Object> = { 'platform': 'harmony' };
|
|
283
|
+
if (this.phone) extra['phone'] = this.phone;
|
|
284
|
+
if (this.storeName) extra['storeName'] = this.storeName;
|
|
285
|
+
if (this.userId) extra['userId'] = this.userId;
|
|
286
|
+
if (this.pflag !== -1) extra['pflag'] = this.pflag;
|
|
287
|
+
if (this.platformName) extra['platformName'] = this.platformName;
|
|
288
|
+
return extra;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private extractApiPath(url: string): string {
|
|
292
|
+
try {
|
|
293
|
+
const qIdx = url.indexOf('?');
|
|
294
|
+
const clean = qIdx >= 0 ? url.substring(0, qIdx) : url;
|
|
295
|
+
const schemeIdx = clean.indexOf('://');
|
|
296
|
+
if (schemeIdx >= 0) {
|
|
297
|
+
const pathIdx = clean.indexOf('/', schemeIdx + 3);
|
|
298
|
+
if (pathIdx >= 0) return clean.substring(pathIdx);
|
|
299
|
+
}
|
|
300
|
+
return clean;
|
|
301
|
+
} catch (e) {
|
|
302
|
+
return url;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private getNetworkType(): string {
|
|
307
|
+
try {
|
|
308
|
+
if (!connection.hasDefaultNetSync()) return '';
|
|
309
|
+
const netHandle = connection.getDefaultNetSync();
|
|
310
|
+
const cap = connection.getNetCapabilitiesSync(netHandle);
|
|
311
|
+
if (cap && cap.bearerTypes) {
|
|
312
|
+
if (cap.bearerTypes.includes(connection.NetBearType.BEARER_WIFI)) return 'wifi';
|
|
313
|
+
if (cap.bearerTypes.includes(connection.NetBearType.BEARER_CELLULAR)) return '4g';
|
|
314
|
+
if (cap.bearerTypes.includes(connection.NetBearType.BEARER_ETHERNET)) return 'ethernet';
|
|
315
|
+
}
|
|
316
|
+
return 'other';
|
|
317
|
+
} catch (e) {
|
|
318
|
+
return '';
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private enqueueEvent(event: TrackerEvent): void {
|
|
323
|
+
this.eventQueue.push(event);
|
|
324
|
+
if (this.eventQueue.length > HarmonyTracker.MAX_QUEUE_SIZE) {
|
|
325
|
+
this.eventQueue.splice(0, this.eventQueue.length - HarmonyTracker.MAX_QUEUE_SIZE);
|
|
326
|
+
}
|
|
327
|
+
this.saveQueueToDisk();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private async saveQueueToDisk(): Promise<void> {
|
|
331
|
+
try {
|
|
332
|
+
const util = new PreferencesUtil();
|
|
333
|
+
await util.saveCache(HarmonyTracker.CACHE_KEY, JSON.stringify(this.eventQueue));
|
|
334
|
+
} catch (e) {}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private async loadCachedEvents(): Promise<void> {
|
|
338
|
+
try {
|
|
339
|
+
const util = new PreferencesUtil();
|
|
340
|
+
const cache = await util.getCache(HarmonyTracker.CACHE_KEY);
|
|
341
|
+
if (cache && typeof cache === 'string') {
|
|
342
|
+
const parsed = JSON.parse(cache) as Array<TrackerEvent>;
|
|
343
|
+
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
344
|
+
this.eventQueue = parsed.concat(this.eventQueue);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
} catch (e) {}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private startTimer(): void {
|
|
351
|
+
if (this.flushTimerId !== -1) return;
|
|
352
|
+
this.flushTimerId = setInterval(() => {
|
|
353
|
+
this.flushAsync();
|
|
354
|
+
}, HarmonyTracker.FLUSH_INTERVAL_MS);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public flushAsync(): void {
|
|
358
|
+
if (this.isFlushing || this.eventQueue.length === 0) return;
|
|
359
|
+
this.flushInternal();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
public async flushSync(): Promise<void> {
|
|
363
|
+
await this.flushInternal();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
private async flushInternal(): Promise<void> {
|
|
367
|
+
if (this.isFlushing || this.eventQueue.length === 0) return;
|
|
368
|
+
this.isFlushing = true;
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
let maxBatches = 5;
|
|
372
|
+
while (maxBatches-- > 0 && this.eventQueue.length > 0) {
|
|
373
|
+
const batch = this.eventQueue.slice(0, HarmonyTracker.BATCH_SIZE);
|
|
374
|
+
const success = await this.sendBatch(batch);
|
|
375
|
+
if (success) {
|
|
376
|
+
this.eventQueue.splice(0, batch.length);
|
|
377
|
+
await this.saveQueueToDisk();
|
|
378
|
+
} else {
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
} finally {
|
|
383
|
+
this.isFlushing = false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private async sendBatch(records: Array<TrackerEvent>): Promise<boolean> {
|
|
388
|
+
if (!this.serverUrl || records.length === 0) return false;
|
|
389
|
+
const httpRequest = http.createHttp();
|
|
390
|
+
|
|
391
|
+
try {
|
|
392
|
+
let batchSessionId = this.sessionId;
|
|
393
|
+
let batchUserId = this.userId;
|
|
394
|
+
if (records[0].sessionId) batchSessionId = records[0].sessionId;
|
|
395
|
+
if (records[0].userId) batchUserId = records[0].userId;
|
|
396
|
+
|
|
397
|
+
const body: Record<string, Object> = {
|
|
398
|
+
'appId': parseInt(this.appId, 10),
|
|
399
|
+
'sessionId': batchSessionId,
|
|
400
|
+
'deviceId': this.deviceId,
|
|
401
|
+
'userId': batchUserId,
|
|
402
|
+
'phone': this.phone,
|
|
403
|
+
'storeName': this.storeName,
|
|
404
|
+
'userName': this.userName,
|
|
405
|
+
'platform': 'harmony',
|
|
406
|
+
'events': records
|
|
407
|
+
};
|
|
408
|
+
if (this.pflag !== -1) body['pflag'] = this.pflag;
|
|
409
|
+
if (this.platformName) body['platformName'] = this.platformName;
|
|
410
|
+
|
|
411
|
+
const bodyStr = JSON.stringify(body);
|
|
412
|
+
const options: http.HttpRequestOptions = {
|
|
413
|
+
method: http.RequestMethod.POST,
|
|
414
|
+
header: {
|
|
415
|
+
'Content-Type': 'application/json; charset=UTF-8',
|
|
416
|
+
'appId': this.appId,
|
|
417
|
+
'deviceId': this.deviceId
|
|
418
|
+
},
|
|
419
|
+
extraData: bodyStr,
|
|
420
|
+
expectDataType: http.HttpDataType.STRING,
|
|
421
|
+
connectTimeout: 5000,
|
|
422
|
+
readTimeout: 5000
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const resp = await httpRequest.request(this.serverUrl, options);
|
|
426
|
+
return resp.responseCode >= 200 && resp.responseCode < 300;
|
|
427
|
+
} catch (e) {
|
|
428
|
+
hilog.error(HarmonyTracker.LOG_DOMAIN, HarmonyTracker.LOG_TAG, 'sendBatch failed: %{public}s', JSON.stringify(e));
|
|
429
|
+
return false;
|
|
430
|
+
} finally {
|
|
431
|
+
httpRequest.destroy();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|