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
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { AppHookLifeCircle } from '@@/types/eventHooks';
|
|
2
2
|
import { GrowingIOType } from '@@/types/growingIO';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
isObject,
|
|
6
|
-
typeOf,
|
|
7
|
-
keys,
|
|
8
|
-
forEach,
|
|
9
|
-
has,
|
|
10
|
-
isNil
|
|
11
|
-
} from '@@/utils/glodash';
|
|
12
|
-
import { qsStringify } from '@@/utils/tools';
|
|
3
|
+
import { isEmpty, typeOf } from '@@/utils/glodash';
|
|
4
|
+
import { getLaunchQuery, qsStringify } from '@@/utils/tools';
|
|
13
5
|
import EMIT_MSG from '@@/constants/emitMsg';
|
|
14
6
|
|
|
15
7
|
class AppEffects {
|
|
8
|
+
public enterParams: any = {};
|
|
16
9
|
constructor(public growingIO: GrowingIOType) {}
|
|
17
10
|
|
|
18
11
|
main = (event: AppHookLifeCircle, args: any) => {
|
|
@@ -28,7 +21,6 @@ class AppEffects {
|
|
|
28
21
|
trackersExecute,
|
|
29
22
|
shareOut,
|
|
30
23
|
lastCloseTime,
|
|
31
|
-
eventHooks,
|
|
32
24
|
saveStorageInfo,
|
|
33
25
|
setOriginalSource
|
|
34
26
|
}
|
|
@@ -48,29 +40,39 @@ class AppEffects {
|
|
|
48
40
|
params: args[0] ?? {}
|
|
49
41
|
});
|
|
50
42
|
switch (event) {
|
|
43
|
+
case appListeners.appLaunch:
|
|
44
|
+
// 在launch先获取一次是防止在此生命周期中发埋点或调用其他api时获取不到path和query
|
|
45
|
+
this.enterParams = { ...args[0] };
|
|
46
|
+
break;
|
|
51
47
|
// 快应用是执行onCreate
|
|
52
48
|
case appListeners.appCreate:
|
|
53
49
|
// 各小程序执行onShow
|
|
54
50
|
case appListeners.appShow: {
|
|
55
51
|
// 获取进入小程序的path、query和scene
|
|
56
|
-
const { path, query } = this.enterParamsParse(args[0]);
|
|
52
|
+
const { path, query, referralPage } = this.enterParamsParse(args[0]);
|
|
57
53
|
if (!shareOut && vdsConfig.originalSource) {
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
// 个别(说的就是你:淘宝)小程序场景值不一样后台拉起时可能args中会没有path和query
|
|
55
|
+
if (path) {
|
|
56
|
+
// 保存初始来源信息
|
|
57
|
+
trackersExecute((trackingId: string) => {
|
|
58
|
+
setOriginalSource(trackingId, { path, query, referralPage });
|
|
59
|
+
});
|
|
60
|
+
}
|
|
62
61
|
}
|
|
63
62
|
// 以下条件均会被认为是一次新的访问
|
|
64
63
|
// 没有关闭时间说明是新访问
|
|
65
64
|
if (!lastCloseTime) {
|
|
66
|
-
// 保存进入小程序的参数
|
|
67
|
-
dataStore.lastVisitEvent = { path, query };
|
|
68
65
|
trackersExecute((trackingId: string) => {
|
|
69
|
-
|
|
66
|
+
dataStore.lastVisitEvent[trackingId] = {
|
|
67
|
+
path,
|
|
68
|
+
query,
|
|
69
|
+
referralPage
|
|
70
|
+
};
|
|
71
|
+
this.buildVisitEvent(trackingId, { path, query, referralPage });
|
|
70
72
|
});
|
|
71
73
|
} else if (
|
|
72
74
|
// 两次打开间隔时间超过keepAlive设定(默认5分钟)
|
|
73
|
-
Date.now() - lastCloseTime > vdsConfig.keepAlive ||
|
|
75
|
+
Date.now() - lastCloseTime > vdsConfig.keepAlive * 60 * 1000 ||
|
|
74
76
|
// 两次打开时的场景值不一样(即从不同的来源进入小程序)
|
|
75
77
|
(dataStore.lastScene && dataStore.scene !== dataStore.lastScene)
|
|
76
78
|
) {
|
|
@@ -78,11 +80,6 @@ class AppEffects {
|
|
|
78
80
|
trackersExecute((trackingId: string) => {
|
|
79
81
|
userStore.setSessionId(trackingId);
|
|
80
82
|
});
|
|
81
|
-
// 需要按自然逻辑发visit时,清掉pagetime,防止取值错误(会在page中重新生成)
|
|
82
|
-
eventHooks.currentPage.time = undefined;
|
|
83
|
-
trackersExecute((trackingId: string) => {
|
|
84
|
-
this.buildVisitEvent(trackingId, { path, query });
|
|
85
|
-
});
|
|
86
83
|
}
|
|
87
84
|
break;
|
|
88
85
|
}
|
|
@@ -108,16 +105,11 @@ class AppEffects {
|
|
|
108
105
|
};
|
|
109
106
|
|
|
110
107
|
// 进入小程序时的相关数据处理
|
|
111
|
-
enterParamsParse = (args: any) => {
|
|
108
|
+
enterParamsParse = (args: any = {}) => {
|
|
112
109
|
const { gioPlatform, minipInstance, dataStore } = this.growingIO;
|
|
113
|
-
let
|
|
114
|
-
let
|
|
115
|
-
|
|
116
|
-
vPath = p;
|
|
117
|
-
vQuery = keys(q)
|
|
118
|
-
.map((k) => `${k}=${q[k]}`)
|
|
119
|
-
.join('&');
|
|
120
|
-
};
|
|
110
|
+
let rPath = ''; // 进入小程序时的path
|
|
111
|
+
let rQuery = ''; // 进入小程序时的参数(启动参数)
|
|
112
|
+
let rAppId = ''; // scene=1037或1038时来源小程序、公众号或 App 的 appId
|
|
121
113
|
// 支持getEnterOptionsSync
|
|
122
114
|
if (
|
|
123
115
|
gioPlatform !== 'quickapp' &&
|
|
@@ -125,35 +117,25 @@ class AppEffects {
|
|
|
125
117
|
) {
|
|
126
118
|
const { path, query, scene, referrerInfo } =
|
|
127
119
|
minipInstance.minip.getEnterOptionsSync() || {};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
!has(originQuery, k) &&
|
|
138
|
-
// 只处理字符串、数字和布尔类型的值
|
|
139
|
-
['string', 'number', 'boolean'].includes(typeOf(v))
|
|
140
|
-
) {
|
|
141
|
-
extraQuery.push(`${k}=${v}`);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const extraQueryString = extraQuery.join('&');
|
|
145
|
-
vQuery =
|
|
146
|
-
vQuery && extraQueryString
|
|
147
|
-
? `${vQuery}&${extraQueryString}`
|
|
148
|
-
: vQuery || extraQueryString;
|
|
120
|
+
rPath = path || args.path;
|
|
121
|
+
rQuery = query || args.query;
|
|
122
|
+
rAppId = referrerInfo?.appId || args?.referrerInfo?.appId || '';
|
|
123
|
+
dataStore.scene = scene || args.scene;
|
|
124
|
+
// 来源有额外参数时并入页面参数
|
|
125
|
+
if (!isEmpty(referrerInfo?.extraData)) {
|
|
126
|
+
rQuery = qsStringify(getLaunchQuery(rQuery, referrerInfo.extraData));
|
|
127
|
+
} else {
|
|
128
|
+
rQuery = qsStringify(rQuery);
|
|
149
129
|
}
|
|
150
130
|
} else {
|
|
151
131
|
// 不支持的按老逻辑兜底
|
|
152
|
-
const { path, query } = args;
|
|
153
|
-
|
|
132
|
+
const { path, query, referrerInfo } = args;
|
|
133
|
+
rPath = path;
|
|
134
|
+
rQuery = qsStringify(query);
|
|
135
|
+
rAppId = referrerInfo?.appId || '';
|
|
154
136
|
this.parseScene(args);
|
|
155
137
|
}
|
|
156
|
-
return { path:
|
|
138
|
+
return { path: rPath, query: rQuery, referralPage: rAppId };
|
|
157
139
|
};
|
|
158
140
|
|
|
159
141
|
// 获取来源场景值
|
|
@@ -188,13 +170,7 @@ class AppEffects {
|
|
|
188
170
|
// 构建访问事件
|
|
189
171
|
buildVisitEvent = (trackingId: string, props?: any) => {
|
|
190
172
|
const {
|
|
191
|
-
dataStore: {
|
|
192
|
-
getOriginalSource,
|
|
193
|
-
eventContextBuilder,
|
|
194
|
-
eventInterceptor,
|
|
195
|
-
eventHooks
|
|
196
|
-
},
|
|
197
|
-
minipInstance,
|
|
173
|
+
dataStore: { getOriginalSource, eventContextBuilder, eventInterceptor },
|
|
198
174
|
vdsConfig
|
|
199
175
|
} = this.growingIO;
|
|
200
176
|
const originalSource = getOriginalSource(trackingId);
|
|
@@ -202,22 +178,20 @@ class AppEffects {
|
|
|
202
178
|
const query = props?.query || '';
|
|
203
179
|
let event = {
|
|
204
180
|
eventType: 'VISIT',
|
|
205
|
-
...eventContextBuilder(trackingId, {
|
|
206
|
-
// params.path是生命周期值或者是已有的值
|
|
207
|
-
path: props?.path || '',
|
|
208
|
-
// params.query是对象说明是生命周期调用,否则是补发调用
|
|
209
|
-
query: typeOf(query) === 'string' ? query : qsStringify(query),
|
|
210
|
-
// visit事件要单独设一次title以覆盖eventContextBuilder中的lastPage的可能的title错误值
|
|
211
|
-
title:
|
|
212
|
-
eventHooks.currentPage?.title ||
|
|
213
|
-
minipInstance.getPageTitle(minipInstance.getCurrentPage()),
|
|
214
|
-
timestamp: eventHooks.currentPage.time
|
|
215
|
-
? eventHooks.currentPage.time - 1
|
|
216
|
-
: +Date.now()
|
|
217
|
-
})
|
|
181
|
+
...eventContextBuilder(trackingId, {})
|
|
218
182
|
};
|
|
183
|
+
if (!isEmpty(props) && props.path) {
|
|
184
|
+
// props.path是生命周期值或者是已有的值
|
|
185
|
+
event.path = props.path || '';
|
|
186
|
+
// props.query是对象说明是生命周期调用,否则是补发调用
|
|
187
|
+
event.query = typeOf(query) === 'string' ? query : qsStringify(query);
|
|
188
|
+
// 如果有来源
|
|
189
|
+
if (props.referralPage) {
|
|
190
|
+
event.referralPage = props.referralPage;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
219
193
|
// 配置使用初始来源时,visit使用初始来源数据
|
|
220
|
-
if (vdsConfig.originalSource && !
|
|
194
|
+
if (vdsConfig.originalSource && !isEmpty(originalSource)) {
|
|
221
195
|
event = { ...event, ...originalSource };
|
|
222
196
|
}
|
|
223
197
|
eventInterceptor(event);
|
|
@@ -304,15 +304,25 @@ class EventHooks implements EventHooksType {
|
|
|
304
304
|
});
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
-
growingApp = (app: any) =>
|
|
307
|
+
growingApp = (app: any) =>
|
|
308
|
+
isFunction(this.originalApp)
|
|
309
|
+
? this.originalApp(this.appOverriding(app))
|
|
310
|
+
: this.appOverriding(app);
|
|
308
311
|
|
|
309
|
-
growingPage = (page: any) =>
|
|
312
|
+
growingPage = (page: any) =>
|
|
313
|
+
isFunction(this.originalPage)
|
|
314
|
+
? this.originalPage(this.pageOverriding(page))
|
|
315
|
+
: this.pageOverriding(page);
|
|
310
316
|
|
|
311
317
|
growingComponent = (component: any) =>
|
|
312
|
-
this.originalComponent
|
|
318
|
+
isFunction(this.originalComponent)
|
|
319
|
+
? this.originalComponent(this.componentOverriding(component))
|
|
320
|
+
: this.componentOverriding(component);
|
|
313
321
|
|
|
314
322
|
growingBehavior = (behavior: any) =>
|
|
315
|
-
this.originalBehavior
|
|
323
|
+
isFunction(this.originalBehavior)
|
|
324
|
+
? this.originalBehavior(this.componentOverriding(behavior))
|
|
325
|
+
: this.componentOverriding(behavior);
|
|
316
326
|
|
|
317
327
|
nativeGrowing = (
|
|
318
328
|
designated: string[] = ['App', 'Page', 'Component', 'Behavior']
|
|
@@ -320,15 +330,12 @@ class EventHooks implements EventHooksType {
|
|
|
320
330
|
const self = this;
|
|
321
331
|
const { platformConfig } = this.growingIO;
|
|
322
332
|
const platformHooks = platformConfig.hooks;
|
|
323
|
-
this.setAppEffectCbs();
|
|
324
|
-
this.setPageEffectCbs();
|
|
325
333
|
if (designated.includes('App')) {
|
|
326
334
|
try {
|
|
327
335
|
// 重写App
|
|
328
336
|
if (platformHooks.App && !this.appHooked) {
|
|
329
|
-
this.originalApp = App || global.App || function () {};
|
|
330
337
|
App = function (...args) {
|
|
331
|
-
return self.
|
|
338
|
+
return self.originalApp(self.appOverriding(args[0]));
|
|
332
339
|
};
|
|
333
340
|
this.appHooked = true;
|
|
334
341
|
}
|
|
@@ -340,9 +347,8 @@ class EventHooks implements EventHooksType {
|
|
|
340
347
|
try {
|
|
341
348
|
// 重写Page
|
|
342
349
|
if (platformHooks.Page && !this.pageHooked) {
|
|
343
|
-
this.originalPage = Page || global.Page || function () {};
|
|
344
350
|
Page = function (...args) {
|
|
345
|
-
return self.
|
|
351
|
+
return self.originalPage(self.pageOverriding(args[0]));
|
|
346
352
|
};
|
|
347
353
|
this.pageHooked = true;
|
|
348
354
|
}
|
|
@@ -354,10 +360,8 @@ class EventHooks implements EventHooksType {
|
|
|
354
360
|
try {
|
|
355
361
|
// 重写Component
|
|
356
362
|
if (platformHooks.Component && !this.componentHooked) {
|
|
357
|
-
this.originalComponent =
|
|
358
|
-
Component || global.Component || function () {};
|
|
359
363
|
Component = function (...args) {
|
|
360
|
-
return self.
|
|
364
|
+
return self.originalComponent(self.componentOverriding(args[0]));
|
|
361
365
|
};
|
|
362
366
|
this.componentHooked = true;
|
|
363
367
|
}
|
|
@@ -369,9 +373,8 @@ class EventHooks implements EventHooksType {
|
|
|
369
373
|
try {
|
|
370
374
|
// 重写Behavior
|
|
371
375
|
if (platformHooks.Behavior && !this.behaviorHooked) {
|
|
372
|
-
this.originalBehavior = Behavior || global.Behavior || function () {};
|
|
373
376
|
Behavior = function (...args) {
|
|
374
|
-
return self.
|
|
377
|
+
return self.originalBehavior(self.componentOverriding(args[0]));
|
|
375
378
|
};
|
|
376
379
|
this.behaviorHooked = true;
|
|
377
380
|
}
|
|
@@ -381,26 +384,39 @@ class EventHooks implements EventHooksType {
|
|
|
381
384
|
}
|
|
382
385
|
};
|
|
383
386
|
|
|
384
|
-
//
|
|
387
|
+
// 初始化原始值
|
|
388
|
+
initOriginalValue = () => {
|
|
389
|
+
this.setAppEffectCbs();
|
|
390
|
+
this.setPageEffectCbs();
|
|
391
|
+
this.originalApp = niceTry(() => App || global.App);
|
|
392
|
+
this.originalPage = niceTry(() => Page || global.Page);
|
|
393
|
+
this.originalComponent = niceTry(() => Component || global.Component);
|
|
394
|
+
this.originalBehavior = niceTry(() => Behavior || global.Behavior);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// 初始化事件钩子
|
|
385
398
|
initEventHooks = () => {
|
|
386
399
|
const self = this;
|
|
387
400
|
const { platformConfig, gioPlatform } = this.growingIO;
|
|
401
|
+
this.initOriginalValue();
|
|
388
402
|
if (platformConfig.canHook) {
|
|
389
403
|
this.nativeGrowing();
|
|
390
|
-
getGlobal().GioApp = niceTry(() => App ??
|
|
391
|
-
getGlobal().GioPage = niceTry(() => Page ??
|
|
404
|
+
getGlobal().GioApp = niceTry(() => App ?? this.originalApp);
|
|
405
|
+
getGlobal().GioPage = niceTry(() => Page ?? this.originalPage);
|
|
392
406
|
getGlobal().GioComponent = niceTry(
|
|
393
|
-
() => Component ??
|
|
407
|
+
() => Component ?? this.originalComponent
|
|
408
|
+
);
|
|
409
|
+
getGlobal().GioBehavior = niceTry(
|
|
410
|
+
() => Behavior ?? this.originalBehavior
|
|
394
411
|
);
|
|
395
|
-
getGlobal().GioBehavior = niceTry(() => Behavior);
|
|
396
412
|
} else if (gioPlatform === 'quickapp') {
|
|
397
|
-
|
|
413
|
+
getGlobal().GioApp = function (...args) {
|
|
398
414
|
return self.appOverriding(args[0]);
|
|
399
415
|
};
|
|
400
|
-
|
|
416
|
+
getGlobal().GioPage = function (...args) {
|
|
401
417
|
return self.pageOverriding(args[0]);
|
|
402
418
|
};
|
|
403
|
-
|
|
419
|
+
getGlobal().GioComponent = function (...args) {
|
|
404
420
|
return self.pageOverriding(args[0]);
|
|
405
421
|
};
|
|
406
422
|
}
|
|
@@ -16,68 +16,128 @@ import {
|
|
|
16
16
|
qsParse,
|
|
17
17
|
niceTry,
|
|
18
18
|
getDynamicAttributes,
|
|
19
|
-
limitObject
|
|
19
|
+
limitObject,
|
|
20
|
+
getLaunchQuery
|
|
20
21
|
} from '@@/utils/tools';
|
|
21
22
|
import { EVENT } from '@@/types/base';
|
|
22
23
|
|
|
23
24
|
class MinipPage implements MinipPageType {
|
|
24
|
-
|
|
25
|
-
public
|
|
26
|
-
public query: any;
|
|
27
|
-
// 页面title (优先级:setNavigationBarTitle > data.gioPageTitle[不保证能取到] > config.js中设置的值 > tabBar配置)
|
|
28
|
-
public title: string;
|
|
25
|
+
// 根据页面存储的页面参数
|
|
26
|
+
public queryOption: any;
|
|
29
27
|
// 通过调用wx.setNavigationBarTitle设置的title
|
|
30
|
-
public
|
|
28
|
+
public configuredTitle: any;
|
|
31
29
|
// 页面级属性
|
|
32
30
|
public pageProps: any;
|
|
33
31
|
// 上一个执行的小程序生命周期
|
|
34
32
|
public lastLifecycle: string;
|
|
35
33
|
// 当前执行的小程序生命周期
|
|
36
34
|
public currentLifecycle: string;
|
|
35
|
+
// 当前生命周期是否在页面显示前
|
|
36
|
+
public lifeBeforeShow = true;
|
|
37
37
|
|
|
38
38
|
constructor(public growingIO: GrowingIOType) {
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
39
|
+
this.queryOption = {};
|
|
40
|
+
this.configuredTitle = {};
|
|
41
41
|
this.pageProps = {};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const path =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
// 获取页面地址
|
|
45
|
+
getPagePath = () => {
|
|
46
|
+
const { minipInstance, inPlugin, dataStore, trackingId } = this.growingIO;
|
|
47
|
+
const path = minipInstance.getCurrentPath();
|
|
48
|
+
if (inPlugin) {
|
|
49
|
+
const vds = dataStore.getTrackerVds(trackingId);
|
|
50
|
+
// 插件中没有页面时直接将插件appId作为页面信息
|
|
51
|
+
return path || `/插件${vds.appId}`;
|
|
51
52
|
} else {
|
|
52
|
-
|
|
53
|
+
return (
|
|
54
|
+
path ||
|
|
55
|
+
dataStore.eventHooks.appEffects.enterParams?.path ||
|
|
56
|
+
// 作为页面组件时component created生命周期中的埋点会取不到页面堆栈,所以拿最近的一个page事件中的页面信息做兜底
|
|
57
|
+
dataStore.lastPageEvent[trackingId]?.path ||
|
|
58
|
+
// 没有最近的一个page事件说明在app初始化的生命周期中,有些框架可能会有异步处理逻辑导致事件触发比visit晚,则使用visit事件中的页面信息兜底
|
|
59
|
+
dataStore.lastVisitEvent[trackingId]?.path
|
|
60
|
+
);
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// 获取页面参数
|
|
65
|
+
getPageQuery = () => {
|
|
66
|
+
const { minipInstance, dataStore, trackingId } = this.growingIO;
|
|
67
|
+
const stackPage = minipInstance.getCurrentPage();
|
|
68
|
+
const stackPath = minipInstance.getCurrentPath();
|
|
69
|
+
const { enterParams = {} } = dataStore.eventHooks.appEffects;
|
|
70
|
+
if (stackPath) {
|
|
71
|
+
const pageParams = stackPage.options ?? stackPage.$taroParams;
|
|
72
|
+
// 堆栈中有页面信息,则使用堆栈中的页面参数
|
|
73
|
+
if (!isEmpty(pageParams)) {
|
|
74
|
+
// 删掉taro框架中自带的字段
|
|
75
|
+
unset(pageParams, '$taroTimestamp');
|
|
76
|
+
// 有页面解析的option直接取
|
|
77
|
+
return this.qsQuery(pageParams);
|
|
78
|
+
} else if (!isEmpty(this.queryOption[stackPath])) {
|
|
79
|
+
// 没有option从hook获取的生命周期参数中取
|
|
80
|
+
return this.qsQuery(this.queryOption[stackPath]);
|
|
81
|
+
} else if (stackPath === enterParams.path) {
|
|
82
|
+
// 某些小程序虽然有页面堆栈,但是页面还没加载完,兜底取启动参数
|
|
83
|
+
return this.qsQuery(
|
|
84
|
+
getLaunchQuery(
|
|
85
|
+
enterParams?.query,
|
|
86
|
+
enterParams?.referrerInfo?.extraData
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} else if (enterParams.path) {
|
|
91
|
+
// 堆栈中没有页面信息,但启动参数中有,说明是小程序刚启动还没加载页面,直接取启动参数
|
|
92
|
+
return this.qsQuery(
|
|
93
|
+
getLaunchQuery(enterParams?.query, enterParams?.referrerInfo?.extraData)
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
// 作为页面组件时component created生命周期中的埋点会取不到页面堆栈,所以拿最近的一个page事件中的页面信息做兜底
|
|
97
|
+
return dataStore.lastPageEvent[trackingId]?.path
|
|
98
|
+
? dataStore.lastPageEvent[trackingId]?.query
|
|
99
|
+
: // 没有最近的一个page事件说明在app初始化的生命周期中,有些框架可能会有异步处理逻辑导致事件触发比visit晚,则使用visit事件中的页面信息兜底
|
|
100
|
+
dataStore.lastVisitEvent[trackingId]?.query;
|
|
56
101
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// 获取页面标题
|
|
105
|
+
// 页面title (优先级:setNavigationBarTitle > data.gioPageTitle[不保证能取到] > config.js中设置的值 > tabBar配置)
|
|
106
|
+
getPageTitle = (trackingId?: string) => {
|
|
107
|
+
const { minipInstance, inPlugin, dataStore } = this.growingIO;
|
|
108
|
+
const path = minipInstance.getCurrentPath();
|
|
109
|
+
const title =
|
|
110
|
+
this.configuredTitle[path] ||
|
|
111
|
+
minipInstance.getPageTitle(minipInstance.getCurrentPage());
|
|
112
|
+
if (inPlugin) {
|
|
113
|
+
const vds = dataStore.getTrackerVds(
|
|
114
|
+
trackingId || this.growingIO.trackingId
|
|
63
115
|
);
|
|
116
|
+
// 插件中没有页面时直接将插件appId作为页面信息
|
|
117
|
+
return (
|
|
118
|
+
title || `/插件${vds.appId}${path ? '_' + last(path.split('/')) : ''}`
|
|
119
|
+
);
|
|
120
|
+
} else {
|
|
121
|
+
return title;
|
|
122
|
+
}
|
|
64
123
|
};
|
|
65
124
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
unset(
|
|
70
|
-
return qsStringify(
|
|
125
|
+
// 格式化页面参数
|
|
126
|
+
qsQuery = (query = {}) => {
|
|
127
|
+
const slimQuery = { ...query };
|
|
128
|
+
unset(slimQuery, 'wxShoppingListScene');
|
|
129
|
+
return qsStringify(slimQuery);
|
|
71
130
|
};
|
|
72
131
|
|
|
73
|
-
//
|
|
132
|
+
// 获取页面来源
|
|
74
133
|
getReferralPage = (trackingId: string) => {
|
|
75
134
|
const {
|
|
76
135
|
minipInstance,
|
|
77
|
-
dataStore: { lastPageEvent, scene }
|
|
136
|
+
dataStore: { lastPageEvent, scene, eventHooks }
|
|
78
137
|
} = this.growingIO;
|
|
79
138
|
return (
|
|
80
139
|
lastPageEvent[trackingId]?.path ||
|
|
140
|
+
eventHooks.appEffects.enterParams?.referrerInfo?.appId ||
|
|
81
141
|
(scene ? `scn:${minipInstance.scnPrefix}${scene}` : null)
|
|
82
142
|
);
|
|
83
143
|
};
|
|
@@ -89,22 +149,22 @@ class MinipPage implements MinipPageType {
|
|
|
89
149
|
// 自定义path的地址参数截取(onShareAppMessage中的页面参数是拼在地址中的)
|
|
90
150
|
const customSplit = splitPath(result.path ?? '');
|
|
91
151
|
|
|
92
|
-
let path = this.
|
|
93
|
-
let
|
|
152
|
+
let path = this.getPagePath();
|
|
153
|
+
let parsedQuery: any = {};
|
|
94
154
|
let resultHasPath = has(result, 'path');
|
|
95
155
|
// 优先使用自定义的地址
|
|
96
156
|
if (resultHasPath) {
|
|
97
157
|
path = head(customSplit);
|
|
98
|
-
|
|
158
|
+
parsedQuery = qsParse(last(customSplit)) || {};
|
|
99
159
|
}
|
|
100
160
|
|
|
101
161
|
// 自定义path中没有截取到query说明是在onShareAppMessage中没有参数,或是在onShareTimeline中需要取自定义query
|
|
102
|
-
if (isEmpty(
|
|
103
|
-
|
|
104
|
-
compact(keys(
|
|
105
|
-
// 删除从默认页面的query中原有的utm参数,防止带入到下一次分享导致渠道统计错误(如果客户质疑参数被删,让他们自己拼回去或者关
|
|
162
|
+
if (isEmpty(parsedQuery)) {
|
|
163
|
+
parsedQuery = qsParse(result.query ?? '') || {};
|
|
164
|
+
compact(keys(parsedQuery)).forEach((key) => {
|
|
165
|
+
// 删除从默认页面的query中原有的utm参数,防止带入到下一次分享导致渠道统计错误(如果客户质疑参数被删,让他们自己拼回去或者关followShare)
|
|
106
166
|
if (key.toLowerCase().startsWith('utm_')) {
|
|
107
|
-
unset(
|
|
167
|
+
unset(parsedQuery, key);
|
|
108
168
|
}
|
|
109
169
|
});
|
|
110
170
|
}
|
|
@@ -113,11 +173,13 @@ class MinipPage implements MinipPageType {
|
|
|
113
173
|
|
|
114
174
|
// 自定义query没有值则使用当前页面默认参数
|
|
115
175
|
// 如果path存在,但是不携带参数,此时不使用当前页面的默认参数
|
|
116
|
-
if (!resultHasPath && isEmpty(
|
|
117
|
-
|
|
176
|
+
if (!resultHasPath && isEmpty(parsedQuery)) {
|
|
177
|
+
const stackPage = this.growingIO.minipInstance.getCurrentPage();
|
|
178
|
+
parsedQuery =
|
|
179
|
+
stackPage.options || this.queryOption[stackPage.route] || {};
|
|
118
180
|
}
|
|
119
181
|
|
|
120
|
-
return [path, qsStringify(
|
|
182
|
+
return [path, qsStringify(parsedQuery)];
|
|
121
183
|
}
|
|
122
184
|
|
|
123
185
|
// 更新分享结果
|
|
@@ -144,7 +206,9 @@ class MinipPage implements MinipPageType {
|
|
|
144
206
|
|
|
145
207
|
// 给事件合并页面属性
|
|
146
208
|
eventSetPageProps = (trackingId: string, event: EVENT) => {
|
|
147
|
-
const pageProps = niceTry(
|
|
209
|
+
const pageProps = niceTry(
|
|
210
|
+
() => this.pageProps[trackingId][this.getPagePath()]
|
|
211
|
+
);
|
|
148
212
|
if (!isEmpty(pageProps)) {
|
|
149
213
|
return limitObject(
|
|
150
214
|
getDynamicAttributes({
|