gio-miniprogram-sdk 4.0.1 → 4.1.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/dist/alipay.js +1 -1
- package/dist/baidu.js +1 -1
- package/dist/bytedance.js +1 -1
- package/dist/jingdong.js +1 -1
- package/dist/kuaishou.js +1 -1
- package/dist/plugins/gioABTest.js +1 -1
- package/dist/plugins/gioCompress.js +1 -1
- package/dist/plugins/gioEventAutoTracking.js +1 -1
- package/dist/plugins/gioImpressionTracking.js +1 -1
- package/dist/plugins/gioMultipleInstances.js +1 -0
- package/dist/qq.js +1 -1
- package/dist/quickapp.js +1 -1
- package/dist/taobao.js +1 -1
- package/dist/taro.js +1 -1
- package/dist/uniapp.js +1 -1
- package/dist/wechat.js +1 -1
- package/package.json +39 -42
- package/rollup.config.js +11 -6
- package/rollup.plugins.config.js +13 -10
- package/src/{pluginsOut/frameworks → adapters}/gioTaobaoAdapter.ts +47 -43
- package/src/{pluginsOut/frameworks → adapters}/gioTaroAdapter.ts +4 -4
- package/src/{pluginsOut/frameworks → adapters}/gioUniAppAdapter.ts +35 -6
- package/src/constants/config.ts +47 -18
- package/src/constants/emitMsg.ts +23 -0
- package/src/constants/regex.ts +0 -1
- package/src/core/dataStore/eventContextBuilder.ts +28 -17
- package/src/core/dataStore/eventHooks/appEffects.ts +50 -31
- package/src/core/dataStore/eventHooks/index.ts +7 -5
- package/src/core/dataStore/eventHooks/minipPage.ts +2 -11
- package/src/core/dataStore/eventHooks/pageEffects.ts +61 -27
- package/src/core/dataStore/index.ts +263 -185
- package/src/core/growingIO.ts +312 -178
- package/src/core/pluginsInstance/base.ts +157 -0
- package/src/core/pluginsInstance/taro.ts +15 -0
- package/src/core/pluginsInstance/tb.ts +15 -0
- package/src/core/pluginsInstance/uniapp.ts +15 -0
- package/src/core/uploader.ts +131 -82
- package/src/core/userStore.ts +160 -121
- package/src/index.ts +37 -28
- package/src/minipInstance/base.ts +2 -1
- package/src/minipInstance/quickapp.ts +5 -19
- package/src/platformConfig/base.ts +0 -4
- package/src/{pluginsOut/ordinary → plugins}/gioABTest.ts +74 -37
- package/src/{pluginsOut/ordinary → plugins}/gioEventAutoTracking.ts +25 -18
- package/src/{pluginsOut/ordinary → plugins}/gioImpressionTracking.ts +55 -22
- package/src/plugins/gioMultipleInstances.ts +176 -0
- package/src/types/base.ts +10 -3
- package/src/types/dataStore.ts +31 -16
- package/src/types/eventHooks.ts +5 -6
- package/src/types/growingIO.ts +30 -14
- package/src/types/platforms.ts +0 -4
- package/src/types/plugins.ts +1 -1
- package/src/types/uploader.ts +16 -10
- package/src/types/userStore.ts +21 -17
- package/src/utils/glodash.ts +10 -3
- package/src/utils/tools.ts +27 -6
- package/src/utils/verifiers.ts +25 -50
- package/typings/global.d.ts +5 -0
- package/.babelrc +0 -4
- package/bin/build/full.sh +0 -32
- package/bin/build/jd.sh +0 -14
- package/bin/build/ks.sh +0 -14
- package/bin/build/my.sh +0 -14
- package/bin/build/plugins.sh +0 -5
- package/bin/build/qq.sh +0 -14
- package/bin/build/quickapp.sh +0 -14
- package/bin/build/swan.sh +0 -14
- package/bin/build/taro.sh +0 -18
- package/bin/build/tb.sh +0 -18
- package/bin/build/tt.sh +0 -14
- package/bin/build/uniapp.sh +0 -18
- package/bin/build/wx.sh +0 -14
- package/src/core/plugins.ts +0 -152
- package/src/pluginsOut/ordinary/gioCustomTracking.ts +0 -71
- package/bin/{build/all.sh → build.sh} +3 -3
- /package/src/{pluginsOut/ordinary → plugins}/gioCompress.ts +0 -0
package/src/utils/verifiers.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 代码中一些通用的或者业务上的校验器
|
|
3
3
|
*/
|
|
4
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
5
|
-
import { compact, isNumber, isObject, isString, last } from '@@/utils/glodash';
|
|
6
4
|
import { consoleText } from '@@/utils/tools';
|
|
5
|
+
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
|
+
import { isNumber, isString, toString } from '@@/utils/glodash';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 一些id的合法性校验
|
|
@@ -18,59 +18,34 @@ export const verifyId = (o: string | number) =>
|
|
|
18
18
|
* 初始化时的一些合法性校验
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
export const
|
|
22
|
-
//
|
|
23
|
-
|
|
21
|
+
export const initialCheck = (growingIO: GrowingIOType, args: any) => {
|
|
22
|
+
// ?重复初始化由init方法内部判断
|
|
23
|
+
const projectId = toString(args[0]);
|
|
24
|
+
const dataSourceId = toString(args[1]);
|
|
25
|
+
// 参数为空校验
|
|
26
|
+
const userOptions = (args.length === 4 ? args[3] : args[2]) || {};
|
|
27
|
+
if (!projectId || !dataSourceId) {
|
|
24
28
|
consoleText(
|
|
25
|
-
'SDK
|
|
26
|
-
'warn'
|
|
27
|
-
);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
return true;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// 参数为空校验
|
|
34
|
-
export const paramsEmptyCheck = (args: any) => {
|
|
35
|
-
if (!compact(args)) {
|
|
36
|
-
consoleText(
|
|
37
|
-
'SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "你的应用 AppId", options); 进行初始化!',
|
|
29
|
+
'SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "您的小程序 AppId(可选)", options: { host: "您的数据上报地址host" }); 进行初始化!',
|
|
38
30
|
'error'
|
|
39
31
|
);
|
|
40
32
|
return false;
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
consoleText('SDK初始化失败,accountId 参数不合法!', 'error');
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
// 参数校验(userOptions)
|
|
55
|
-
if (!isObject(userOptions) || !userOptions) {
|
|
56
|
-
userOptions = {};
|
|
57
|
-
}
|
|
58
|
-
return { projectId, userOptions };
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// 额外的参数校验(校验dataSourceId、AppId)
|
|
62
|
-
export const paramExtraCheck = (args: any) => {
|
|
63
|
-
// 参数校验(dataSourceId)
|
|
64
|
-
const dataSourceId: string = args[1];
|
|
65
|
-
let appId: any = args[2];
|
|
66
|
-
const options: any = last(args);
|
|
67
|
-
if (!dataSourceId || !isString(dataSourceId)) {
|
|
68
|
-
consoleText('SDK初始化失败,dataSourceId 参数不合法!', 'error');
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if (!verifyId(appId)) {
|
|
72
|
-
consoleText('SDK初始化失败,appId 参数不合法!', 'error');
|
|
34
|
+
const gioSDKInitialized = growingIO.dataStore.initializedTrackingIds.some(
|
|
35
|
+
(tid: string, index: number) => {
|
|
36
|
+
const vds =
|
|
37
|
+
index === 0 ? growingIO.vdsConfig : growingIO.subInstance[tid];
|
|
38
|
+
return vds.projectId === projectId && vds.dataSourceId === dataSourceId;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
if (gioSDKInitialized) {
|
|
42
|
+
consoleText('SDK初始化失败,重复初始化,请检查初始化参数!', 'error');
|
|
73
43
|
return false;
|
|
74
44
|
}
|
|
75
|
-
return {
|
|
45
|
+
return {
|
|
46
|
+
projectId,
|
|
47
|
+
dataSourceId,
|
|
48
|
+
appId: toString(args.length === 4 ? args[2] : ''),
|
|
49
|
+
userOptions
|
|
50
|
+
};
|
|
76
51
|
};
|
package/typings/global.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ declare module "__GIO_PLATFORM_INSTANCE__" {
|
|
|
46
46
|
export default module;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
declare module "__GIO_PLUGIN_INSTANCE__" {
|
|
50
|
+
let module: any;
|
|
51
|
+
export default module;
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
declare module "@system.app" {
|
|
50
55
|
let module: any;
|
|
51
56
|
export default module;
|
package/.babelrc
DELETED
package/bin/build/full.sh
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
### 全量打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 框架适配插件
|
|
10
|
-
cp src/pluginsOut/frameworks/gioTaroAdapter.ts src/pluginsIn/gioTaroAdapter.ts
|
|
11
|
-
cp src/pluginsOut/frameworks/gioUniAppAdapter.ts src/pluginsIn/gioUniAppAdapter.ts
|
|
12
|
-
# 埋点插件
|
|
13
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
14
|
-
# 无埋点插件
|
|
15
|
-
cp src/pluginsOut/ordinary/gioEventAutoTracking.ts src/pluginsIn/gioEventAutoTracking.ts
|
|
16
|
-
# 加密插件
|
|
17
|
-
cp src/pluginsOut/ordinary/gioCompress.ts src/pluginsIn/gioCompress.ts
|
|
18
|
-
# 曝光插件
|
|
19
|
-
cp src/pluginsOut/ordinary/gioImpressionTracking.ts src/pluginsIn/gioImpressionTracking.ts
|
|
20
|
-
# 打包
|
|
21
|
-
rollup -c rollup.config.js --framework-full
|
|
22
|
-
# 移除框架适配插件
|
|
23
|
-
rm src/pluginsIn/gioTaroAdapter.ts
|
|
24
|
-
rm src/pluginsIn/gioUniAppAdapter.ts
|
|
25
|
-
# 移除埋点插件
|
|
26
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
|
27
|
-
# 移除无埋点插件
|
|
28
|
-
rm src/pluginsIn/gioEventAutoTracking.ts
|
|
29
|
-
# 移除加密插件
|
|
30
|
-
rm src/pluginsIn/gioCompress.ts
|
|
31
|
-
# 移除曝光插件
|
|
32
|
-
rm src/pluginsIn/gioImpressionTracking.ts
|
package/bin/build/jd.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生京东小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --jd
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/ks.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生快手小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --ks
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/my.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生阿里小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --my
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/plugins.sh
DELETED
package/bin/build/qq.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生QQ小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --qq
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/quickapp.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生快应用打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --quickapp
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/swan.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生百度小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --swan
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/taro.sh
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
### Taro打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 框架适配插件
|
|
10
|
-
cp src/pluginsOut/frameworks/gioTaroAdapter.ts src/pluginsIn/gioTaroAdapter.ts
|
|
11
|
-
# 埋点插件
|
|
12
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
13
|
-
# 打包
|
|
14
|
-
rollup -c rollup.config.js --framework-taro
|
|
15
|
-
# 移除框架适配插件
|
|
16
|
-
rm src/pluginsIn/gioTaroAdapter.ts
|
|
17
|
-
# 移除埋点插件
|
|
18
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/tb.sh
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
### 原生淘宝小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 淘宝小程序上报适配插件
|
|
10
|
-
cp src/pluginsOut/frameworks/gioTaobaoAdapter.ts src/pluginsIn/gioTaobaoAdapter.ts
|
|
11
|
-
# 埋点插件
|
|
12
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
13
|
-
# 打包
|
|
14
|
-
rollup -c rollup.config.js --tb
|
|
15
|
-
# 移除淘宝小程序上报适配插件
|
|
16
|
-
rm src/pluginsIn/gioTaobaoAdapter.ts
|
|
17
|
-
# 移除埋点插件
|
|
18
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/tt.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生字节小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --tt
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/uniapp.sh
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
### UniApp打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 框架适配插件
|
|
10
|
-
cp src/pluginsOut/frameworks/gioUniAppAdapter.ts src/pluginsIn/gioUniAppAdapter.ts
|
|
11
|
-
# 埋点插件
|
|
12
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
13
|
-
# 打包
|
|
14
|
-
rollup -c rollup.config.js --framework-uniapp
|
|
15
|
-
# 移除框架适配插件
|
|
16
|
-
rm src/pluginsIn/gioUniAppAdapter.ts
|
|
17
|
-
# 移除埋点插件
|
|
18
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/bin/build/wx.sh
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### 原生微信小程序打包逻辑
|
|
2
|
-
|
|
3
|
-
# 新建plugins目录
|
|
4
|
-
mkdir -p src/pluginsIn
|
|
5
|
-
# 移除已有文件
|
|
6
|
-
rm src/pluginsIn/*
|
|
7
|
-
|
|
8
|
-
### 打包逻辑
|
|
9
|
-
# 埋点插件
|
|
10
|
-
cp src/pluginsOut/ordinary/gioCustomTracking.ts src/pluginsIn/gioCustomTracking.ts
|
|
11
|
-
# 打包
|
|
12
|
-
rollup -c rollup.config.js --wx
|
|
13
|
-
# 移除埋点插件
|
|
14
|
-
rm src/pluginsIn/gioCustomTracking.ts
|
package/src/core/plugins.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
3
|
-
import { PluginItem, PluginsType } from '@@/types/plugins';
|
|
4
|
-
import { isEmpty, isFunction, keys, lowerFirst, unset } from '@@/utils/glodash';
|
|
5
|
-
import { consoleText } from '@@/utils/tools';
|
|
6
|
-
|
|
7
|
-
import * as pluginsContext from '../pluginsIn/*.ts';
|
|
8
|
-
|
|
9
|
-
class Plugins implements PluginsType {
|
|
10
|
-
public pluginItems: PluginItem[];
|
|
11
|
-
constructor(public growingIO: GrowingIOType) {
|
|
12
|
-
this.pluginItems = [];
|
|
13
|
-
this.growingIO.emitter.on('onComposeBefore', this.onComposeBefore);
|
|
14
|
-
this.growingIO.emitter.on('onComposeAfter', this.onComposeAfter);
|
|
15
|
-
this.growingIO.emitter.on('onSendBefore', this.onSendBefore);
|
|
16
|
-
this.growingIO.emitter.on('onSendAfter', this.onSendAfter);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 初始化内置插件,不允许客户自己热插拔的插件,内置打包完成
|
|
20
|
-
innerPluginInit = () => {
|
|
21
|
-
keys(pluginsContext.pluginsIn).forEach((key) => {
|
|
22
|
-
const { name, method }: { name: string; method: any } =
|
|
23
|
-
pluginsContext.pluginsIn[key];
|
|
24
|
-
// 若列表中出现同名插件,以第一个扫描出来的插件为准
|
|
25
|
-
const isExist = this.pluginItems.find((o) => o.name === name);
|
|
26
|
-
if (!isExist) {
|
|
27
|
-
this.pluginItems.push({
|
|
28
|
-
// 优先使用指定插件名
|
|
29
|
-
name: lowerFirst(name || key),
|
|
30
|
-
method: method ? method : (growingIO) => {} // eslint-disable-line
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
if (!isEmpty(this.pluginItems)) {
|
|
35
|
-
this.installAll();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// 挂载插件
|
|
40
|
-
install = (pluginName: string, pluginItem?: any, options?: any): boolean => {
|
|
41
|
-
const pluginTarget: PluginItem =
|
|
42
|
-
pluginItem ||
|
|
43
|
-
this.pluginItems.find((o: PluginItem) => o.name === pluginName);
|
|
44
|
-
// 插件已加载或与已加载的插件重名
|
|
45
|
-
if (this.growingIO?.plugins[pluginName]) {
|
|
46
|
-
consoleText(`重复加载插件 ${pluginName} 或插件重名,已跳过加载!`, 'warn');
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
// 插件列表中不存在要加载的插件
|
|
50
|
-
if (!pluginTarget) {
|
|
51
|
-
consoleText(`插件加载失败!不存在名为 ${pluginName} 的插件!`, 'error');
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
// 将插件实例挂载到growingIO实例上使得其他模块可以调用
|
|
55
|
-
try {
|
|
56
|
-
this.growingIO.plugins[pluginName] = new pluginTarget.method(
|
|
57
|
-
this.growingIO,
|
|
58
|
-
options
|
|
59
|
-
);
|
|
60
|
-
if (pluginItem) {
|
|
61
|
-
consoleText(`加载插件:${pluginName}`, 'info');
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
} catch (error) {
|
|
65
|
-
consoleText(`插件【${pluginName}】加载异常 ${error}`, 'error');
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// 挂载所有插件
|
|
71
|
-
installAll = (plugins: PluginItem[]) => {
|
|
72
|
-
(plugins || this.pluginItems).forEach((o: PluginItem) =>
|
|
73
|
-
this.install(o.name, plugins ? o : undefined, o.options)
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// 移除插件
|
|
78
|
-
uninstall = (pluginName: string): boolean => {
|
|
79
|
-
unset(this.pluginItems, pluginName);
|
|
80
|
-
const u = unset(this.growingIO?.plugins, pluginName);
|
|
81
|
-
if (!u) {
|
|
82
|
-
consoleText(`卸载插件 ${pluginName} 失败!`, 'error');
|
|
83
|
-
}
|
|
84
|
-
return u;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// 移除所有插件
|
|
88
|
-
uninstallAll = () => {
|
|
89
|
-
this.pluginItems.forEach((o: PluginItem) => this.uninstall(o.name));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
lifeError = (p: PluginItem, e: any) =>
|
|
93
|
-
consoleText(`插件执行错误 ${p.name} ${e}`, 'error');
|
|
94
|
-
|
|
95
|
-
// 触发生命周期事件(事件合成前)
|
|
96
|
-
onComposeBefore = (args: any) => {
|
|
97
|
-
this.pluginItems.forEach((o: PluginItem) => {
|
|
98
|
-
const method = this.growingIO.plugins[o.name]?.onComposeBefore;
|
|
99
|
-
if (method && isFunction(method)) {
|
|
100
|
-
try {
|
|
101
|
-
method(args);
|
|
102
|
-
} catch (e) {
|
|
103
|
-
this.lifeError(o, e);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// 触发生命周期事件(事件合成后)
|
|
110
|
-
onComposeAfter = (args: any) => {
|
|
111
|
-
this.pluginItems.forEach((o: PluginItem) => {
|
|
112
|
-
const method = this.growingIO.plugins[o.name]?.onComposeAfter;
|
|
113
|
-
if (method && isFunction(method)) {
|
|
114
|
-
try {
|
|
115
|
-
method(args);
|
|
116
|
-
} catch (e) {
|
|
117
|
-
this.lifeError(o, e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// 触发生命周期事件(事件发送前)
|
|
124
|
-
onSendBefore = (args: any) => {
|
|
125
|
-
this.pluginItems.forEach((o: PluginItem) => {
|
|
126
|
-
const method = this.growingIO.plugins[o.name]?.onSendBefore;
|
|
127
|
-
if (method && isFunction(method)) {
|
|
128
|
-
try {
|
|
129
|
-
method(args);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
this.lifeError(o, e);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// 触发生命周期事件(事件发送后)
|
|
138
|
-
onSendAfter = (args: any) => {
|
|
139
|
-
this.pluginItems.forEach((o: PluginItem) => {
|
|
140
|
-
const method = this.growingIO.plugins[o.name]?.onSendAfter;
|
|
141
|
-
if (method && isFunction(method)) {
|
|
142
|
-
try {
|
|
143
|
-
method(args);
|
|
144
|
-
} catch (e) {
|
|
145
|
-
this.lifeError(o, e);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export default Plugins;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 名称:自定义埋点插件
|
|
3
|
-
* 用途:用于提供自定义埋点的事件构建方法。
|
|
4
|
-
*/
|
|
5
|
-
import { GioCustomTrackingType } from '@@/types/gioCustomTracking';
|
|
6
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
7
|
-
|
|
8
|
-
let ut;
|
|
9
|
-
class GioCustomTracking implements GioCustomTrackingType {
|
|
10
|
-
constructor(public growingIO: GrowingIOType) {
|
|
11
|
-
ut = this.growingIO.utils;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// 获取动态属性的值
|
|
15
|
-
getDynamicAttributes = (properties: any) => {
|
|
16
|
-
if (!ut.isNil(properties)) {
|
|
17
|
-
ut.keys(properties).forEach((k: string) => {
|
|
18
|
-
if (ut.isFunction(properties[k])) {
|
|
19
|
-
properties[k] = properties[k]();
|
|
20
|
-
} else if (!ut.isArray(properties[k])) {
|
|
21
|
-
properties[k] = ut.toString(properties[k]);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return properties;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// 构建自定义埋点事件
|
|
29
|
-
buildCustomEvent = (name: string, properties: { [key: string]: string }) => {
|
|
30
|
-
ut.eventNameValidate(name, () => {
|
|
31
|
-
const {
|
|
32
|
-
dataStore: { eventContextBuilder, eventInterceptor }
|
|
33
|
-
} = this.growingIO;
|
|
34
|
-
const event = {
|
|
35
|
-
eventType: 'CUSTOM',
|
|
36
|
-
eventName: name,
|
|
37
|
-
attributes: ut.limitObject(
|
|
38
|
-
this.getDynamicAttributes(
|
|
39
|
-
ut.isObject(properties) && !ut.isEmpty(properties)
|
|
40
|
-
? properties
|
|
41
|
-
: undefined
|
|
42
|
-
)
|
|
43
|
-
),
|
|
44
|
-
...eventContextBuilder()
|
|
45
|
-
};
|
|
46
|
-
eventInterceptor(event);
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// 构建用户变量事件
|
|
51
|
-
buildUserAttributesEvent = (attributes: { [key: string]: string }) => {
|
|
52
|
-
const {
|
|
53
|
-
dataStore: { eventContextBuilder, eventInterceptor, lastVisitEvent }
|
|
54
|
-
} = this.growingIO;
|
|
55
|
-
const event = {
|
|
56
|
-
eventType: 'LOGIN_USER_ATTRIBUTES',
|
|
57
|
-
attributes: ut.limitObject(attributes),
|
|
58
|
-
...eventContextBuilder()
|
|
59
|
-
};
|
|
60
|
-
// 该方法很可能被放在在app的onShow中的wx.login异步回调中,
|
|
61
|
-
// 此时页面的path和query可能还没取到,就拿visit事件的path和query补上
|
|
62
|
-
if (!event.path) {
|
|
63
|
-
event.path = lastVisitEvent.path;
|
|
64
|
-
event.query = lastVisitEvent.query;
|
|
65
|
-
event.title = lastVisitEvent.title;
|
|
66
|
-
}
|
|
67
|
-
eventInterceptor(event);
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export default { name: 'gioCustomTracking', method: GioCustomTracking };
|
|
File without changes
|