gio-miniprogram-sdk 4.0.1 → 4.2.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.
Files changed (76) hide show
  1. package/dist/alipay.js +1 -1
  2. package/dist/baidu.js +1 -1
  3. package/dist/bytedance.js +1 -1
  4. package/dist/jingdong.js +1 -1
  5. package/dist/kuaishou.js +1 -1
  6. package/dist/plugins/gioABTest.js +1 -1
  7. package/dist/plugins/gioCompress.js +1 -1
  8. package/dist/plugins/gioEventAutoTracking.js +1 -1
  9. package/dist/plugins/gioImpressionTracking.js +1 -1
  10. package/dist/plugins/gioMultipleInstances.js +1 -0
  11. package/dist/qq.js +1 -1
  12. package/dist/quickapp.js +1 -1
  13. package/dist/taobao.js +1 -1
  14. package/dist/taro.js +1 -1
  15. package/dist/uniapp.js +1 -1
  16. package/dist/wechat.js +1 -1
  17. package/package.json +39 -42
  18. package/rollup.config.js +11 -6
  19. package/rollup.plugins.config.js +18 -10
  20. package/src/{pluginsOut/frameworks → adapters}/gioTaobaoAdapter.ts +49 -43
  21. package/src/{pluginsOut/frameworks → adapters}/gioTaroAdapter.ts +6 -4
  22. package/src/{pluginsOut/frameworks → adapters}/gioUniAppAdapter.ts +37 -6
  23. package/src/constants/config.ts +48 -18
  24. package/src/constants/emitMsg.ts +23 -0
  25. package/src/constants/regex.ts +0 -1
  26. package/src/core/dataStore/eventContextBuilder.ts +54 -25
  27. package/src/core/dataStore/eventHooks/appEffects.ts +50 -31
  28. package/src/core/dataStore/eventHooks/index.ts +13 -6
  29. package/src/core/dataStore/eventHooks/minipPage.ts +41 -13
  30. package/src/core/dataStore/eventHooks/pageEffects.ts +54 -31
  31. package/src/core/dataStore/index.ts +287 -205
  32. package/src/core/growingIO.ts +370 -180
  33. package/src/core/pluginsInstance/base.ts +157 -0
  34. package/src/core/pluginsInstance/taro.ts +15 -0
  35. package/src/core/pluginsInstance/tb.ts +15 -0
  36. package/src/core/pluginsInstance/uniapp.ts +15 -0
  37. package/src/core/uploader.ts +131 -82
  38. package/src/core/userStore.ts +160 -121
  39. package/src/index.ts +37 -28
  40. package/src/minipInstance/base.ts +2 -1
  41. package/src/minipInstance/quickapp.ts +5 -19
  42. package/src/platformConfig/base.ts +0 -5
  43. package/src/{pluginsOut/ordinary → plugins}/gioABTest.ts +88 -44
  44. package/src/{pluginsOut/ordinary → plugins}/gioCompress.ts +2 -0
  45. package/src/{pluginsOut/ordinary → plugins}/gioEventAutoTracking.ts +45 -21
  46. package/src/{pluginsOut/ordinary → plugins}/gioImpressionTracking.ts +67 -23
  47. package/src/plugins/gioMultipleInstances.ts +187 -0
  48. package/src/types/base.ts +10 -3
  49. package/src/types/dataStore.ts +35 -16
  50. package/src/types/eventHooks.ts +8 -6
  51. package/src/types/growingIO.ts +74 -39
  52. package/src/types/platforms.ts +0 -4
  53. package/src/types/plugins.ts +1 -1
  54. package/src/types/uploader.ts +16 -10
  55. package/src/types/userStore.ts +21 -17
  56. package/src/utils/glodash.ts +10 -3
  57. package/src/utils/tools.ts +31 -6
  58. package/src/utils/verifiers.ts +25 -50
  59. package/typings/global.d.ts +5 -0
  60. package/.babelrc +0 -4
  61. package/bin/build/full.sh +0 -32
  62. package/bin/build/jd.sh +0 -14
  63. package/bin/build/ks.sh +0 -14
  64. package/bin/build/my.sh +0 -14
  65. package/bin/build/plugins.sh +0 -5
  66. package/bin/build/qq.sh +0 -14
  67. package/bin/build/quickapp.sh +0 -14
  68. package/bin/build/swan.sh +0 -14
  69. package/bin/build/taro.sh +0 -18
  70. package/bin/build/tb.sh +0 -18
  71. package/bin/build/tt.sh +0 -14
  72. package/bin/build/uniapp.sh +0 -18
  73. package/bin/build/wx.sh +0 -14
  74. package/src/core/plugins.ts +0 -152
  75. package/src/pluginsOut/ordinary/gioCustomTracking.ts +0 -71
  76. package/bin/{build/all.sh → build.sh} +3 -3
@@ -1,8 +1,12 @@
1
+ import { IMP_EVENTNAME_REG } from '@@/constants/regex';
1
2
  import {
3
+ compact,
2
4
  find,
3
5
  forEach,
6
+ formatDate,
4
7
  head,
5
8
  isArray,
9
+ isDate,
6
10
  isEmpty,
7
11
  isFunction,
8
12
  isNil,
@@ -11,7 +15,8 @@ import {
11
15
  keys,
12
16
  split,
13
17
  startsWith,
14
- toString
18
+ toString,
19
+ unset
15
20
  } from '@@/utils/glodash';
16
21
 
17
22
  // 控制台打印提示信息,包含错误、警告和信息3种形式
@@ -62,7 +67,7 @@ export const eventNameValidate = (eventName: string, callback: () => void) => {
62
67
  if (
63
68
  isString(eventName) &&
64
69
  !isEmpty(eventName) &&
65
- eventName.match(/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/)
70
+ eventName.match(IMP_EVENTNAME_REG)
66
71
  ) {
67
72
  return callback();
68
73
  } else {
@@ -74,6 +79,22 @@ export const eventNameValidate = (eventName: string, callback: () => void) => {
74
79
  }
75
80
  };
76
81
 
82
+ // 获取动态属性的值
83
+ export const getDynamicAttributes = (properties: any) => {
84
+ if (!isNil(properties)) {
85
+ keys(properties).forEach((k: string) => {
86
+ if (isFunction(properties[k])) {
87
+ properties[k] = niceTry(() => properties[k]());
88
+ } else if (isObject(properties[k])) {
89
+ unset(properties, k);
90
+ } else if (!isArray(properties[k])) {
91
+ properties[k] = toString(properties[k]);
92
+ }
93
+ });
94
+ }
95
+ return properties;
96
+ };
97
+
77
98
  // 生成uuid
78
99
  export const guid = () => {
79
100
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
@@ -132,7 +153,7 @@ export const compareVersion = (v1 = '', v2 = '') => {
132
153
  // 获取vue的主版本号
133
154
  export const getVueVersion = (vue) => {
134
155
  if (vue) {
135
- const mv = Number.parseInt(head(split(vue.version, '.')), 10);
156
+ const mv = Number(head(split(vue.version, '.')));
136
157
  return Number.isNaN(mv) ? 0 : mv;
137
158
  } else {
138
159
  return 0;
@@ -282,13 +303,17 @@ export const getGlobal = () => {
282
303
  export const limitObject = (o: any) => {
283
304
  const ob = {};
284
305
  if (isObject(o)) {
306
+ // 移除预置的'&&sendTo'字段
307
+ unset(o, '&&sendTo');
285
308
  forEach(o, (v, k) => {
286
309
  const key = toString(k).slice(0, 100);
287
310
  if (isObject(v)) {
288
311
  ob[key] = limitObject(v);
289
312
  } else if (isArray(v)) {
290
- ob[key] = v.slice(0, 100);
313
+ ob[key] = compact(v.slice(0, 100), true);
291
314
  ob[key] = ob[key].join('||').slice(0, 1000);
315
+ } else if (isDate(v)) {
316
+ ob[key] = formatDate(v);
292
317
  } else {
293
318
  ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
294
319
  }
@@ -368,7 +393,7 @@ export const qsParse = (s: string) => {
368
393
  };
369
394
 
370
395
  // 将字符串转为hash
371
- export const hashCode = (string) => {
396
+ export const hashCode = (string: string, abs = false) => {
372
397
  let hash = 0;
373
398
  if (isEmpty(string) || typeof string === 'boolean') {
374
399
  return hash;
@@ -380,5 +405,5 @@ export const hashCode = (string) => {
380
405
  hash = hash & hash; //Convert to 32bit integer
381
406
  i++;
382
407
  }
383
- return hash;
408
+ return abs ? Math.abs(hash) : hash;
384
409
  };
@@ -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 initPreCheck = (growingIO: GrowingIOType) => {
22
- // 重复初始化校验
23
- if (growingIO.vdsConfig || growingIO.gioSDKInitialized) {
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重复初始化,请检查是否重复加载SDK或接入其他平台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
- return true;
43
- };
44
-
45
- // 基础参数校验(projectId、userOptions)
46
- export const paramsBaseCheck = (args: any) => {
47
- const projectId: string = args[0];
48
- let userOptions: object = last(args);
49
- // 参数校验(projectId)
50
- if (!verifyId(projectId)) {
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 { dataSourceId, appId, options };
45
+ return {
46
+ projectId,
47
+ dataSourceId,
48
+ appId: toString(args.length === 4 ? args[2] : ''),
49
+ userOptions
50
+ };
76
51
  };
@@ -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
@@ -1,4 +0,0 @@
1
- {
2
- // "presets": ["@babel/preset-env"],
3
- "plugins": ["babel-plugin-bulk-import"]
4
- }
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
@@ -1,5 +0,0 @@
1
- # 清空原产物
2
- rm -r dist/plugins/*
3
-
4
- # 打包插件
5
- rollup -c rollup.plugins.config.js --ordinary
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
@@ -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
@@ -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
@@ -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 };
@@ -1,9 +1,6 @@
1
1
  # 清空产物
2
2
  rm -r dist/*
3
3
 
4
- # 插件
5
- npm run build:plugins
6
-
7
4
  # 微信小程序
8
5
  npm run build:wx
9
6
 
@@ -36,3 +33,6 @@ npm run build:uniapp
36
33
 
37
34
  # taro2/3 react/vue2/vue3
38
35
  npm run build:taro
36
+
37
+ # 插件
38
+ npm run build:plugins