gio-miniprogram-sdk 4.0.0 → 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.
Files changed (78) 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 +13 -10
  20. package/src/{pluginsOut/frameworks → adapters}/gioTaobaoAdapter.ts +47 -44
  21. package/src/adapters/gioTaroAdapter.ts +459 -0
  22. package/src/{pluginsOut/frameworks → adapters}/gioUniAppAdapter.ts +35 -6
  23. package/src/constants/config.ts +49 -20
  24. package/src/constants/emitMsg.ts +23 -0
  25. package/src/constants/regex.ts +14 -0
  26. package/src/core/dataStore/eventContextBuilder.ts +28 -17
  27. package/src/core/dataStore/eventHooks/appEffects.ts +50 -31
  28. package/src/core/dataStore/eventHooks/index.ts +7 -5
  29. package/src/core/dataStore/eventHooks/minipPage.ts +2 -11
  30. package/src/core/dataStore/eventHooks/pageEffects.ts +61 -27
  31. package/src/core/dataStore/index.ts +266 -181
  32. package/src/core/growingIO.ts +312 -179
  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 -87
  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 -4
  43. package/src/{pluginsOut/ordinary → plugins}/gioABTest.ts +74 -37
  44. package/src/{pluginsOut/ordinary → plugins}/gioEventAutoTracking.ts +25 -18
  45. package/src/{pluginsOut/ordinary → plugins}/gioImpressionTracking.ts +109 -41
  46. package/src/plugins/gioMultipleInstances.ts +176 -0
  47. package/src/types/base.ts +12 -3
  48. package/src/types/dataStore.ts +31 -16
  49. package/src/types/eventHooks.ts +8 -9
  50. package/src/types/growingIO.ts +30 -14
  51. package/src/types/platforms.ts +0 -4
  52. package/src/types/plugins.ts +1 -1
  53. package/src/types/uploader.ts +16 -12
  54. package/src/types/userStore.ts +21 -17
  55. package/src/utils/glodash.ts +10 -3
  56. package/src/utils/tools.ts +27 -6
  57. package/src/utils/verifiers.ts +25 -50
  58. package/typings/global.d.ts +5 -0
  59. package/.babelrc +0 -4
  60. package/bin/build/full.sh +0 -32
  61. package/bin/build/jd.sh +0 -14
  62. package/bin/build/ks.sh +0 -14
  63. package/bin/build/my.sh +0 -14
  64. package/bin/build/plugins.sh +0 -5
  65. package/bin/build/qq.sh +0 -14
  66. package/bin/build/quickapp.sh +0 -14
  67. package/bin/build/swan.sh +0 -14
  68. package/bin/build/taro.sh +0 -18
  69. package/bin/build/tb.sh +0 -18
  70. package/bin/build/tt.sh +0 -14
  71. package/bin/build/uniapp.sh +0 -18
  72. package/bin/build/wx.sh +0 -14
  73. package/src/core/plugins.ts +0 -152
  74. package/src/pluginsOut/README.md +0 -50
  75. package/src/pluginsOut/frameworks/gioTaroAdapter.ts +0 -358
  76. package/src/pluginsOut/ordinary/gioCustomTracking.ts +0 -71
  77. package/bin/{build/all.sh → build.sh} +3 -3
  78. /package/src/{pluginsOut/ordinary → plugins}/gioCompress.ts +0 -0
@@ -1,6 +1,8 @@
1
1
  import { get, isEmpty, isFunction, unset } from '@@/utils/glodash';
2
2
  import { GrowingIOType } from '@@/types/growingIO';
3
+ import { niceTry } from '@@/utils/tools';
3
4
  import { PageHookLifeCircle } from '@@/types/eventHooks';
5
+ import EMIT_MSG from '@@/constants/emitMsg';
4
6
 
5
7
  class PageEffects {
6
8
  public buildTabClickEvent: (tabItem: any) => void;
@@ -20,6 +22,8 @@ class PageEffects {
20
22
  vdsConfig,
21
23
  platformConfig,
22
24
  dataStore: {
25
+ getTrackerVds,
26
+ trackersExecute,
23
27
  shareOut,
24
28
  eventHooks,
25
29
  toggleShareOut,
@@ -45,7 +49,7 @@ class PageEffects {
45
49
  }
46
50
  const path =
47
51
  page.route || page.uri || page.__route__ || page?.$page?.fullPath || '';
48
- emitter.emit('minipLifecycle', {
52
+ emitter.emit(EMIT_MSG.MINIP_LIFECYCLE, {
49
53
  event: `Page ${event}`,
50
54
  timestamp: eventTime,
51
55
  params: { page, args: args[0] }
@@ -56,7 +60,7 @@ class PageEffects {
56
60
  this.prevEvent[event] = Date.now();
57
61
  const pageListeners = platformConfig.listeners.page;
58
62
  // 向插件广播事件
59
- emitter.emit('onComposeBefore', {
63
+ emitter.emit(EMIT_MSG.ON_COMPOSE_BEFORE, {
60
64
  page,
61
65
  event: `Page ${event}`,
62
66
  params: { page, args: args[0] }
@@ -84,18 +88,26 @@ class PageEffects {
84
88
  currentPage.path = `/插件${vdsConfig.appId}}`;
85
89
  currentPage.title = `/插件${vdsConfig.appId}}`;
86
90
  }
87
- this.buildPageEvent();
91
+ trackersExecute((trackingId: string) => {
92
+ const { trackPage } = getTrackerVds(trackingId);
93
+ if (trackPage) {
94
+ this.buildPageEvent(trackingId);
95
+ }
96
+ });
88
97
  } else if (!shareOut || !eventHooks.currentPage.time) {
89
98
  // 不是因为分享切出再返回的onshow(视为第一次进入改页面)和切出去以后因为超时或者进入的场景值不一致时(会在appshow清掉页面时间),发page
90
99
  currentPage.parsePage(page, this.argQuery[path]);
91
100
  // 超时进入页面时前后path一致parsePage方法不会重置页面时间,可能会没有值,所以要补充重设一次
92
101
  eventHooks.currentPage.time = Date.now();
93
- this.buildPageEvent();
102
+ trackersExecute((trackingId: string) => {
103
+ const { trackPage } = getTrackerVds(trackingId);
104
+ if (trackPage) {
105
+ this.buildPageEvent(trackingId);
106
+ }
107
+ });
94
108
  }
95
109
  // 分享标记置为false
96
110
  toggleShareOut(false);
97
- // 保存分享id(记录是从哪个用户id的分享来的)
98
- currentPage.saveShareId(this.argQuery[path]);
99
111
  break;
100
112
  }
101
113
  case pageListeners.pageHide:
@@ -104,19 +116,30 @@ class PageEffects {
104
116
  }
105
117
  case pageListeners.shareApp: {
106
118
  toggleShareOut(true);
107
- if (vdsConfig.followShare) {
108
- buildAppMessageEvent(args);
109
- }
119
+ trackersExecute((trackingId: string) => {
120
+ const { followShare } = getTrackerVds(trackingId);
121
+ if (followShare) {
122
+ buildAppMessageEvent(trackingId, args);
123
+ }
124
+ });
110
125
  break;
111
126
  }
112
127
  case pageListeners.shareTime: {
113
- if (vdsConfig.followShare) {
114
- buildTimelineEvent(args);
115
- }
128
+ trackersExecute((trackingId: string) => {
129
+ const { followShare } = getTrackerVds(trackingId);
130
+ if (followShare) {
131
+ buildTimelineEvent(trackingId, args);
132
+ }
133
+ });
116
134
  break;
117
135
  }
118
136
  case pageListeners.addFavorites: {
119
- buildAddFavorites(args);
137
+ trackersExecute((trackingId: string) => {
138
+ const { followShare } = getTrackerVds(trackingId);
139
+ if (followShare) {
140
+ buildAddFavorites(trackingId, args);
141
+ }
142
+ });
120
143
  break;
121
144
  }
122
145
  case pageListeners.tabTap: {
@@ -127,7 +150,7 @@ class PageEffects {
127
150
  buildTabClickEvent &&
128
151
  isFunction(buildTabClickEvent)
129
152
  ) {
130
- buildTabClickEvent(args[0]);
153
+ buildTabClickEvent(this.growingIO.trackingId, args[0]);
131
154
  }
132
155
  break;
133
156
  }
@@ -136,30 +159,41 @@ class PageEffects {
136
159
  }
137
160
  // 页面销毁移除当前页面的属性
138
161
  if (event === pageListeners.pageUnload) {
139
- currentPage.pageProps[path] = undefined;
162
+ trackersExecute((trackingId: string) => {
163
+ currentPage.pageProps[trackingId] = undefined;
164
+ });
140
165
  }
141
166
  };
142
167
 
143
168
  // 构建页面访问事件
144
- buildPageEvent = (props?: any) => {
169
+ buildPageEvent = (trackingId: string, props?: any) => {
145
170
  const {
146
- dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
171
+ dataStore: {
172
+ eventContextBuilder,
173
+ eventInterceptor,
174
+ eventHooks: { currentPage }
175
+ },
176
+ minipInstance
147
177
  } = this.growingIO;
148
- const { currentPage } = eventHooks;
149
178
  const event = {
150
179
  eventType: 'PAGE',
151
- referralPage: currentPage.getReferralPage(),
152
- ...eventContextBuilder(),
180
+ referralPage: currentPage.getReferralPage(trackingId),
181
+ ...eventContextBuilder(trackingId),
182
+ // page事件要单独设一个title以覆盖eventContextBuilder中的lastPage的title错误值
183
+ title:
184
+ currentPage?.title ||
185
+ minipInstance.getPageTitle(minipInstance.getCurrentPage()),
153
186
  timestamp: currentPage.time
154
187
  };
155
- // 添加页面属性
156
- if (!isEmpty(currentPage.pageProps[event.path])) {
157
- event.attributes = currentPage.pageProps[event.path];
188
+ // 传入参数生成的page事件取值为传入参数
189
+ if (!isEmpty(props) && props.title) {
190
+ event.title = props.title;
158
191
  }
159
- if (!isEmpty(props) && props.path) {
160
- event.path = props.path;
161
- event.query = props.query;
162
- event.title = props.title ?? event.title;
192
+ // 添加页面属性
193
+ const pageProps = niceTry(() => currentPage.pageProps[trackingId]);
194
+ if (!isEmpty(pageProps)) {
195
+ event.attributes = pageProps;
196
+ currentPage.pageProps[trackingId] = undefined;
163
197
  }
164
198
  eventInterceptor(event);
165
199
  };