react-native-quicktracking-analytics-module 1.0.0-beta.2 → 1.0.0

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # 集成
2
- QT React Native 埋点SDK是基于Quick Tracking 原生客户端SDK上的扩展,封装了埋点常用的api,如全局属性、页面属性、自定义事件等,需要分别在RN、Android、iOS三端做集成。
1
+ # 集成说明
2
+ > QuickTracking React Native SDK是基于QuickTracking 原生客户端埋点SDK上的扩展,封装了QT埋点常用的api,如全局属性、页面属性、自定义事件等,需要分别在RN、Android、iOS三端做集成。
3
3
 
4
- ## React Native 集成
5
- ### 下载npm包到项目中
4
+ # React Native SDK集成
5
+ ## 下载npm包到项目中
6
6
  ```bash
7
7
  # npm
8
8
  npm install react-native-quicktracking-analytics-module
@@ -13,20 +13,18 @@ yarn add react-native-quicktracking-analytics-module
13
13
  # pnpm
14
14
  pnpm add react-native-quicktracking-analytics-module
15
15
  ```
16
-
17
- ### 引入QT类
16
+ ## 引入SDK环境变量
18
17
  ```tsx
19
18
  import { QT } from "react-native-quicktracking-analytics-module";
20
19
  ```
21
-
22
- ## Android 集成
20
+ ## Android 基座集成
23
21
  ### 进入控制台
24
22
  进入QT后台,点击“管理控制台”
25
- ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/220937/1646903919683-276177f8-42a7-4f6e-87aa-fff88ae87a77.png#clientId=u468f5541-19bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=790&id=EZloP&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1580&originWidth=2878&originalType=binary&ratio=1&rotation=0&showTitle=false&size=2103957&status=done&style=none&taskId=ua2f5b36f-3995-47d2-909b-a42abba8f55&title=&width=1439)
23
+ ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/220937/1646903919683-276177f8-42a7-4f6e-87aa-fff88ae87a77.png#clientId=u468f5541-19bf-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=790&id=VqtE7&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1580&originWidth=2878&originalType=binary&ratio=1&rotation=0&showTitle=false&size=2103957&status=done&style=none&taskId=ua2f5b36f-3995-47d2-909b-a42abba8f55&title=&width=1439)
26
24
 
27
25
  ### 集成应用
28
26
  找到需要集成埋点的应用:进入“应用列表”,选择所需组织,点击操作中的“详情或者去集成”
29
- ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/220937/1646904230482-8878cb3e-71d7-4514-a6a8-4e0b6b2322c0.png#clientId=u468f5541-19bf-4&crop=0&crop=0.1396&crop=1&crop=1&from=paste&height=788&id=dcFuI&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1576&originWidth=2880&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1188843&status=done&style=none&taskId=uc344d9e4-34d9-4702-9b3a-fcec5a8a04c&title=&width=1440)
27
+ ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/64356327/1668567046473-aab9b13d-38fe-4e33-bd03-e5bedc69b0e4.png#clientId=uf7b76841-8b1b-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=602&id=ub77f00bf&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1204&originWidth=2562&originalType=binary&ratio=1&rotation=0&showTitle=false&size=646074&status=done&style=none&taskId=ube368388-293d-4ce2-a7ad-9aca1566a87&title=&width=1281)
30
28
 
31
29
  ### Maven地址配置
32
30
  在工程 build.gradle 配置脚本中 buildscript 和 allprojects 段中添加 sdk maven 仓库地址
@@ -151,19 +149,87 @@ QtConfigure.init(this,"appkey","unknown",UMConfigure.DEVICE_TYPE_PHONE, "");
151
149
  ```
152
150
 
153
151
 
154
- ## iOS集成
155
- 注意您的ruby版本,MacOS自带的Ruby为2.6.8,不符合RN项目需求。
156
- 建议在本地终端中执行 ruby --version,并下载ruby包管理器,如rbenv或rvm等,改成ruby版本为RN需要的[版本](https://github.com/facebook/react-native/blob/main/template/_ruby-version)
157
-
158
-
159
-
152
+ ## iOS 基座集成
153
+ ### 使用CocoaPods集成
154
+ 进入iOS工程目录
155
+ ```shell
156
+ cd ios && pod install && cd ..
157
+ ```
158
+ ### SDK初始化并集成appKey
159
+ 为保证您的App在集成统计SDK之后,能够满足工信部相关合规要求,您应确保App首次冷启动时,在用户阅读您的《隐私政策》并取得用户授权之后,才调用正式初始化函数初始化统计SDK,此时SDK才会真正采集设备信息并上报数据。反之,如果用户不同意《隐私政策》授权,则不能调用初始化函数
160
+ ```objectivec
161
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
162
+ {
163
+ ...
164
+ /** 初始化所有组件产品
165
+ @param appKey 开发者在QT申请的appkey.
166
+ @param channel 渠道标识,可设置nil表示"App Store".
167
+ */
168
+ [QTConfigure initWithAppkey:@"应用的appKey" channel:@"安装渠道"];
169
+ ...
170
+ return YES;
171
+ }
172
+ ```
173
+ 一旦App获取到《隐私政策》的用户授权,后续的App冷启动,开发者应该保证调用到初始化函数。
174
+ ### 配置收数域名
175
+ ```objectivec
176
+ #import <QTCommon/UMConfigure.h>
177
+
178
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
179
+ {
180
+ ...
181
+ /** 设置上报统计日志的主域名和备用域名。此函数必须在SDK初始化函数调用之前调用。
182
+ @param primaryDomain 传日志的主域名收数地址,参数不能为null或者空串。例如:https://www.umeng.com
183
+ @param standbyDomain 上传日志备用域名收数地址,参数可以为null或者空串,若此参数为空,SDK内部会自动将主域名设置为备用域名。
184
+ */
185
+
186
+ [QTConfigure setCustomDomain:@"主收数域名" standbyDomain:@"备用收数域名"];
187
+ ...
188
+ return YES;
189
+ }
190
+ ```
191
+ ### 按需引入日志组件
192
+ 引入统计所需组件库(在更新SDK时,您可以直接使用 pod update 命令进行直接更新)
193
+ ```objectivec
194
+ pod 'UMCCommonLog'
195
+ ```
196
+ Podfile示例
197
+ ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/281773/1668518339815-d4ccb536-a399-4341-ba2c-902dcf24b1da.png#clientId=uf686b11a-7b20-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=564&id=u6a3e4c24&margin=%5Bobject%20Object%5D&name=image.png&originHeight=571&originWidth=751&originalType=binary&ratio=1&rotation=0&showTitle=false&size=80695&status=done&style=none&taskId=ub00bc826-f430-4519-9921-c4040b208a7&title=&width=741.5)
198
+ 开启日志打印
199
+ ```objectivec
200
+ #import <QTCommon/UMConfigure.h>
201
+ #import <UMCommonLog/UMCommonLogHeaders.h>
202
+
203
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
204
+ {
205
+ ...
206
+ [UMCommonLogManager setUpUMCommonLogManager];
207
+ [QTConfigure setLogEnabled:YES];
208
+ ...
209
+ return YES;
210
+ }
211
+ ```
212
+ ### 埋点验证配置
213
+ 添加您的 URL Scheme 到项目中,URL Scheme 位于项目设置 target -> 选项卡 Info - > URL Types。
214
+ 填入的scheme:atm.yourappkey。
215
+ ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2022/png/281773/1668518096477-d9471acb-e7d0-4bba-8590-15891559b6b6.png#clientId=uf686b11a-7b20-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=412&id=ub7bbb0cc&margin=%5Bobject%20Object%5D&name=image.png&originHeight=823&originWidth=1366&originalType=binary&ratio=1&rotation=0&showTitle=false&size=127257&status=done&style=none&taskId=u9c88f1a5-85f6-4db1-a079-1dbef87724e&title=&width=683)
216
+ 在AppDelegate中调用函数[QTMobClick handleUrl:url]来接收 URL
217
+ ```objectivec
218
+ - (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
219
+ {
220
+ if ([QTMobClick handleUrl:url]) {
221
+ return YES;
222
+ }
223
+ return YES;
224
+ }
160
225
 
161
- # 埋点
226
+ ```
227
+ # 埋点API
162
228
  ## 用户账号上报
163
229
  ### 用户登录
164
230
  该值的上传对应产品中“登录用户”:计算“登录用户”数,就是计算下述API上传值的去重数
165
231
  ```typescript
166
- function profileSignIn(ID: string, provider?: string) {}
232
+ function profileSignIn(ID: string, provider?: string): void
167
233
  ```
168
234
  | 参数 | 含义 |
169
235
  | --- | --- |
@@ -175,24 +241,19 @@ function profileSignIn(ID: string, provider?: string) {}
175
241
  ### 用户登出
176
242
  账号登出时需调用此接口,调用之后不再发送账号相关内容。
177
243
  ```typescript
178
- function profileSignOff(ID: string, provider?: string)
244
+ function profileSignOff(): void
179
245
  ```
180
246
 
181
247
  示例:
182
248
  ```typescript
183
- const profileSignIn = () => {
184
- QT.profileSignIn('用户ID');
185
- };
186
-
187
- const profileSignOff = () => {
188
- QT.profileSignOff();
189
- };
249
+ QT.profileSignIn('用户ID');
250
+ QT.profileSignOff();
190
251
  ```
191
252
 
192
253
  ## 用户属性上传
193
254
  使用事件编码固定为"$$_user_profile"的自定义事件上传,该事件所携带的事件属性会被作为用户属性放在用户表中。
194
255
  ```typescript
195
- function sendEvent(eventId: string, params: any)
256
+ function sendEvent(eventId: string, params: any): void
196
257
  ```
197
258
  | 参数 | 含义 |
198
259
  | --- | --- |
@@ -216,31 +277,34 @@ QT.sendEvent("$$_user_profile", user);
216
277
  全局属性为每一个事件都会携带的属性
217
278
  ### 注册全局属性
218
279
  ```java
219
- function registerGlobalProperty(globalProperty: any) {}
280
+ function registerGlobalProperty(globalProperty: any): void
220
281
  ```
221
282
  | 参数 | 含义 |
222
283
  | --- | --- |
223
- | globalProperty | 要注册的全局属性,定义为“属性名:属性值”的“<键-值>”对 |
284
+ | globalProperty | 要注册的全局属性,定义为“属性名:属性值”的“<键-值>”对。为单层对象结构,不支持多层嵌套。 |
224
285
 
225
286
  **注意:**
226
287
 
227
288
  1. 属性名、string类型的属性值,只支持大小写字母、数字及下划线。
228
- 2. 在Android中,不支持JavaScript的boolean类型,需要手动在JS中转为0、1。
289
+ 2. 在Android中,属性值不支持JavaScript的boolean类型,需要手动在JS中转为0、1。
229
290
  3. 在Android中,对于全局属性值为null或undefined的场景,底层Android sdk会过滤这个全局属性字段,如需要空值分析场景,需自定义默认空值
230
291
  4. 在iOS中,全局属性值不支持null和undefined,需要手动过滤。
231
292
 
232
293
  示例:
233
294
  ```typescript
234
295
  QT.registerGlobalProperty({
235
- name: 'MyApp',
236
- description: 'this is a app',
237
- }
238
- );
296
+ name: 'MyApp',
297
+ description: 'this is a app',
298
+ aBoolean: 1, //boolean类型需传为0或1,
299
+ aNull: '', //null或undefined类型需传空字符串
300
+ //默认为number类型,对于返回值为null或undefined场景,需业务自定义数值型默认空值
301
+ aNumber: 66,
302
+ });
239
303
  ```
240
304
 
241
305
  ### 删除特定的全局属性
242
306
  ```java
243
- function unRegisterGlobalProperty(propertyName: string) {}
307
+ function unregisterGlobalProperty(propertyName: string): void
244
308
  ```
245
309
  | 参数 | 含义 |
246
310
  | --- | --- |
@@ -253,7 +317,7 @@ function unRegisterGlobalProperty(propertyName: string) {}
253
317
 
254
318
  ### 获取特定的全局属性
255
319
  ```java
256
- function getGlobalProperty(propertyName: string) {}
320
+ async function getGlobalProperty(propertyName: string): Promise<any>
257
321
  ```
258
322
  | 参数 | 含义 |
259
323
  | --- | --- |
@@ -261,12 +325,23 @@ function getGlobalProperty(propertyName: string) {}
261
325
 
262
326
  示例:
263
327
  ```typescript
264
- QT.getGlobalProperty('name'); // 获取全局属性name,返回 {name: "MyApp"}
328
+ await QT.getGlobalProperty('name'); // 获取全局属性name,返回 {name: "MyApp"}
329
+ ```
330
+
331
+ ### 获取所有全局属性
332
+ ```java
333
+ async function getGlobalProperties(propertyName: string): Promise<any>
334
+ ```
335
+
336
+ 示例:
337
+ ```typescript
338
+ await QT.getGlobalProperties(); // 获取所有全局属性
265
339
  ```
266
340
 
341
+
267
342
  ### 清除所有全局属性
268
343
  ```java
269
- function clearGlobalProperties() {}
344
+ function clearGlobalProperties(): void
270
345
  ```
271
346
  示例:
272
347
  ```tsx
@@ -277,8 +352,8 @@ QT.clearGlobalProperties(); // 所有全局属性都被清除(慎用)
277
352
  ## 页面浏览事件埋点
278
353
  开发者如果希望对页面路径和页面停留时长进行采集和统计。可以通过调用该接口手动埋点
279
354
  ```typescript
280
- function onPageStart(pageName: string) {}
281
- function onPageEnd(pageName: string) {}
355
+ function onPageStart(pageName: string): void
356
+ function onPageEnd(pageName: string): void
282
357
  ```
283
358
  | 参数 | 含义 |
284
359
  | --- | --- |
@@ -286,12 +361,8 @@ function onPageEnd(pageName: string) {}
286
361
 
287
362
  示例:
288
363
  ```typescript
289
- const onPageStart = () => {
290
- QT.onPageStart('MainPage');
291
- };
292
- const onPageEnd = () => {
293
- QT.onPageEnd('MainPage');
294
- };
364
+ QT.onPageStart('MainPage');
365
+ QT.onPageEnd('MainPage');
295
366
  ```
296
367
  注意:
297
368
  onPageStart 和 onPageEnd 必须成对调用。
@@ -305,21 +376,19 @@ onPageStart 和 onPageEnd 必须成对调用。
305
376
  * @param eventId 当前统计的事件ID
306
377
  * @param params 对当前事件的参数描述,定义为“参数名:参数值”的“<键-值>”对
307
378
  */
308
- function sendEvent(eventId: string, params: any) {}
379
+ function sendEvent(eventId: string, params: any): void
309
380
  ```
310
381
  | 参数 | 含义 |
311
382
  | --- | --- |
312
383
  | eventId | 为当前统计的事件ID。 |
313
- | params | 对当前事件的参数描述,定义为“参数名:参数值”的“<键-值>对”。 |
384
+ | params | 对当前事件的参数描述,定义为“参数名:参数值”的“<键-值>对”。为单层对象结构,不支持多层嵌套。 |
314
385
 
315
386
  **示例:**
316
387
  ```typescript
317
- const sendEvent = () => {
318
- QT.sendEvent('my_event', {
319
- name: 'app_name',
320
- options: 'xxx',
321
- });
322
- };
388
+ QT.sendEvent('my_event', {
389
+ name: 'app_name',
390
+ options: 'xxx',
391
+ });
323
392
  ```
324
393
  > **_备注:_**
325
394
  > - 多参数类型事件能满足原来计算事件/计数事件的分析场景;
@@ -334,19 +403,118 @@ const sendEvent = () => {
334
403
  2. 在Android中,对于全局属性值为null或undefined的场景,底层Android sdk会过滤这个全局属性字段,如需要空值分析场景,需自定义默认空值
335
404
  3. 在iOS中,全局属性值不支持null和undefined,需要手动过滤。
336
405
 
337
- ## RN App中嵌入h5页面
338
- 集成:
339
- 桥接:
406
+ ## 桥接事件埋点
407
+ 桥接事件用于h5桥接RN的场景,使用此接口将H5日志发送至App中。
408
+ ```typescript
340
409
 
410
+ /**
411
+ * 桥接事件埋点
412
+ * @param data H5转发事件的日志体
413
+ */
414
+ function sendEventForH5(data: string): void
415
+ ```
416
+ | 参数 | 含义 |
417
+ | --- | --- |
418
+ | data | H5转发事件的日志体 |
419
+
420
+ **示例:**
421
+ ```typescript
422
+ const content = data.nativeEvent.data;
423
+ QT.sendEventForH5(content);
424
+ ```
425
+
426
+ # RN App中嵌入h5页面(RN桥接模式)
427
+ ## H5集成 QuickTracking Web SDK
428
+ 该步骤请参考[QuickTrackingWeb SDK集成手册](https://help.aliyun.com/document_detail/428531.html)
429
+ ## 转发H5端发送的日志给React Native WebView
430
+ ```javascript
431
+ <script charset="UTF-8">
432
+ ...
433
+ // sdk接入及配置部分
434
+ ...
435
+
436
+ //转发页面自定义事件(点击、元素曝光、其他)
437
+ aplus_queue.push({
438
+ action: 'aplus.aplus_pubsub.subscribe',
439
+ arguments: ['mw_change_hjlj', function (content) {
440
+ var eventData = content && content.what_to_send && content.what_to_send.hjljdataToUmNative;
441
+ if (/*iOS环境*/) {
442
+ window.ReactNativeWebView.postMessage(JSON.stringify(eventData), '*');
443
+ } else {
444
+ window.ReactNativeWebView.postMessage(JSON.stringify(eventData));
445
+ }
446
+ }]
447
+ })
448
+
449
+ aplus_queue.push({
450
+ action: 'aplus.aplus_pubsub.subscribe',
451
+ arguments: ['mw_change_pv', function (content) {
452
+ var pvData = content && content.what_to_send && content.what_to_send.pvdataToUmNative;
453
+ if (/*iOS环境*/) {
454
+ window.ReactNativeWebView.postMessage(JSON.stringify(pvData), '*');
455
+ } else {
456
+ window.ReactNativeWebView.postMessage(JSON.stringify(pvData));
457
+ }
458
+ }]
459
+ })
460
+ </script>
461
+ ```
462
+ ## React Native WebView接收消息并调用QT SDK上报日志
463
+ ```javascript
464
+ import * as React from 'react'
465
+ import { WebView } from 'react-native-webview';
466
+ import { QT } from 'react-native-quicktracking-analytics-module';
467
+ import { Platform, SafeAreaView } from 'react-native';
468
+
469
+ export default function WebPage() {
470
+ const onMessage = (data) => {
471
+ try {
472
+ const content = data.nativeEvent.data;
473
+ QT.sendEventForH5(content);
474
+ } catch (error) {
475
+ console.log('webview message error:', error);
476
+ }
477
+ };
478
+ ...
479
+ return (
480
+ <SafeAreaView style={{ flex: 1 }}>
481
+ <WebView
482
+ ...
483
+ onMessage={onMessage}
484
+ ...
485
+ />
486
+ </SafeAreaView>
487
+ );
488
+ }
489
+ ```
341
490
  # FAQ
342
- ### 控制台提示[APLUS] -- jsbridge Android environment error, Umeng4Aplus = undefined
491
+ ## Umeng4Plus为空
492
+ 控制台提示[APLUS] -- jsbridge Android environment error, Umeng4Aplus = undefined
343
493
  Umeng4Plus是桥接的环境变量,若提示undefined,说明在原生端未接入桥接功能,请找负责Android或iOS的同学对接。
344
494
 
495
+ ## ruby版本过低
496
+ 进入项目时提示,Required ruby-2.7.5 is not installed. To install do: 'rvm install "ruby-2.7.5"'
497
+ 注意您的ruby版本,MacOS自带的Ruby为2.6.8,不符合RN项目需求。
498
+ 建议在本地终端中执行 ruby --version
499
+ 下载ruby包管理器,如rbenv或rvm等,改成ruby版本为RN需要的[版本](https://github.com/facebook/react-native/blob/main/template/_ruby-version)
500
+ ```shell
501
+ rvm install 2.7.5
502
+ rvm use 2.7.5
503
+ ```
504
+
505
+
506
+ ## 嵌入的html可以收发数,但Android端不能
507
+ 查看Android Manifest里有没有配置网络权限。
508
+
509
+ # 参考
510
+ > [QuickTracking Android SDK集成手册](https://help.aliyun.com/document_detail/260238.html)
511
+ >
512
+ > [QuickTracking iOS SDK集成手册](https://help.aliyun.com/document_detail/260233.html)
513
+ >
514
+ > [React Native Android 本地模块](https://reactnative.dev/docs/native-modules-android)
515
+ >
516
+ > [React Native iOS 本地模块](https://reactnative.dev/docs/native-modules-ios)
345
517
 
346
- ## 详细文档请参考
347
- 1. [Quicktracking iOS 集成文档](https://help.aliyun.com/document_detail/260230.html)
348
- 2. [Quicktracking Android 集成文档](https://help.aliyun.com/document_detail/260235.html)
349
- 3. [QuickTracking H5 集成文档](https://help.aliyun.com/document_detail/252737.html)
350
518
 
351
519
 
352
520
 
@@ -28,7 +28,7 @@ import com.quick.qt.spm.SpmAgent;
28
28
  @ReactModule(name = QuicktrackingAnalyticsModuleModule.NAME)
29
29
  public class QuicktrackingAnalyticsModuleModule extends ReactContextBaseJavaModule {
30
30
  public static final String NAME = "QuicktrackingAnalyticsModule";
31
- public static final String TAG = "GlobalProperty";
31
+ public static final String TAG = "QuickTracking == ";
32
32
  private ReactApplicationContext context;
33
33
 
34
34
  public QuicktrackingAnalyticsModuleModule(ReactApplicationContext reactContext) {
@@ -77,8 +77,13 @@ public class QuicktrackingAnalyticsModuleModule extends ReactContextBaseJavaModu
77
77
  }
78
78
 
79
79
  @ReactMethod
80
- public void onEventForH5(String params) {
81
- SpmAgent.CALL(params);
80
+ public void onEventForH5(String content) {
81
+ try {
82
+ // android.util.Log.e(TAG, " " + content);
83
+ SpmAgent.CALL(content);
84
+ } catch (Exception e) {
85
+ android.util.Log.e(TAG, "桥接事件发送失败!", e);
86
+ }
82
87
  }
83
88
 
84
89
  @ReactMethod
package/ios/.DS_Store ADDED
Binary file
@@ -58,13 +58,15 @@ class QT {
58
58
  QuicktrackingAnalyticsModule.onEventForH5(JSON.stringify({
59
59
  params: json,
60
60
  methodName: 'sendPV',
61
- sid: `${Date.now()}`
61
+ sid: `${Date.now()}`,
62
+ className: 'Umeng4Aplus'
62
63
  }));
63
64
  } else {
64
65
  QuicktrackingAnalyticsModule.onEventForH5(JSON.stringify({
65
66
  params: json,
66
67
  methodName: 'sendEvent',
67
- sid: `${Date.now()}`
68
+ sid: `${Date.now()}`,
69
+ className: 'Umeng4Aplus'
68
70
  }));
69
71
  }
70
72
  }
@@ -82,7 +84,15 @@ class QT {
82
84
  */
83
85
  static registerGlobalProperty(gp) {
84
86
  if (_reactNative.Platform.OS === 'ios') {
85
- QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
87
+ Object.keys(gp).forEach((_propertyName, propertyValue) => {
88
+ if (!propertyValue && propertyValue !== 0) {
89
+ console.warn('属性值不能为null或undefined');
90
+ } else if (typeof propertyValue === 'object') {
91
+ console.warn('全局属性只能是单层对象');
92
+ } else {
93
+ QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
94
+ }
95
+ });
86
96
  } else {
87
97
  QuicktrackingAnalyticsModule.registerGlobalProperties(gp);
88
98
  }
@@ -52,13 +52,15 @@ export class QT {
52
52
  QuicktrackingAnalyticsModule.onEventForH5(JSON.stringify({
53
53
  params: json,
54
54
  methodName: 'sendPV',
55
- sid: `${Date.now()}`
55
+ sid: `${Date.now()}`,
56
+ className: 'Umeng4Aplus'
56
57
  }));
57
58
  } else {
58
59
  QuicktrackingAnalyticsModule.onEventForH5(JSON.stringify({
59
60
  params: json,
60
61
  methodName: 'sendEvent',
61
- sid: `${Date.now()}`
62
+ sid: `${Date.now()}`,
63
+ className: 'Umeng4Aplus'
62
64
  }));
63
65
  }
64
66
  }
@@ -76,7 +78,15 @@ export class QT {
76
78
  */
77
79
  static registerGlobalProperty(gp) {
78
80
  if (Platform.OS === 'ios') {
79
- QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
81
+ Object.keys(gp).forEach((_propertyName, propertyValue) => {
82
+ if (!propertyValue && propertyValue !== 0) {
83
+ console.warn('属性值不能为null或undefined');
84
+ } else if (typeof propertyValue === 'object') {
85
+ console.warn('全局属性只能是单层对象');
86
+ } else {
87
+ QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
88
+ }
89
+ });
80
90
  } else {
81
91
  QuicktrackingAnalyticsModule.registerGlobalProperties(gp);
82
92
  }
@@ -1,3 +1,5 @@
1
+ declare type GlobalProperty = Record<string, string | number>;
2
+ declare type EventParams = Record<string, string | number>;
1
3
  /**
2
4
  *引入 QuickTracking SDK
3
5
  */
@@ -17,7 +19,7 @@ export declare class QT {
17
19
  * @param eventId 当前统计的事件ID
18
20
  * @param params 对当前事件的参数描述,定义为“参数名:参数值”的“<键-值>”对
19
21
  */
20
- static sendEvent(eventId: string, params: any): void;
22
+ static sendEvent(eventId: string, params: EventParams): void;
21
23
  /**
22
24
  * 桥接事件埋点
23
25
  * @param data H5转发事件的日志体
@@ -30,7 +32,7 @@ export declare class QT {
30
32
  * 且这些属性及属性值存入缓存,APP退出后清除。
31
33
  * 在分析数据时,可根据此属性进行查看和筛选。
32
34
  */
33
- static registerGlobalProperty(gp: any): void;
35
+ static registerGlobalProperty(gp: GlobalProperty): void;
34
36
  /**
35
37
  * 删除一个全局事件属性
36
38
  * @param propertyName 要删除的全局事件属性名,只支持大小写字母、数字及下划线
@@ -60,3 +62,4 @@ export declare class QT {
60
62
  */
61
63
  static profileSignOff(): void;
62
64
  }
65
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-quicktracking-analytics-module",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0",
4
4
  "description": "QuickTracking ReactNative SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.tsx CHANGED
@@ -1,5 +1,9 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
  const QuicktrackingAnalyticsModule = NativeModules.QuicktrackingAnalyticsModule;
3
+
4
+ type GlobalProperty = Record<string, string | number>;
5
+ type EventParams = Record<string, string | number>;
6
+
3
7
  /**
4
8
  *引入 QuickTracking SDK
5
9
  */
@@ -25,7 +29,7 @@ export class QT {
25
29
  * @param eventId 当前统计的事件ID
26
30
  * @param params 对当前事件的参数描述,定义为“参数名:参数值”的“<键-值>”对
27
31
  */
28
- static sendEvent(eventId: string, params: any) {
32
+ static sendEvent(eventId: string, params: EventParams) {
29
33
  if (params) {
30
34
  QuicktrackingAnalyticsModule.onEventObject(eventId, params);
31
35
  } else {
@@ -54,6 +58,7 @@ export class QT {
54
58
  params: json,
55
59
  methodName: 'sendPV',
56
60
  sid: `${Date.now()}`,
61
+ className: 'Umeng4Aplus',
57
62
  })
58
63
  );
59
64
  } else {
@@ -62,6 +67,7 @@ export class QT {
62
67
  params: json,
63
68
  methodName: 'sendEvent',
64
69
  sid: `${Date.now()}`,
70
+ className: 'Umeng4Aplus',
65
71
  })
66
72
  );
67
73
  }
@@ -78,9 +84,17 @@ export class QT {
78
84
  * 且这些属性及属性值存入缓存,APP退出后清除。
79
85
  * 在分析数据时,可根据此属性进行查看和筛选。
80
86
  */
81
- static registerGlobalProperty(gp: any) {
87
+ static registerGlobalProperty(gp: GlobalProperty) {
82
88
  if (Platform.OS === 'ios') {
83
- QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
89
+ Object.keys(gp).forEach((_propertyName, propertyValue) => {
90
+ if (!propertyValue && propertyValue !== 0) {
91
+ console.warn('属性值不能为null或undefined');
92
+ } else if (typeof propertyValue === 'object') {
93
+ console.warn('全局属性只能是单层对象');
94
+ } else {
95
+ QuicktrackingAnalyticsModule.registerGlobalProperty(gp);
96
+ }
97
+ });
84
98
  } else {
85
99
  QuicktrackingAnalyticsModule.registerGlobalProperties(gp);
86
100
  }