gio-miniprogram-sdk 4.4.1 → 4.4.3
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 -1
- package/dist/plugins/gioPerformance.js +1 -1
- 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/dist/xiaohongshu.js +1 -1
- package/package.json +7 -1
- package/.eslintignore +0 -11
- package/.eslintrc.js +0 -120
- package/.github/workflows/greetings.yml +0 -13
- package/.github/workflows/publish.yml +0 -45
- package/.prettierignore +0 -19
- package/.prettierrc.js +0 -9
- package/babel.config.js +0 -6
- package/rollup.config.js +0 -100
- package/rollup.plugins.config.js +0 -84
- package/src/adapters/gioTaobaoAdapter.ts +0 -202
- package/src/adapters/gioTaroAdapter.ts +0 -467
- package/src/adapters/gioUniAppAdapter.ts +0 -431
- package/src/constants/config.ts +0 -170
- package/src/constants/emitMsg.ts +0 -24
- package/src/constants/regex.ts +0 -18
- package/src/core/dataStore/eventContextBuilder.ts +0 -95
- package/src/core/dataStore/eventHooks/appEffects.ts +0 -218
- package/src/core/dataStore/eventHooks/index.ts +0 -468
- package/src/core/dataStore/eventHooks/minipPage.ts +0 -234
- package/src/core/dataStore/eventHooks/pageEffects.ts +0 -189
- package/src/core/dataStore/index.ts +0 -661
- package/src/core/growingIO.ts +0 -637
- package/src/core/pluginsInstance/base.ts +0 -157
- package/src/core/pluginsInstance/taro.ts +0 -15
- package/src/core/pluginsInstance/tb.ts +0 -15
- package/src/core/pluginsInstance/uniapp.ts +0 -15
- package/src/core/uploader.ts +0 -272
- package/src/core/userStore.ts +0 -267
- package/src/index.ts +0 -77
- package/src/minipInstance/base.ts +0 -352
- package/src/minipInstance/framework.ts +0 -24
- package/src/minipInstance/jd.ts +0 -11
- package/src/minipInstance/ks.ts +0 -12
- package/src/minipInstance/my.ts +0 -131
- package/src/minipInstance/qq.ts +0 -12
- package/src/minipInstance/quickapp.ts +0 -233
- package/src/minipInstance/swan.ts +0 -20
- package/src/minipInstance/tb.ts +0 -58
- package/src/minipInstance/tt.ts +0 -12
- package/src/minipInstance/wx.ts +0 -27
- package/src/minipInstance/xhs.ts +0 -20
- package/src/platformConfig/base.ts +0 -82
- package/src/platformConfig/framework.ts +0 -31
- package/src/platformConfig/jd.ts +0 -11
- package/src/platformConfig/ks.ts +0 -11
- package/src/platformConfig/my.ts +0 -16
- package/src/platformConfig/qq.ts +0 -13
- package/src/platformConfig/quickapp.ts +0 -48
- package/src/platformConfig/swan.ts +0 -11
- package/src/platformConfig/tb.ts +0 -29
- package/src/platformConfig/tt.ts +0 -11
- package/src/platformConfig/wx.ts +0 -20
- package/src/platformConfig/xhs.ts +0 -27
- package/src/plugins/gioABTest.ts +0 -348
- package/src/plugins/gioCompress.ts +0 -253
- package/src/plugins/gioEventAutoTracking.ts +0 -288
- package/src/plugins/gioImpressionTracking.ts +0 -386
- package/src/plugins/gioMultipleInstances.ts +0 -189
- package/src/plugins/gioPerformance/exception.ts +0 -152
- package/src/plugins/gioPerformance/monitor.ts +0 -284
- package/src/plugins/gioPerformance/network.ts +0 -197
- package/src/plugins/gioPerformance.ts +0 -131
- package/src/types/base.ts +0 -167
- package/src/types/dataStore.ts +0 -62
- package/src/types/eventHooks.ts +0 -147
- package/src/types/gioCustomTracking.ts +0 -9
- package/src/types/gioEventTracking.ts +0 -10
- package/src/types/gioPerformance.ts +0 -8
- package/src/types/growingIO.ts +0 -137
- package/src/types/minipInstance.ts +0 -133
- package/src/types/platforms.ts +0 -64
- package/src/types/plugins.ts +0 -24
- package/src/types/uploader.ts +0 -30
- package/src/types/userStore.ts +0 -28
- package/src/utils/glodash.ts +0 -430
- package/src/utils/tools.ts +0 -472
- package/src/utils/verifiers.ts +0 -52
- package/tsconfig.json +0 -32
- package/typings/global.d.ts +0 -105
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
2
|
-
import {
|
|
3
|
-
getDynamicAttributes,
|
|
4
|
-
getOS,
|
|
5
|
-
getScreenHeight,
|
|
6
|
-
getScreenWidth,
|
|
7
|
-
limitObject
|
|
8
|
-
} from '@@/utils/tools';
|
|
9
|
-
import { isEmpty, unset } from '@@/utils/glodash';
|
|
10
|
-
|
|
11
|
-
class EventContextBuilder {
|
|
12
|
-
constructor(public growingIO: GrowingIOType) {}
|
|
13
|
-
|
|
14
|
-
// 通用字段组装
|
|
15
|
-
main = (trackingId: string, params?: any, executeAttributes = true) => {
|
|
16
|
-
// 预置事件或者默认就是发给主实例的事件不需要传trackingId
|
|
17
|
-
if (!trackingId) {
|
|
18
|
-
trackingId = this.growingIO.trackingId;
|
|
19
|
-
}
|
|
20
|
-
const {
|
|
21
|
-
sdkVersion,
|
|
22
|
-
platformConfig,
|
|
23
|
-
minipInstance,
|
|
24
|
-
userStore,
|
|
25
|
-
dataStore,
|
|
26
|
-
dataStore: {
|
|
27
|
-
scene,
|
|
28
|
-
eventHooks: { currentPage },
|
|
29
|
-
generalProps
|
|
30
|
-
}
|
|
31
|
-
} = this.growingIO;
|
|
32
|
-
const { version, dataSourceId, appId, idMapping, ignoreFields } =
|
|
33
|
-
dataStore.getTrackerVds(trackingId);
|
|
34
|
-
const locationData = dataStore.locationData[trackingId];
|
|
35
|
-
const { systemInfo = {}, network = {} } = minipInstance;
|
|
36
|
-
const { brand, model, platform, language } = systemInfo;
|
|
37
|
-
const pagePath = currentPage.getPagePath();
|
|
38
|
-
// 事件主要内容组装
|
|
39
|
-
const context: any = {
|
|
40
|
-
appChannel: `scn:${scene || 'NA'}`,
|
|
41
|
-
appVersion: version,
|
|
42
|
-
dataSourceId: dataSourceId,
|
|
43
|
-
deviceBrand: brand,
|
|
44
|
-
deviceId: userStore.getUid(),
|
|
45
|
-
deviceModel: model,
|
|
46
|
-
deviceType: getOS(platform, platformConfig.name),
|
|
47
|
-
domain: appId,
|
|
48
|
-
language: language,
|
|
49
|
-
latitude: locationData?.latitude,
|
|
50
|
-
longitude: locationData?.longitude,
|
|
51
|
-
networkState: network?.networkType || network?.type || network?.subtype,
|
|
52
|
-
operatingSystem: getOS(platform, platformConfig.name),
|
|
53
|
-
path: pagePath, // 如果页面中的path取不到,说明页面没初始化
|
|
54
|
-
platform: platformConfig.platform,
|
|
55
|
-
platformVersion:
|
|
56
|
-
platformConfig.name +
|
|
57
|
-
(systemInfo.version ? ` ${systemInfo.version}` : ''),
|
|
58
|
-
query: pagePath ? currentPage.getPageQuery() : '', // 如果页面中的path取不到,说明页面没初始化
|
|
59
|
-
screenHeight: getScreenHeight(systemInfo),
|
|
60
|
-
screenWidth: getScreenWidth(systemInfo),
|
|
61
|
-
sdkVersion,
|
|
62
|
-
sessionId: userStore.getSessionId(trackingId),
|
|
63
|
-
title: currentPage.getPageTitle(),
|
|
64
|
-
timestamp: Date.now(),
|
|
65
|
-
timezoneOffset: new Date().getTimezoneOffset(),
|
|
66
|
-
userId: userStore.getUserId(trackingId)
|
|
67
|
-
};
|
|
68
|
-
if (idMapping) {
|
|
69
|
-
context.userKey = userStore.getUserKey(trackingId);
|
|
70
|
-
}
|
|
71
|
-
// 全局属性
|
|
72
|
-
if (executeAttributes && !isEmpty(generalProps[trackingId])) {
|
|
73
|
-
context.attributes = { ...generalProps[trackingId] };
|
|
74
|
-
}
|
|
75
|
-
// 属性格式化
|
|
76
|
-
if (!isEmpty(context.attributes)) {
|
|
77
|
-
context.attributes = limitObject(
|
|
78
|
-
getDynamicAttributes({ ...context.attributes })
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
if (!isEmpty(ignoreFields)) {
|
|
82
|
-
ignoreFields.forEach((o) => {
|
|
83
|
-
unset(context, o);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
// 此时可能存在数据为空的字段,在数据组装完成后由转换方法移除空值字段
|
|
87
|
-
if (!isEmpty(params)) {
|
|
88
|
-
return { ...context, ...params, trackingId };
|
|
89
|
-
} else {
|
|
90
|
-
return { ...context, trackingId };
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export default EventContextBuilder;
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { AppHookLifeCircle } from '@@/types/eventHooks';
|
|
2
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
3
|
-
import { isEmpty, typeOf, unset } from '@@/utils/glodash';
|
|
4
|
-
import { getLaunchQuery, qsStringify } from '@@/utils/tools';
|
|
5
|
-
import EMIT_MSG from '@@/constants/emitMsg';
|
|
6
|
-
|
|
7
|
-
class AppEffects {
|
|
8
|
-
public enterParams: any = {};
|
|
9
|
-
constructor(public growingIO: GrowingIOType) {}
|
|
10
|
-
|
|
11
|
-
main = (event: AppHookLifeCircle, args: any) => {
|
|
12
|
-
const eventTime = Date.now();
|
|
13
|
-
const {
|
|
14
|
-
emitter,
|
|
15
|
-
userStore,
|
|
16
|
-
vdsConfig,
|
|
17
|
-
platformConfig,
|
|
18
|
-
uploader,
|
|
19
|
-
dataStore,
|
|
20
|
-
minipInstance,
|
|
21
|
-
dataStore: {
|
|
22
|
-
trackersExecute,
|
|
23
|
-
shareOut,
|
|
24
|
-
lastCloseTime,
|
|
25
|
-
saveStorageInfo,
|
|
26
|
-
setOriginalSource
|
|
27
|
-
}
|
|
28
|
-
}: GrowingIOType = this.growingIO;
|
|
29
|
-
emitter.emit(EMIT_MSG.MINIP_LIFECYCLE, {
|
|
30
|
-
event: `App ${event}`,
|
|
31
|
-
timestamp: eventTime,
|
|
32
|
-
params: args[0] ?? {}
|
|
33
|
-
});
|
|
34
|
-
if (vdsConfig.debug) {
|
|
35
|
-
console.log('App:', event, eventTime);
|
|
36
|
-
}
|
|
37
|
-
const appListeners = platformConfig.listeners.app;
|
|
38
|
-
// 向插件广播事件
|
|
39
|
-
emitter.emit(EMIT_MSG.ON_COMPOSE_BEFORE, {
|
|
40
|
-
event: `App ${event}`,
|
|
41
|
-
params: args[0] ?? {}
|
|
42
|
-
});
|
|
43
|
-
switch (event) {
|
|
44
|
-
case appListeners.appLaunch:
|
|
45
|
-
// 在launch先获取一次是防止在此生命周期中发埋点或调用其他api时获取不到path和query
|
|
46
|
-
this.enterParams = { ...args[0] };
|
|
47
|
-
break;
|
|
48
|
-
// 快应用是执行onCreate
|
|
49
|
-
case appListeners.appCreate:
|
|
50
|
-
// 各小程序执行onShow
|
|
51
|
-
case appListeners.appShow: {
|
|
52
|
-
// 获取进入小程序的path、query和scene
|
|
53
|
-
const { path, query, referralPage } = this.enterParamsParse(args[0]);
|
|
54
|
-
if (!shareOut && vdsConfig.originalSource) {
|
|
55
|
-
// 个别(说的就是你:淘宝)小程序场景值不一样后台拉起时可能args中会没有path和query
|
|
56
|
-
if (path) {
|
|
57
|
-
// 保存初始来源信息
|
|
58
|
-
trackersExecute((trackingId: string) => {
|
|
59
|
-
setOriginalSource(trackingId, { path, query, referralPage });
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// 以下条件均会被认为是一次新的访问
|
|
64
|
-
// 没有关闭时间说明是新访问
|
|
65
|
-
if (!lastCloseTime) {
|
|
66
|
-
trackersExecute((trackingId: string) => {
|
|
67
|
-
dataStore.lastVisitEvent[trackingId] = {
|
|
68
|
-
path,
|
|
69
|
-
query,
|
|
70
|
-
referralPage
|
|
71
|
-
};
|
|
72
|
-
this.buildVisitEvent(trackingId, { path, query, referralPage });
|
|
73
|
-
});
|
|
74
|
-
} else if (
|
|
75
|
-
// 两次打开间隔时间超过keepAlive设定(默认5分钟)
|
|
76
|
-
Date.now() - lastCloseTime > vdsConfig.keepAlive * 60 * 1000 ||
|
|
77
|
-
// 两次打开时的场景值不一样(即从不同的来源进入小程序)
|
|
78
|
-
(dataStore.lastScene && dataStore.scene !== dataStore.lastScene)
|
|
79
|
-
) {
|
|
80
|
-
// 重置sessionId
|
|
81
|
-
trackersExecute((trackingId: string) => {
|
|
82
|
-
userStore.setSessionId(trackingId);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
// 添加网络状态变更监听
|
|
86
|
-
minipInstance.setNetworkStatusListener();
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case appListeners.appClose: {
|
|
90
|
-
// 同步信息
|
|
91
|
-
dataStore.lastScene = dataStore.scene;
|
|
92
|
-
dataStore.lastCloseTime = Date.now();
|
|
93
|
-
saveStorageInfo();
|
|
94
|
-
userStore.saveUserInfo();
|
|
95
|
-
trackersExecute((trackingId: string) => {
|
|
96
|
-
this.buildCloseEvent(trackingId);
|
|
97
|
-
// forceLogin不生效时强制把请求队列中的事件全部发送
|
|
98
|
-
if (!vdsConfig.forceLogin) {
|
|
99
|
-
uploader.initiateRequest(trackingId, true);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
default:
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// 进入小程序时的相关数据处理
|
|
111
|
-
enterParamsParse = (args: any = {}) => {
|
|
112
|
-
const { gioPlatform, minipInstance, dataStore } = this.growingIO;
|
|
113
|
-
let rPath = ''; // 进入小程序时的path
|
|
114
|
-
let rQuery = ''; // 进入小程序时的参数(启动参数)
|
|
115
|
-
let rAppId = ''; // scene=1037或1038时来源小程序、公众号或 App 的 appId
|
|
116
|
-
// 支持getEnterOptionsSync
|
|
117
|
-
if (
|
|
118
|
-
gioPlatform !== 'quickapp' &&
|
|
119
|
-
minipInstance.minip.canIUse('getEnterOptionsSync')
|
|
120
|
-
) {
|
|
121
|
-
const { path, query, scene, referrerInfo } =
|
|
122
|
-
minipInstance.minip.getEnterOptionsSync() || {};
|
|
123
|
-
rPath = path || args.path;
|
|
124
|
-
rQuery = query || args.query;
|
|
125
|
-
rAppId = referrerInfo?.appId || args?.referrerInfo?.appId || '';
|
|
126
|
-
dataStore.scene = scene || args.scene;
|
|
127
|
-
// 移除某些小程序圈选时我们带入的圈选地址参数
|
|
128
|
-
unset(query, 'gdpCircleRoomCollectUrl');
|
|
129
|
-
// 来源有额外参数时并入页面参数
|
|
130
|
-
if (!isEmpty(referrerInfo?.extraData)) {
|
|
131
|
-
rQuery = qsStringify(getLaunchQuery(rQuery, referrerInfo.extraData));
|
|
132
|
-
} else {
|
|
133
|
-
rQuery = qsStringify(rQuery);
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
// 不支持的按老逻辑兜底
|
|
137
|
-
const { path, query, referrerInfo } = args;
|
|
138
|
-
rPath = path;
|
|
139
|
-
rQuery = qsStringify(query);
|
|
140
|
-
rAppId = referrerInfo?.appId || '';
|
|
141
|
-
this.parseScene(args);
|
|
142
|
-
}
|
|
143
|
-
return { path: rPath, query: rQuery, referralPage: rAppId };
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// 获取来源场景值
|
|
147
|
-
/**
|
|
148
|
-
* wx:https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html
|
|
149
|
-
* alipay:https://opendocs.alipay.com/mini/framework/scene
|
|
150
|
-
* swan:https://smartprogram.baidu.com/docs/data/host_scene/
|
|
151
|
-
* tt:https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/framework/scene-value/
|
|
152
|
-
* qq:https://q.qq.com/wiki/develop/game/frame/scene/
|
|
153
|
-
* quickapp:https://doc.quickapp.cn/features/system/app.html?h=%E6%9D%A5%E6%BA%90
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
parseScene = (args) => {
|
|
157
|
-
const { minipInstance, gioPlatform, dataStore } = this.growingIO;
|
|
158
|
-
let newScene;
|
|
159
|
-
// 快应用处理逻辑
|
|
160
|
-
if (gioPlatform === 'quickapp') {
|
|
161
|
-
const { extra, type } = minipInstance.getAppSource();
|
|
162
|
-
newScene = extra?.scene || type;
|
|
163
|
-
} else if (!isEmpty(args)) {
|
|
164
|
-
if (args?.query?.wxShoppingListScene) {
|
|
165
|
-
newScene = args.query.wxShoppingListScene;
|
|
166
|
-
} else if (args?.scene) {
|
|
167
|
-
newScene = args.scene;
|
|
168
|
-
} else {
|
|
169
|
-
dataStore.scene = 'NA';
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
dataStore.scene = newScene;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// 构建访问事件
|
|
176
|
-
buildVisitEvent = (trackingId: string, props?: any) => {
|
|
177
|
-
const {
|
|
178
|
-
dataStore: { getOriginalSource, eventContextBuilder, eventInterceptor },
|
|
179
|
-
vdsConfig
|
|
180
|
-
} = this.growingIO;
|
|
181
|
-
const originalSource = getOriginalSource(trackingId);
|
|
182
|
-
// 生命周期中调用构建使用参数赋值,补发场景调用构建使用上一次的值
|
|
183
|
-
const query = props?.query || '';
|
|
184
|
-
let event = {
|
|
185
|
-
eventType: 'VISIT',
|
|
186
|
-
...eventContextBuilder(trackingId, {})
|
|
187
|
-
};
|
|
188
|
-
if (!isEmpty(props) && props.path) {
|
|
189
|
-
// props.path是生命周期值或者是已有的值
|
|
190
|
-
event.path = props.path || '';
|
|
191
|
-
// props.query是对象说明是生命周期调用,否则是补发调用
|
|
192
|
-
event.query = typeOf(query) === 'string' ? query : qsStringify(query);
|
|
193
|
-
// 如果有来源
|
|
194
|
-
if (props.referralPage) {
|
|
195
|
-
event.referralPage = props.referralPage;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// 配置使用初始来源时,visit使用初始来源数据
|
|
199
|
-
if (vdsConfig.originalSource && !isEmpty(originalSource)) {
|
|
200
|
-
event = { ...event, ...originalSource };
|
|
201
|
-
}
|
|
202
|
-
eventInterceptor(event);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
// 构建关闭事件
|
|
206
|
-
buildCloseEvent = (trackingId: string) => {
|
|
207
|
-
const {
|
|
208
|
-
dataStore: { eventContextBuilder, eventInterceptor }
|
|
209
|
-
} = this.growingIO;
|
|
210
|
-
const event = {
|
|
211
|
-
eventType: 'APP_CLOSED',
|
|
212
|
-
...eventContextBuilder(trackingId)
|
|
213
|
-
};
|
|
214
|
-
eventInterceptor(event);
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export default AppEffects;
|