gio-miniprogram-sdk 4.4.2 → 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 -221
- 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 -310
- 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 -146
- 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 -511
- package/src/utils/verifiers.ts +0 -52
- package/tsconfig.json +0 -32
- package/typings/global.d.ts +0 -105
package/src/platformConfig/ks.ts
DELETED
package/src/platformConfig/my.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import BaseConfig from './base';
|
|
2
|
-
|
|
3
|
-
const MyConfig = {
|
|
4
|
-
...BaseConfig,
|
|
5
|
-
listeners: { ...BaseConfig.listeners },
|
|
6
|
-
name: 'Alipay',
|
|
7
|
-
platform: 'alip',
|
|
8
|
-
scnPrefix: 'alip_',
|
|
9
|
-
shareEventTypes: ['onShareAppMessage'],
|
|
10
|
-
hooks: {
|
|
11
|
-
...BaseConfig?.hooks,
|
|
12
|
-
Behavior: false
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default MyConfig;
|
package/src/platformConfig/qq.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import BaseConfig from './base';
|
|
2
|
-
|
|
3
|
-
const QQConfig = {
|
|
4
|
-
...BaseConfig,
|
|
5
|
-
listeners: { ...BaseConfig.listeners },
|
|
6
|
-
name: 'QQ',
|
|
7
|
-
platform: 'qq',
|
|
8
|
-
scnPrefix: 'qq_'
|
|
9
|
-
};
|
|
10
|
-
QQConfig.pageHandlers = [...BaseConfig.pageHandlers, 'onAddToFavorites'];
|
|
11
|
-
QQConfig.listeners.page.addFavorites = 'onAddToFavorites';
|
|
12
|
-
|
|
13
|
-
export default QQConfig;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const QuickAppConfig = {
|
|
2
|
-
name: 'QuickApp',
|
|
3
|
-
platform: 'quickapp',
|
|
4
|
-
scnPrefix: 'quickapp_',
|
|
5
|
-
appHandlers: ['onCreate', 'onShow', 'onHide', 'onDestroy', 'onError'],
|
|
6
|
-
pageHandlers: [
|
|
7
|
-
'onInit',
|
|
8
|
-
'onReady',
|
|
9
|
-
'onShow',
|
|
10
|
-
'onHide',
|
|
11
|
-
'onDestroy',
|
|
12
|
-
'onMenuPress',
|
|
13
|
-
'onShareAppMessage'
|
|
14
|
-
],
|
|
15
|
-
actionEventTypes: ['click', 'longpress', 'blur', 'change'],
|
|
16
|
-
canHook: false,
|
|
17
|
-
hooks: {
|
|
18
|
-
App: false,
|
|
19
|
-
Page: false,
|
|
20
|
-
Component: false,
|
|
21
|
-
Behavior: false
|
|
22
|
-
},
|
|
23
|
-
listeners: {
|
|
24
|
-
app: {
|
|
25
|
-
appCreate: 'onCreate',
|
|
26
|
-
appShow: 'onShow',
|
|
27
|
-
appHide: 'onHide',
|
|
28
|
-
appClose: 'onDestroy'
|
|
29
|
-
},
|
|
30
|
-
page: {
|
|
31
|
-
pageLoad: 'onInit',
|
|
32
|
-
pageReady: 'onReady',
|
|
33
|
-
pageShow: 'onShow',
|
|
34
|
-
pageHide: 'onHide',
|
|
35
|
-
pageClose: 'onDestroy',
|
|
36
|
-
menuPress: 'onMenuPress',
|
|
37
|
-
tabTap: undefined,
|
|
38
|
-
shareApp: 'onShareAppMessage'
|
|
39
|
-
},
|
|
40
|
-
actions: {
|
|
41
|
-
click: ['click', 'longpress'],
|
|
42
|
-
change: ['blur', 'change'],
|
|
43
|
-
submit: []
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export default QuickAppConfig;
|
package/src/platformConfig/tb.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import BaseConfig from './base';
|
|
2
|
-
|
|
3
|
-
const TbConfig = {
|
|
4
|
-
...BaseConfig,
|
|
5
|
-
pageHandlers: [
|
|
6
|
-
...BaseConfig.pageHandlers,
|
|
7
|
-
'onInit',
|
|
8
|
-
'didMount',
|
|
9
|
-
'didUnmount'
|
|
10
|
-
],
|
|
11
|
-
listeners: {
|
|
12
|
-
...BaseConfig.listeners,
|
|
13
|
-
page: {
|
|
14
|
-
...BaseConfig.listeners.page,
|
|
15
|
-
onInit: 'onInit',
|
|
16
|
-
didMount: 'didMount',
|
|
17
|
-
didUnmount: 'didUnmount'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
name: 'Taobao',
|
|
21
|
-
platform: 'tbp',
|
|
22
|
-
scnPrefix: 'tbp_',
|
|
23
|
-
hooks: {
|
|
24
|
-
...BaseConfig?.hooks,
|
|
25
|
-
Behavior: false
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default TbConfig;
|
package/src/platformConfig/tt.ts
DELETED
package/src/platformConfig/wx.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import BaseConfig from './base';
|
|
2
|
-
|
|
3
|
-
const WXConfig = {
|
|
4
|
-
...BaseConfig,
|
|
5
|
-
listeners: { ...BaseConfig.listeners },
|
|
6
|
-
name: 'Weixin',
|
|
7
|
-
platform: 'MinP'
|
|
8
|
-
};
|
|
9
|
-
WXConfig.pageHandlers = [
|
|
10
|
-
...BaseConfig.pageHandlers,
|
|
11
|
-
'onShareTimeline',
|
|
12
|
-
'onAddToFavorites'
|
|
13
|
-
];
|
|
14
|
-
WXConfig.listeners.page = {
|
|
15
|
-
...BaseConfig.listeners.page,
|
|
16
|
-
shareTime: 'onShareTimeline',
|
|
17
|
-
addFavorites: 'onAddToFavorites'
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default WXConfig;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import BaseConfig from './base';
|
|
2
|
-
|
|
3
|
-
const XHSConfig = {
|
|
4
|
-
...BaseConfig,
|
|
5
|
-
pageHandlers: [
|
|
6
|
-
...BaseConfig.pageHandlers,
|
|
7
|
-
'onShareChat',
|
|
8
|
-
'onCopyUrl',
|
|
9
|
-
'onShareAppMessage',
|
|
10
|
-
'onShareTimeline'
|
|
11
|
-
],
|
|
12
|
-
shareEventTypes: [...BaseConfig.shareEventTypes, 'onShareChat', 'onCopyUrl'],
|
|
13
|
-
listeners: {
|
|
14
|
-
...BaseConfig.listeners,
|
|
15
|
-
page: {
|
|
16
|
-
...BaseConfig.listeners.page,
|
|
17
|
-
shareTime: 'onShareTimeline',
|
|
18
|
-
shareChat: 'onShareChat',
|
|
19
|
-
copyUrl: 'onCopyUrl'
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
name: 'XiaoHongShu',
|
|
23
|
-
platform: 'xhsp',
|
|
24
|
-
scnPrefix: 'xhs_'
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default XHSConfig;
|
package/src/plugins/gioABTest.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 名称:ABTest插件
|
|
3
|
-
* 用途:用于提供自动获取AB实验数据和上报实验命中的插件。
|
|
4
|
-
*/
|
|
5
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
|
-
import {
|
|
7
|
-
isEmpty,
|
|
8
|
-
isNaN,
|
|
9
|
-
isNumber,
|
|
10
|
-
isObject,
|
|
11
|
-
isString,
|
|
12
|
-
keys,
|
|
13
|
-
startsWith,
|
|
14
|
-
toString,
|
|
15
|
-
unset
|
|
16
|
-
} from '@@/utils/glodash';
|
|
17
|
-
import {
|
|
18
|
-
consoleText,
|
|
19
|
-
hashCode,
|
|
20
|
-
limitObject,
|
|
21
|
-
niceCallback
|
|
22
|
-
} from '@@/utils/tools';
|
|
23
|
-
import EMIT_MSG from '@@/constants/emitMsg';
|
|
24
|
-
import { ABTEST_DATA_REG, ABTEST_SIGN_REG } from '@@/constants/regex';
|
|
25
|
-
|
|
26
|
-
class GioABTest {
|
|
27
|
-
public pluginVersion: string;
|
|
28
|
-
// 请求间隔时长
|
|
29
|
-
public requestInterval: number;
|
|
30
|
-
// 请求超时时长
|
|
31
|
-
public requestTimeout: number;
|
|
32
|
-
// 分流服务请求地址
|
|
33
|
-
public url: any;
|
|
34
|
-
// 接口重试计数
|
|
35
|
-
public retryCount: number;
|
|
36
|
-
// 标记当前是否为新访问设备
|
|
37
|
-
public newDevice: boolean;
|
|
38
|
-
// 各个实例新设备进入时的sessionId;小程序没有刷新页面保持session的问题,所以存在内存里就可以
|
|
39
|
-
public visitSids: any;
|
|
40
|
-
constructor(public growingIO: GrowingIOType, options: any) {
|
|
41
|
-
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
42
|
-
const {
|
|
43
|
-
abServerUrl = 'https://ab.growingio.com',
|
|
44
|
-
requestInterval,
|
|
45
|
-
requestTimeout
|
|
46
|
-
} = options ?? {};
|
|
47
|
-
this.timeoutCheck(requestInterval, requestTimeout);
|
|
48
|
-
const { emitter, userStore } = this.growingIO;
|
|
49
|
-
this.growingIO.getABTest = this.getABTest;
|
|
50
|
-
this.visitSids = {};
|
|
51
|
-
emitter.on(EMIT_MSG.OPTION_INITIALIZED, () => {
|
|
52
|
-
if (!isEmpty(abServerUrl)) {
|
|
53
|
-
this.abtStorageCheck();
|
|
54
|
-
this.url = {};
|
|
55
|
-
if (isString(abServerUrl)) {
|
|
56
|
-
this.generateUrl(this.growingIO.trackingId, abServerUrl);
|
|
57
|
-
} else if (isObject(abServerUrl)) {
|
|
58
|
-
keys(abServerUrl).forEach((trackingId: string) => {
|
|
59
|
-
this.generateUrl(trackingId, abServerUrl[trackingId]);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
consoleText(
|
|
64
|
-
'如果您需要使用ABTest功能,请配置服务地址 abServerUrl!',
|
|
65
|
-
'warn'
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
emitter.on(EMIT_MSG.UID_UPDATE, ({ newUId, oldUId }) => {
|
|
70
|
-
// 没有旧deviceId说明是第一次进入的新设备
|
|
71
|
-
if (!oldUId && newUId) {
|
|
72
|
-
if (isString(abServerUrl)) {
|
|
73
|
-
const trackingId = this.growingIO.trackingId;
|
|
74
|
-
const sId = userStore.getSessionId(trackingId);
|
|
75
|
-
this.visitSids[trackingId] = sId;
|
|
76
|
-
} else if (isObject(abServerUrl)) {
|
|
77
|
-
keys(abServerUrl).forEach((trackingId: string) => {
|
|
78
|
-
const sId = userStore.getSessionId(trackingId);
|
|
79
|
-
this.visitSids[trackingId] = sId;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
this.retryCount = 0;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 两个时长的初始化处理
|
|
88
|
-
timeoutCheck = (
|
|
89
|
-
requestInterval: number | string,
|
|
90
|
-
requestTimeout: number | string
|
|
91
|
-
) => {
|
|
92
|
-
this.requestInterval =
|
|
93
|
-
isNumber(Number(requestInterval)) &&
|
|
94
|
-
!isNaN(Number(requestInterval as string))
|
|
95
|
-
? Number(requestInterval as string)
|
|
96
|
-
: 5;
|
|
97
|
-
if (this.requestInterval > 60 * 24 || this.requestInterval < 0) {
|
|
98
|
-
this.requestInterval = 5;
|
|
99
|
-
}
|
|
100
|
-
this.requestTimeout =
|
|
101
|
-
isNumber(Number(requestTimeout)) &&
|
|
102
|
-
!isNaN(Number(requestTimeout as string))
|
|
103
|
-
? Number(requestTimeout as string)
|
|
104
|
-
: 1000;
|
|
105
|
-
if (this.requestTimeout > 5000 || this.requestTimeout < 100) {
|
|
106
|
-
this.requestTimeout = 1000;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// 检查存储中的实验数据是否已过期
|
|
111
|
-
abtStorageCheck = () => {
|
|
112
|
-
const { minipInstance }: any = this.growingIO;
|
|
113
|
-
const storageKeys = minipInstance.minip?.getStorageInfoSync().keys || [];
|
|
114
|
-
// 请求标记
|
|
115
|
-
const abtsKeys = storageKeys.filter((k) => ABTEST_SIGN_REG.test(k));
|
|
116
|
-
abtsKeys.forEach((k) => {
|
|
117
|
-
// 移除过期的数据,防止存储超限
|
|
118
|
-
const sign = minipInstance.getStorageSync(k);
|
|
119
|
-
if (!sign || sign < Date.now()) {
|
|
120
|
-
minipInstance.removeStorageSync(k);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
// abtest数据
|
|
124
|
-
const abtdKeys = storageKeys.filter((k) => ABTEST_DATA_REG.test(k));
|
|
125
|
-
abtdKeys.forEach((k) => {
|
|
126
|
-
// 移除过期的数据,防止存储超限
|
|
127
|
-
if (isEmpty(minipInstance.getStorageSync(k))) {
|
|
128
|
-
minipInstance.removeStorageSync(k);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// 生成存储的hash key
|
|
134
|
-
getHashKey = (trackingId: string, layerId: string | number) => {
|
|
135
|
-
const {
|
|
136
|
-
userStore: { getUid },
|
|
137
|
-
vdsConfig: { projectId }
|
|
138
|
-
} = this.growingIO;
|
|
139
|
-
return hashCode(`${trackingId}#${projectId}#${getUid()}#${layerId}`, true);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// 生成数据接口地址
|
|
143
|
-
generateUrl = (trackingId: string, abServerUrl: string) => {
|
|
144
|
-
// 如果是延迟初始化的实例,当前又是首次进入设备,要补充把session存起来
|
|
145
|
-
if (this.newDevice && !this.visitSids[trackingId]) {
|
|
146
|
-
// 这里要用userStore中的getSessionId,调用这个方法的时候实例肯定已经初始化了
|
|
147
|
-
// 如果是新初始化可以通过getSessionId准确获取sessionExpires来生成准确的session值;
|
|
148
|
-
// 如果是旧实例则直接用存储中的sessionId
|
|
149
|
-
this.visitSids[trackingId] =
|
|
150
|
-
this.growingIO.userStore.getSessionId(trackingId);
|
|
151
|
-
}
|
|
152
|
-
if (!startsWith(abServerUrl, 'http')) {
|
|
153
|
-
this.url[
|
|
154
|
-
trackingId
|
|
155
|
-
] = `https://${abServerUrl}/diversion/specified-layer-variables`;
|
|
156
|
-
} else {
|
|
157
|
-
this.url[
|
|
158
|
-
trackingId
|
|
159
|
-
] = `${abServerUrl}/diversion/specified-layer-variables`;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// 获取实验调用
|
|
164
|
-
getABTest = (trackingId: string, layerId: string | number, callback: any) => {
|
|
165
|
-
if (isEmpty(this.url[trackingId])) {
|
|
166
|
-
this.generateUrl(trackingId, 'https://ab.growingio.com');
|
|
167
|
-
}
|
|
168
|
-
if (!layerId) {
|
|
169
|
-
consoleText('获取ABTest数据失败! 实验层Id不合法!', 'error');
|
|
170
|
-
niceCallback(callback, {});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const { minipInstance } = this.growingIO;
|
|
174
|
-
// 接口调用的超时时间
|
|
175
|
-
const abtSign =
|
|
176
|
-
minipInstance.getStorageSync(
|
|
177
|
-
`${this.getHashKey(trackingId, layerId)}_gdp_abt_sign`
|
|
178
|
-
) || 0;
|
|
179
|
-
// 没有超时尝试取数据
|
|
180
|
-
const expData =
|
|
181
|
-
minipInstance.getStorageSync(
|
|
182
|
-
`${this.getHashKey(trackingId, layerId)}_gdp_abtd`
|
|
183
|
-
) || {};
|
|
184
|
-
// 没有有效数据或者接口请求标记超时则从调用分流服务获取数据
|
|
185
|
-
if (!abtSign || abtSign < Date.now()) {
|
|
186
|
-
this.initiateRequest(trackingId, layerId, expData, callback);
|
|
187
|
-
} else {
|
|
188
|
-
niceCallback(callback, expData);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// 发起请求
|
|
193
|
-
initiateRequest = (
|
|
194
|
-
trackingId: string,
|
|
195
|
-
layerId: string | number,
|
|
196
|
-
originData: any,
|
|
197
|
-
callback: any
|
|
198
|
-
) => {
|
|
199
|
-
const {
|
|
200
|
-
userStore: { getUid, getSessionId },
|
|
201
|
-
dataStore,
|
|
202
|
-
minipInstance
|
|
203
|
-
} = this.growingIO;
|
|
204
|
-
const { projectId, dataSourceId } = dataStore.getTrackerVds(trackingId);
|
|
205
|
-
minipInstance.request({
|
|
206
|
-
url: this.url[trackingId],
|
|
207
|
-
header: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
208
|
-
method: 'POST',
|
|
209
|
-
data: {
|
|
210
|
-
accountId: projectId,
|
|
211
|
-
datasourceId: dataSourceId,
|
|
212
|
-
distinctId: getUid(),
|
|
213
|
-
layerId,
|
|
214
|
-
newDevice: this.visitSids[trackingId] === getSessionId(trackingId)
|
|
215
|
-
},
|
|
216
|
-
timeout: this.requestTimeout,
|
|
217
|
-
success: ({ data }: any) => {
|
|
218
|
-
if (data.code === 0) {
|
|
219
|
-
this.experimentVerify(
|
|
220
|
-
trackingId,
|
|
221
|
-
{ ...data, layerId },
|
|
222
|
-
originData,
|
|
223
|
-
callback
|
|
224
|
-
);
|
|
225
|
-
} else {
|
|
226
|
-
consoleText(`获取ABTest数据失败! ${data.errorMsg}!`, 'error');
|
|
227
|
-
// 接口业务失败返回false信息
|
|
228
|
-
niceCallback(callback, {});
|
|
229
|
-
}
|
|
230
|
-
// 接口调用返回后刷新接口调用标记
|
|
231
|
-
minipInstance.setStorageSync(
|
|
232
|
-
`${this.getHashKey(trackingId, layerId)}_gdp_abt_sign`,
|
|
233
|
-
Date.now() + 1000 * 60 * this.requestInterval
|
|
234
|
-
);
|
|
235
|
-
},
|
|
236
|
-
fail: ({ errMsg }: any) => {
|
|
237
|
-
// 请求超时(这里没用微信提供的errno,因为它没有值,其他小程序也不一定能兼容)
|
|
238
|
-
if (errMsg.indexOf('timeout') > -1) {
|
|
239
|
-
consoleText('获取ABTest数据失败! 请求超时!', 'error');
|
|
240
|
-
// 接口超时返回false信息
|
|
241
|
-
niceCallback(callback, {});
|
|
242
|
-
} else {
|
|
243
|
-
// 其他失败情况重试
|
|
244
|
-
if (this.retryCount < 2) {
|
|
245
|
-
this.initiateRequest(trackingId, layerId, originData, callback);
|
|
246
|
-
this.retryCount += 1;
|
|
247
|
-
} else {
|
|
248
|
-
consoleText(
|
|
249
|
-
`获取ABTest数据失败! ${JSON.stringify(errMsg).slice(0, 30)}!`,
|
|
250
|
-
'error'
|
|
251
|
-
);
|
|
252
|
-
// 重试结束后返回false信息
|
|
253
|
-
niceCallback(callback, {});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
// 实验校验(决定是否上报命中事件)
|
|
261
|
-
experimentVerify = (
|
|
262
|
-
trackingId: string,
|
|
263
|
-
responseData: any,
|
|
264
|
-
originData: any,
|
|
265
|
-
callback: any
|
|
266
|
-
) => {
|
|
267
|
-
const {
|
|
268
|
-
layerId,
|
|
269
|
-
strategyId,
|
|
270
|
-
experimentId,
|
|
271
|
-
layerName,
|
|
272
|
-
experimentName,
|
|
273
|
-
strategyName,
|
|
274
|
-
variables
|
|
275
|
-
} = responseData;
|
|
276
|
-
const expDataKey = `${this.getHashKey(trackingId, layerId)}_gdp_abtd`;
|
|
277
|
-
// 从接口取回来的用于hash比较的数据对象
|
|
278
|
-
const comparisonData = {
|
|
279
|
-
layerId: toString(layerId),
|
|
280
|
-
strategyId: toString(strategyId),
|
|
281
|
-
experimentId: toString(experimentId),
|
|
282
|
-
variables
|
|
283
|
-
};
|
|
284
|
-
// 从本地存储中取回来的用于hash比较的数据对象
|
|
285
|
-
const controlData = { ...originData };
|
|
286
|
-
unset(controlData, ['layerName', 'strategyName', 'experimentName']);
|
|
287
|
-
const comparisonValue = hashCode(JSON.stringify(comparisonData));
|
|
288
|
-
const controlValue = hashCode(JSON.stringify(controlData));
|
|
289
|
-
// 需要传给下一步和存储的数据对象
|
|
290
|
-
const expData = {
|
|
291
|
-
...comparisonData,
|
|
292
|
-
layerName,
|
|
293
|
-
strategyName,
|
|
294
|
-
experimentName
|
|
295
|
-
};
|
|
296
|
-
// 存储实验数据(无需经过hash对比判断直接复写存储,防止只改了名称)
|
|
297
|
-
this.growingIO.minipInstance.setStorageSync(
|
|
298
|
-
expDataKey,
|
|
299
|
-
expData,
|
|
300
|
-
new Date(
|
|
301
|
-
new Date().getFullYear(),
|
|
302
|
-
new Date().getMonth(),
|
|
303
|
-
new Date().getDate() + 1
|
|
304
|
-
).getTime()
|
|
305
|
-
);
|
|
306
|
-
// 本地实验和请求回来的实验直接做整体hash数据对比
|
|
307
|
-
if (comparisonValue !== controlValue) {
|
|
308
|
-
// 数据不一致重新发命中埋点
|
|
309
|
-
if (strategyId && experimentId) {
|
|
310
|
-
this.buildExperimentHitEvent(trackingId, expData);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
// 回调调用
|
|
314
|
-
niceCallback(callback, expData);
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
// 构建实验命中事件
|
|
318
|
-
buildExperimentHitEvent = (trackingId: string, expData: any) => {
|
|
319
|
-
const {
|
|
320
|
-
dataStore: { eventContextBuilder, eventConverter }
|
|
321
|
-
} = this.growingIO;
|
|
322
|
-
let event = {
|
|
323
|
-
eventType: 'CUSTOM',
|
|
324
|
-
eventName: '$exp_hit',
|
|
325
|
-
...eventContextBuilder(trackingId)
|
|
326
|
-
};
|
|
327
|
-
const {
|
|
328
|
-
layerId,
|
|
329
|
-
experimentId,
|
|
330
|
-
strategyId,
|
|
331
|
-
layerName,
|
|
332
|
-
experimentName,
|
|
333
|
-
strategyName
|
|
334
|
-
} = expData;
|
|
335
|
-
event.attributes = limitObject({
|
|
336
|
-
...(event.attributes ?? {}),
|
|
337
|
-
$exp_layer_id: layerId,
|
|
338
|
-
$exp_id: experimentId,
|
|
339
|
-
$exp_strategy_id: strategyId,
|
|
340
|
-
$exp_layer_name: layerName,
|
|
341
|
-
$exp_name: experimentName,
|
|
342
|
-
$exp_strategy_name: strategyName
|
|
343
|
-
});
|
|
344
|
-
eventConverter(event);
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export default { name: 'gioABTest', method: GioABTest };
|