gio-miniprogram-sdk 4.2.0 → 4.3.1
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/.github/workflows/publish.yml +2 -0
- 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/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 +1 -1
- package/rollup.config.js +1 -1
- package/rollup.plugins.config.js +1 -1
- package/src/adapters/gioTaobaoAdapter.ts +5 -3
- package/src/adapters/gioTaroAdapter.ts +16 -10
- package/src/adapters/gioUniAppAdapter.ts +1 -32
- package/src/constants/config.ts +5 -1
- package/src/core/dataStore/eventContextBuilder.ts +4 -8
- package/src/core/dataStore/eventHooks/appEffects.ts +53 -79
- package/src/core/dataStore/eventHooks/index.ts +39 -23
- package/src/core/dataStore/eventHooks/minipPage.ts +108 -44
- package/src/core/dataStore/eventHooks/pageEffects.ts +31 -40
- package/src/core/dataStore/index.ts +90 -61
- package/src/core/growingIO.ts +17 -26
- package/src/core/userStore.ts +26 -0
- package/src/index.ts +12 -12
- package/src/minipInstance/base.ts +54 -27
- package/src/minipInstance/my.ts +6 -1
- package/src/minipInstance/tb.ts +6 -1
- package/src/plugins/gioABTest.ts +54 -33
- package/src/plugins/gioImpressionTracking.ts +14 -10
- package/src/plugins/gioMultipleInstances.ts +2 -0
- package/src/types/base.ts +4 -0
- package/src/types/eventHooks.ts +12 -9
- package/src/types/userStore.ts +2 -0
- package/src/utils/tools.ts +22 -3
package/src/minipInstance/my.ts
CHANGED
|
@@ -20,7 +20,7 @@ class Alipay extends BaseImplements {
|
|
|
20
20
|
// 这个currentPath一般认为是在onLoad中获取的当前小程序页面的path,此时SDK还没有parse,保存的还是上一个页面的信息
|
|
21
21
|
const currentPath = self.getCurrentPath();
|
|
22
22
|
const { title } = arguments[0] || {};
|
|
23
|
-
self.growingIO.dataStore.eventHooks.currentPage.
|
|
23
|
+
self.growingIO.dataStore.eventHooks.currentPage.configuredTitle[
|
|
24
24
|
currentPath
|
|
25
25
|
] = title;
|
|
26
26
|
}
|
|
@@ -48,6 +48,11 @@ class Alipay extends BaseImplements {
|
|
|
48
48
|
setStorageSync = (key: string, value: any) => {
|
|
49
49
|
this.minip?.setStorageSync({ key, data: value });
|
|
50
50
|
};
|
|
51
|
+
|
|
52
|
+
// 同步移除指定数据
|
|
53
|
+
removeStorageSync = (key: string) => {
|
|
54
|
+
this.minip?.removeStorageSync({ key });
|
|
55
|
+
};
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
export default Alipay;
|
package/src/minipInstance/tb.ts
CHANGED
|
@@ -20,7 +20,7 @@ class Taobao extends BaseImplements {
|
|
|
20
20
|
// 这个currentPath一般认为是在onLoad中获取的当前小程序页面的path,此时SDK还没有parse,保存的还是上一个页面的信息
|
|
21
21
|
const currentPath = self.getCurrentPath();
|
|
22
22
|
const { title } = arguments[0] || {};
|
|
23
|
-
self.growingIO.dataStore.eventHooks.currentPage.
|
|
23
|
+
self.growingIO.dataStore.eventHooks.currentPage.configuredTitle[
|
|
24
24
|
currentPath
|
|
25
25
|
] = title;
|
|
26
26
|
}
|
|
@@ -48,6 +48,11 @@ class Taobao extends BaseImplements {
|
|
|
48
48
|
setStorageSync = (key: string, value: any) => {
|
|
49
49
|
this.minip?.setStorageSync({ key, data: value });
|
|
50
50
|
};
|
|
51
|
+
|
|
52
|
+
// 同步移除指定数据
|
|
53
|
+
removeStorageSync = (key: string) => {
|
|
54
|
+
this.minip?.removeStorageSync({ key });
|
|
55
|
+
};
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
export default Taobao;
|
package/src/plugins/gioABTest.ts
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
isString,
|
|
12
12
|
keys,
|
|
13
13
|
startsWith,
|
|
14
|
-
toString
|
|
14
|
+
toString,
|
|
15
|
+
unset
|
|
15
16
|
} from '@@/utils/glodash';
|
|
16
17
|
import {
|
|
17
18
|
consoleText,
|
|
@@ -148,15 +149,15 @@ class GioABTest {
|
|
|
148
149
|
`${this.getHashKey(trackingId, layerId)}_gdp_abt_sign`
|
|
149
150
|
) || 0;
|
|
150
151
|
// 没有超时尝试取数据
|
|
151
|
-
const
|
|
152
|
+
const expData =
|
|
152
153
|
minipInstance.getStorageSync(
|
|
153
154
|
`${this.getHashKey(trackingId, layerId)}_gdp_abtd`
|
|
154
155
|
) || {};
|
|
155
156
|
// 没有有效数据或者接口请求标记超时则从调用分流服务获取数据
|
|
156
157
|
if (!abtSign || abtSign < Date.now()) {
|
|
157
|
-
this.initiateRequest(trackingId, layerId,
|
|
158
|
+
this.initiateRequest(trackingId, layerId, expData, callback);
|
|
158
159
|
} else {
|
|
159
|
-
niceCallback(callback,
|
|
160
|
+
niceCallback(callback, expData);
|
|
160
161
|
}
|
|
161
162
|
};
|
|
162
163
|
|
|
@@ -234,49 +235,58 @@ class GioABTest {
|
|
|
234
235
|
originData: any,
|
|
235
236
|
callback: any
|
|
236
237
|
) => {
|
|
237
|
-
const {
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const {
|
|
239
|
+
layerId,
|
|
240
|
+
strategyId,
|
|
241
|
+
experimentId,
|
|
242
|
+
layerName,
|
|
243
|
+
experimentName,
|
|
244
|
+
strategyName,
|
|
245
|
+
variables
|
|
246
|
+
} = responseData;
|
|
247
|
+
const expDataKey = `${this.getHashKey(trackingId, layerId)}_gdp_abtd`;
|
|
248
|
+
// 从接口取回来的用于hash比较的数据对象
|
|
249
|
+
const comparisonData = {
|
|
240
250
|
layerId: toString(layerId),
|
|
241
251
|
strategyId: toString(strategyId),
|
|
242
252
|
experimentId: toString(experimentId),
|
|
243
253
|
variables
|
|
244
254
|
};
|
|
245
|
-
|
|
246
|
-
const
|
|
255
|
+
// 从本地存储中取回来的用于hash比较的数据对象
|
|
256
|
+
const controlData = { ...originData };
|
|
257
|
+
unset(controlData, ['layerName', 'strategyName', 'experimentName']);
|
|
258
|
+
const comparisonValue = hashCode(JSON.stringify(comparisonData));
|
|
259
|
+
const controlValue = hashCode(JSON.stringify(controlData));
|
|
260
|
+
// 需要传给下一步和存储的数据对象
|
|
261
|
+
const expData = {
|
|
262
|
+
...comparisonData,
|
|
263
|
+
layerName,
|
|
264
|
+
strategyName,
|
|
265
|
+
experimentName
|
|
266
|
+
};
|
|
267
|
+
// 存储实验数据(无需经过hash对比判断直接复写存储,防止只改了名称)
|
|
268
|
+
this.growingIO.minipInstance.setStorageSync(
|
|
269
|
+
expDataKey,
|
|
270
|
+
expData,
|
|
271
|
+
new Date(
|
|
272
|
+
new Date().getFullYear(),
|
|
273
|
+
new Date().getMonth(),
|
|
274
|
+
new Date().getDate() + 1
|
|
275
|
+
).getTime()
|
|
276
|
+
);
|
|
247
277
|
// 本地实验和请求回来的实验直接做整体hash数据对比
|
|
248
278
|
if (comparisonValue !== controlValue) {
|
|
249
|
-
// 存储实验数据
|
|
250
|
-
this.growingIO.minipInstance.setStorageSync(
|
|
251
|
-
abtDataKey,
|
|
252
|
-
abtData,
|
|
253
|
-
new Date(
|
|
254
|
-
new Date().getFullYear(),
|
|
255
|
-
new Date().getMonth(),
|
|
256
|
-
new Date().getDate() + 1
|
|
257
|
-
).getTime()
|
|
258
|
-
);
|
|
259
279
|
// 数据不一致重新发命中埋点
|
|
260
280
|
if (strategyId && experimentId) {
|
|
261
|
-
this.buildExperimentHitEvent(
|
|
262
|
-
trackingId,
|
|
263
|
-
toString(layerId),
|
|
264
|
-
toString(experimentId),
|
|
265
|
-
toString(strategyId)
|
|
266
|
-
);
|
|
281
|
+
this.buildExperimentHitEvent(trackingId, expData);
|
|
267
282
|
}
|
|
268
283
|
}
|
|
269
284
|
// 回调调用
|
|
270
|
-
niceCallback(callback,
|
|
285
|
+
niceCallback(callback, expData);
|
|
271
286
|
};
|
|
272
287
|
|
|
273
288
|
// 构建实验命中事件
|
|
274
|
-
buildExperimentHitEvent = (
|
|
275
|
-
trackingId: string,
|
|
276
|
-
layerId: string,
|
|
277
|
-
experimentId: string,
|
|
278
|
-
strategyId: string
|
|
279
|
-
) => {
|
|
289
|
+
buildExperimentHitEvent = (trackingId: string, expData: any) => {
|
|
280
290
|
const {
|
|
281
291
|
dataStore: { eventContextBuilder, eventConverter }
|
|
282
292
|
} = this.growingIO;
|
|
@@ -285,11 +295,22 @@ class GioABTest {
|
|
|
285
295
|
eventName: '$exp_hit',
|
|
286
296
|
...eventContextBuilder(trackingId)
|
|
287
297
|
};
|
|
298
|
+
const {
|
|
299
|
+
layerId,
|
|
300
|
+
experimentId,
|
|
301
|
+
strategyId,
|
|
302
|
+
layerName,
|
|
303
|
+
experimentName,
|
|
304
|
+
strategyName
|
|
305
|
+
} = expData;
|
|
288
306
|
event.attributes = limitObject({
|
|
289
307
|
...(event.attributes ?? {}),
|
|
290
308
|
$exp_layer_id: layerId,
|
|
291
309
|
$exp_id: experimentId,
|
|
292
|
-
$exp_strategy_id: strategyId
|
|
310
|
+
$exp_strategy_id: strategyId,
|
|
311
|
+
$exp_layer_name: layerName,
|
|
312
|
+
$exp_name: experimentName,
|
|
313
|
+
$exp_strategy_name: strategyName
|
|
293
314
|
});
|
|
294
315
|
eventConverter(event);
|
|
295
316
|
};
|
|
@@ -113,7 +113,7 @@ class GioImpressionTracking {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
// 获取到可监听节点后校验节点信息
|
|
116
|
-
|
|
116
|
+
rectObserve = (rect, collectTarget, optionKey) => {
|
|
117
117
|
const { gioPlatform } = this.growingIO;
|
|
118
118
|
if (
|
|
119
119
|
(gioPlatform === 'tt' && collectTarget.__nodeId__) ||
|
|
@@ -146,7 +146,7 @@ class GioImpressionTracking {
|
|
|
146
146
|
this.rects[page.route] = {};
|
|
147
147
|
}
|
|
148
148
|
this.rects[page.route][nodeId] = rect;
|
|
149
|
-
this.
|
|
149
|
+
this.createObserver(collectTarget, optionKey);
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
152
|
|
|
@@ -166,7 +166,7 @@ class GioImpressionTracking {
|
|
|
166
166
|
.boundingClientRect(([rect = []]) => {
|
|
167
167
|
rect = ut.isArray(rect) ? rect : [rect];
|
|
168
168
|
if (!isEmpty(rect)) {
|
|
169
|
-
this.
|
|
169
|
+
this.rectObserve(rect, collectTarget, optionKey);
|
|
170
170
|
}
|
|
171
171
|
});
|
|
172
172
|
query.exec();
|
|
@@ -174,20 +174,22 @@ class GioImpressionTracking {
|
|
|
174
174
|
query.selectAll('.growing_collect_imp').boundingClientRect();
|
|
175
175
|
query.exec(([rect]) => {
|
|
176
176
|
if (!isEmpty(rect)) {
|
|
177
|
-
this.
|
|
177
|
+
this.rectObserve(rect, collectTarget, optionKey);
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
// 创建监听
|
|
184
|
-
|
|
184
|
+
createObserver = (
|
|
185
185
|
collectTarget: any,
|
|
186
186
|
optionKey: 'observeAll' | 'selectAll'
|
|
187
187
|
) => {
|
|
188
|
-
const { gioPlatform, minipInstance } = this.growingIO;
|
|
188
|
+
const { gioPlatform, minipInstance, vdsConfig } = this.growingIO;
|
|
189
189
|
// 初始化监听对象
|
|
190
|
-
|
|
190
|
+
// 数值要大于0,只能无限趋近于0,等于0的时候会导致没出现就会发曝光
|
|
191
|
+
const threshold = vdsConfig.impressionScale || 0.0000000000001;
|
|
192
|
+
const observerOption = { thresholds: [threshold], [optionKey]: true };
|
|
191
193
|
if (
|
|
192
194
|
['tb', 'my'].includes(gioPlatform) &&
|
|
193
195
|
ut.compareVersion(my.SDKVersion, '2.7.0') >= -1
|
|
@@ -221,7 +223,7 @@ class GioImpressionTracking {
|
|
|
221
223
|
)
|
|
222
224
|
: collectTarget.createIntersectionObserver(observerOption);
|
|
223
225
|
observer = observer.relativeToViewport();
|
|
224
|
-
// 不管原先是否创建过,直接覆盖(
|
|
226
|
+
// 不管原先是否创建过,直接覆盖(observerId会更新)
|
|
225
227
|
this.observerIds[page.route][nodeId] = observer;
|
|
226
228
|
// 添加监听回调
|
|
227
229
|
this.targetObserve(observer, page);
|
|
@@ -229,10 +231,12 @@ class GioImpressionTracking {
|
|
|
229
231
|
|
|
230
232
|
// 给目标节点添加监听回调
|
|
231
233
|
targetObserve = (observerTarget: any, collectPage: any) => {
|
|
232
|
-
const { taro } = this.growingIO.vdsConfig;
|
|
234
|
+
const { taro, impressionScale } = this.growingIO.vdsConfig;
|
|
235
|
+
// 数值要大于0,只能无限趋近于0,等于0的时候会导致没出现就会发曝光
|
|
236
|
+
const threshold = impressionScale || 0.0000000000001;
|
|
233
237
|
// 监听节点变化
|
|
234
238
|
observerTarget.observe('.growing_collect_imp', (result: any) => {
|
|
235
|
-
if (!ut.isEmpty(result) && result.intersectionRatio
|
|
239
|
+
if (!ut.isEmpty(result) && result.intersectionRatio >= threshold) {
|
|
236
240
|
let dataset: any = result.dataset;
|
|
237
241
|
if (taro && ut.isTaro3(taro)) {
|
|
238
242
|
dataset = this.getTaro3Dataset(collectPage.route, result.id);
|
package/src/types/base.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface UserOptions {
|
|
|
29
29
|
forceLogin: boolean;
|
|
30
30
|
// 或略上报字段
|
|
31
31
|
ignoreFields: string[];
|
|
32
|
+
// 曝光比例
|
|
33
|
+
impressionScale: number;
|
|
32
34
|
// 是否使用原始来源信息作为访问事件的参数上报
|
|
33
35
|
originalSource: boolean;
|
|
34
36
|
// session保活时长(5分钟)
|
|
@@ -39,6 +41,8 @@ export interface UserOptions {
|
|
|
39
41
|
requestTimeout?: number;
|
|
40
42
|
// 数据上报域名
|
|
41
43
|
serverUrl?: string;
|
|
44
|
+
// session超时时长
|
|
45
|
+
sessionExpires?: number;
|
|
42
46
|
// taro框架实例
|
|
43
47
|
taro?: any;
|
|
44
48
|
// taro框架vue实例
|
package/src/types/eventHooks.ts
CHANGED
|
@@ -76,16 +76,16 @@ export interface PageShareResult {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export interface MinipPageType {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
query: any;
|
|
82
|
-
settedTitle: any;
|
|
83
|
-
title: string;
|
|
79
|
+
queryOption: any;
|
|
80
|
+
configuredTitle: any;
|
|
84
81
|
pageProps: any;
|
|
85
82
|
lastLifecycle: string;
|
|
86
83
|
currentLifecycle: string;
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
lifeBeforeShow: boolean;
|
|
85
|
+
getPagePath: () => string;
|
|
86
|
+
getPageQuery: () => string;
|
|
87
|
+
getPageTitle: (trackingId?: string) => string;
|
|
88
|
+
qsQuery: (query: any) => string;
|
|
89
89
|
getReferralPage: (trackingId: string) => string;
|
|
90
90
|
buildShareQuery: (result: PageShareResult) => [string, string];
|
|
91
91
|
updateAppMessageResult: (result: PageShareResult) => PageShareResult;
|
|
@@ -110,8 +110,7 @@ export interface EventHooksType {
|
|
|
110
110
|
supLifeFcs: (target: any, type: 'app' | 'page') => void;
|
|
111
111
|
// 对象的遍历
|
|
112
112
|
objectTraverse: (target: any, fn: any) => any;
|
|
113
|
-
|
|
114
|
-
initEventHooks: () => void;
|
|
113
|
+
|
|
115
114
|
// 生命周期方法effects
|
|
116
115
|
lifeFcEffects: (eventName: string, method: any, cType: 'App' | 'Page') => any;
|
|
117
116
|
// 自定义方法effects
|
|
@@ -140,4 +139,8 @@ export interface EventHooksType {
|
|
|
140
139
|
growingBehavior: (behavior: any) => any;
|
|
141
140
|
// 对原生的重写方法
|
|
142
141
|
nativeGrowing: (designated?: string[]) => void;
|
|
142
|
+
// 初始化原始值
|
|
143
|
+
initOriginalValue: () => void;
|
|
144
|
+
// 初始化事件钩子
|
|
145
|
+
initEventHooks: () => void;
|
|
143
146
|
}
|
package/src/types/userStore.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface UserStoreType {
|
|
|
7
7
|
getSessionId: (trackingId: string) => string;
|
|
8
8
|
// 设置sessionId
|
|
9
9
|
setSessionId: (trackingId: string, id?: string) => void;
|
|
10
|
+
// session超时时刻
|
|
11
|
+
_sessionExpires: number;
|
|
10
12
|
// 获取userId
|
|
11
13
|
getUserId: (trackingId: string) => string;
|
|
12
14
|
// 设置userId
|
package/src/utils/tools.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
split,
|
|
17
17
|
startsWith,
|
|
18
18
|
toString,
|
|
19
|
+
typeOf,
|
|
19
20
|
unset
|
|
20
21
|
} from '@@/utils/glodash';
|
|
21
22
|
|
|
@@ -239,11 +240,15 @@ export const getPlainConfig = (platform?: string) => {
|
|
|
239
240
|
case 'swan':
|
|
240
241
|
return appConfig;
|
|
241
242
|
case 'tt':
|
|
242
|
-
return
|
|
243
|
+
return (
|
|
244
|
+
niceTry(() => __ttConfig) ||
|
|
245
|
+
global?.TMAConfig ||
|
|
246
|
+
globalThis?.TMAConfig
|
|
247
|
+
); // 可能会拿不到
|
|
243
248
|
case 'qq':
|
|
244
249
|
return __qqConfig;
|
|
245
250
|
case 'ks':
|
|
246
|
-
return __ksConfig;
|
|
251
|
+
return __ksConfig; // 新版快手小程序已经拿不到了
|
|
247
252
|
case 'jd':
|
|
248
253
|
return __jdConfig;
|
|
249
254
|
// 第三方框架下自动获取实例
|
|
@@ -296,7 +301,10 @@ export const getAppInst = () => {
|
|
|
296
301
|
};
|
|
297
302
|
|
|
298
303
|
export const getGlobal = () => {
|
|
299
|
-
return
|
|
304
|
+
return (
|
|
305
|
+
niceTry(() => niceTry(() => niceTry(() => $global) ?? global) ?? window) ??
|
|
306
|
+
globalThis
|
|
307
|
+
);
|
|
300
308
|
};
|
|
301
309
|
|
|
302
310
|
// Object参数限制
|
|
@@ -407,3 +415,14 @@ export const hashCode = (string: string, abs = false) => {
|
|
|
407
415
|
}
|
|
408
416
|
return abs ? Math.abs(hash) : hash;
|
|
409
417
|
};
|
|
418
|
+
|
|
419
|
+
// 获取额外的启动参数并合并进query
|
|
420
|
+
export const getLaunchQuery = (originQuery: any = {}, extraData: any = {}) => {
|
|
421
|
+
const validData = {};
|
|
422
|
+
keys(extraData).forEach((k: string) => {
|
|
423
|
+
if (['string', 'number', 'boolean'].includes(typeOf(extraData[k]))) {
|
|
424
|
+
validData[k] = extraData[k];
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
return Object.assign({}, validData, originQuery);
|
|
428
|
+
};
|