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
|
@@ -6,6 +6,7 @@ import { consoleText, getGlobal, niceTry } from '@@/utils/tools';
|
|
|
6
6
|
import AppEffects from './appEffects';
|
|
7
7
|
import MinipPage from './minipPage';
|
|
8
8
|
import PageEffects from './pageEffects';
|
|
9
|
+
import EMIT_MSG from '@@/constants/emitMsg';
|
|
9
10
|
|
|
10
11
|
class EventHooks implements EventHooksType {
|
|
11
12
|
private appHooked: boolean;
|
|
@@ -33,10 +34,6 @@ class EventHooks implements EventHooksType {
|
|
|
33
34
|
this.appHandlers = config.appHandlers;
|
|
34
35
|
this.pageHandlers = config.pageHandlers;
|
|
35
36
|
this.actionEventTypes = config.actionEventTypes;
|
|
36
|
-
this.originalApp = config.originalApp;
|
|
37
|
-
this.originalPage = config.originalPage;
|
|
38
|
-
this.originalComponent = config.originalComponent;
|
|
39
|
-
this.originalBehavior = config.originalBehavior ?? function () {}; // eslint-disable-line
|
|
40
37
|
this.appEffects = new AppEffects(this.growingIO);
|
|
41
38
|
this.pageEffects = new PageEffects(this.growingIO);
|
|
42
39
|
this.currentPage = new MinipPage(this.growingIO);
|
|
@@ -161,7 +158,7 @@ class EventHooks implements EventHooksType {
|
|
|
161
158
|
if (eventName !== 'onShareAppMessage') {
|
|
162
159
|
result = method.apply(this, args);
|
|
163
160
|
}
|
|
164
|
-
self.growingIO.emitter.emit(
|
|
161
|
+
self.growingIO.emitter.emit(EMIT_MSG.MINIP_LIFECYCLE, {
|
|
165
162
|
event: `${cType} ${eventName}End`,
|
|
166
163
|
timestamp: Date.now(),
|
|
167
164
|
params: { instance: this, arguments: Array.from(args) }
|
|
@@ -324,6 +321,7 @@ class EventHooks implements EventHooksType {
|
|
|
324
321
|
try {
|
|
325
322
|
// 重写App
|
|
326
323
|
if (platformHooks.App && !this.appHooked) {
|
|
324
|
+
this.originalApp = App || global.App || function () {};
|
|
327
325
|
App = function (...args) {
|
|
328
326
|
return self.growingApp(args[0]);
|
|
329
327
|
};
|
|
@@ -337,6 +335,7 @@ class EventHooks implements EventHooksType {
|
|
|
337
335
|
try {
|
|
338
336
|
// 重写Page
|
|
339
337
|
if (platformHooks.Page && !this.pageHooked) {
|
|
338
|
+
this.originalPage = Page || global.Page || function () {};
|
|
340
339
|
Page = function (...args) {
|
|
341
340
|
return self.growingPage(args[0]);
|
|
342
341
|
};
|
|
@@ -350,6 +349,8 @@ class EventHooks implements EventHooksType {
|
|
|
350
349
|
try {
|
|
351
350
|
// 重写Component
|
|
352
351
|
if (platformHooks.Component && !this.componentHooked) {
|
|
352
|
+
this.originalComponent =
|
|
353
|
+
Component || global.Component || function () {};
|
|
353
354
|
Component = function (...args) {
|
|
354
355
|
return self.growingComponent(args[0]);
|
|
355
356
|
};
|
|
@@ -363,6 +364,7 @@ class EventHooks implements EventHooksType {
|
|
|
363
364
|
try {
|
|
364
365
|
// 重写Behavior
|
|
365
366
|
if (platformHooks.Behavior && !this.behaviorHooked) {
|
|
367
|
+
this.originalBehavior = Behavior || global.Behavior || function () {};
|
|
366
368
|
Behavior = function (...args) {
|
|
367
369
|
return self.growingBehavior(args[0]);
|
|
368
370
|
};
|
|
@@ -11,8 +11,6 @@ class MinipPage implements MinipPageType {
|
|
|
11
11
|
public title: string;
|
|
12
12
|
// 通过调用wx.setNavigationBarTitle设置的title
|
|
13
13
|
public settedTitle: any;
|
|
14
|
-
// 当前页面参数中的分享id
|
|
15
|
-
public queryShareId: string;
|
|
16
14
|
// 页面级属性
|
|
17
15
|
public pageProps: any;
|
|
18
16
|
// 上一个执行的小程序生命周期
|
|
@@ -56,24 +54,17 @@ class MinipPage implements MinipPageType {
|
|
|
56
54
|
};
|
|
57
55
|
|
|
58
56
|
// 获取上一个页面路径
|
|
59
|
-
getReferralPage = () => {
|
|
57
|
+
getReferralPage = (trackingId: string) => {
|
|
60
58
|
const {
|
|
61
59
|
minipInstance,
|
|
62
60
|
dataStore: { lastPageEvent, scene }
|
|
63
61
|
} = this.growingIO;
|
|
64
62
|
return (
|
|
65
|
-
lastPageEvent?.path ||
|
|
63
|
+
lastPageEvent[trackingId]?.path ||
|
|
66
64
|
(scene ? `scn:${minipInstance.scnPrefix}${scene}` : null)
|
|
67
65
|
);
|
|
68
66
|
};
|
|
69
67
|
|
|
70
|
-
// 保存分享id(记录是从哪个用户id的分享来的)
|
|
71
|
-
saveShareId = (query: any) => {
|
|
72
|
-
if (query?.gioShareId) {
|
|
73
|
-
this.queryShareId = query.gioShareId;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
68
|
// 处理分享参数
|
|
78
69
|
buildShareQuery(
|
|
79
70
|
result: PageShareResult // 客户自定义的参数
|
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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: {
|
|
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(
|
|
157
|
-
event.
|
|
188
|
+
// 传入参数生成的page事件取值为传入参数
|
|
189
|
+
if (!isEmpty(props) && props.title) {
|
|
190
|
+
event.title = props.title;
|
|
158
191
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
event.
|
|
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
|
};
|