gio-miniprogram-sdk 4.1.0 → 4.3.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/.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 +6 -1
- package/src/adapters/gioTaobaoAdapter.ts +7 -3
- package/src/adapters/gioTaroAdapter.ts +18 -10
- package/src/adapters/gioUniAppAdapter.ts +3 -32
- package/src/constants/config.ts +1 -0
- package/src/core/dataStore/eventContextBuilder.ts +27 -13
- package/src/core/dataStore/eventHooks/appEffects.ts +62 -76
- package/src/core/dataStore/eventHooks/index.ts +45 -24
- package/src/core/dataStore/eventHooks/minipPage.ts +129 -30
- package/src/core/dataStore/eventHooks/pageEffects.ts +25 -53
- package/src/core/dataStore/index.ts +67 -74
- package/src/core/growingIO.ts +93 -45
- package/src/index.ts +12 -12
- package/src/minipInstance/base.ts +53 -26
- package/src/minipInstance/my.ts +5 -0
- package/src/minipInstance/tb.ts +5 -0
- package/src/platformConfig/base.ts +0 -1
- package/src/plugins/gioABTest.ts +15 -8
- package/src/plugins/gioCompress.ts +2 -0
- package/src/plugins/gioEventAutoTracking.ts +20 -3
- package/src/plugins/gioImpressionTracking.ts +13 -2
- package/src/plugins/gioMultipleInstances.ts +14 -3
- package/src/types/dataStore.ts +5 -1
- package/src/types/eventHooks.ts +13 -8
- package/src/types/growingIO.ts +52 -33
- package/src/utils/tools.ts +26 -3
|
@@ -7,7 +7,14 @@ import {
|
|
|
7
7
|
SystemInfo
|
|
8
8
|
} from '@@/types/minipInstance';
|
|
9
9
|
import { PLATFORMS } from '@@/types/platforms';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
isFunction,
|
|
12
|
+
isObject,
|
|
13
|
+
isString,
|
|
14
|
+
last,
|
|
15
|
+
typeOf,
|
|
16
|
+
isEmpty
|
|
17
|
+
} from '@@/utils/glodash';
|
|
11
18
|
import EMIT_MSG from '@@/constants/emitMsg';
|
|
12
19
|
import {
|
|
13
20
|
limitString,
|
|
@@ -126,38 +133,58 @@ class BaseInstance implements MinipInstanceType {
|
|
|
126
133
|
|
|
127
134
|
// 获取页面标题
|
|
128
135
|
getPageTitle = (page) => {
|
|
136
|
+
const platform = getPlainPlatform();
|
|
129
137
|
let title = '';
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
138
|
+
let instConfig = getPlainConfig(platform);
|
|
139
|
+
if (typeOf(instConfig) === 'string') {
|
|
140
|
+
instConfig = niceTry(() => JSON.parse(instConfig)) ?? {};
|
|
141
|
+
}
|
|
142
|
+
// 第一优先级在base中的hook setNavigationBarTitle设置的值(在dataStore page实例中实现)
|
|
143
|
+
// 第二优先级支持客户自己在页面中设置页面title
|
|
144
|
+
const data = page?.data || page.$data || {};
|
|
145
|
+
title = isString(data?.gioPageTitle) ? data?.gioPageTitle : '';
|
|
146
|
+
if (instConfig) {
|
|
147
|
+
// 第三优先级app生命周期中拿不到page对象,拿生命周期的参数来匹配
|
|
148
|
+
const { enterParams } = this.growingIO.dataStore.eventHooks.appEffects;
|
|
149
|
+
if (!page.route && !isEmpty(enterParams)) {
|
|
150
|
+
page.route = enterParams.path || '';
|
|
151
|
+
title = this._getTitleFromTabbar(instConfig, page.route);
|
|
145
152
|
}
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
// 第四优先级取页面的navigationBarTitleText
|
|
154
|
+
niceTry(() => {
|
|
155
|
+
if (!title) {
|
|
156
|
+
const instPage = instConfig.page || {};
|
|
157
|
+
const pageInfo =
|
|
158
|
+
instPage[page.route] || instPage[`${page.route}.html`];
|
|
159
|
+
if (pageInfo) {
|
|
160
|
+
title = pageInfo?.window?.navigationBarTitleText;
|
|
161
|
+
} else if (['wx', 'tt'].includes(platform)) {
|
|
162
|
+
title = (instConfig || global || $global)?.global?.window
|
|
163
|
+
?.navigationBarTitleText;
|
|
164
|
+
} else {
|
|
165
|
+
title = (instConfig || global || $global)?.window
|
|
166
|
+
?.navigationBarTitleText;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
// 第五优先级取tabBar配置
|
|
171
|
+
if (!title) {
|
|
172
|
+
title = this._getTitleFromTabbar(instConfig, page.route);
|
|
154
173
|
}
|
|
155
|
-
} catch (e) {
|
|
156
|
-
return '';
|
|
157
174
|
}
|
|
158
175
|
return limitString(title);
|
|
159
176
|
};
|
|
160
177
|
|
|
178
|
+
private _getTitleFromTabbar = (
|
|
179
|
+
instConfig: any,
|
|
180
|
+
pageRoute: string
|
|
181
|
+
): string => {
|
|
182
|
+
const tabPage = instConfig?.tabBar?.list?.find((p) => {
|
|
183
|
+
return p.pagePath === pageRoute || p.pagePath === `${pageRoute}.html`;
|
|
184
|
+
});
|
|
185
|
+
return tabPage?.text || '';
|
|
186
|
+
};
|
|
187
|
+
|
|
161
188
|
/**
|
|
162
189
|
* 存储相关
|
|
163
190
|
*/
|
package/src/minipInstance/my.ts
CHANGED
|
@@ -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
|
@@ -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
|
@@ -13,11 +13,17 @@ import {
|
|
|
13
13
|
startsWith,
|
|
14
14
|
toString
|
|
15
15
|
} from '@@/utils/glodash';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
consoleText,
|
|
18
|
+
hashCode,
|
|
19
|
+
limitObject,
|
|
20
|
+
niceCallback
|
|
21
|
+
} from '@@/utils/tools';
|
|
17
22
|
import EMIT_MSG from '@@/constants/emitMsg';
|
|
18
23
|
import { ABTEST_DATA_REG, ABTEST_SIGN_REG } from '@@/constants/regex';
|
|
19
24
|
|
|
20
25
|
class GioABTest {
|
|
26
|
+
public pluginVersion: string;
|
|
21
27
|
// 请求间隔时长
|
|
22
28
|
public requestInterval: number;
|
|
23
29
|
// 请求超时时长
|
|
@@ -27,6 +33,7 @@ class GioABTest {
|
|
|
27
33
|
// 接口重试计数
|
|
28
34
|
public retryCount: number;
|
|
29
35
|
constructor(public growingIO: GrowingIOType, options: any) {
|
|
36
|
+
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
30
37
|
const {
|
|
31
38
|
abServerUrl = 'https://ab.growingio.com',
|
|
32
39
|
requestInterval,
|
|
@@ -276,14 +283,14 @@ class GioABTest {
|
|
|
276
283
|
let event = {
|
|
277
284
|
eventType: 'CUSTOM',
|
|
278
285
|
eventName: '$exp_hit',
|
|
279
|
-
|
|
280
|
-
$exp_layer_id: layerId,
|
|
281
|
-
$exp_id: experimentId,
|
|
282
|
-
$exp_strategy_id: strategyId
|
|
283
|
-
},
|
|
284
|
-
...eventContextBuilder(trackingId),
|
|
285
|
-
customEventType: 0
|
|
286
|
+
...eventContextBuilder(trackingId)
|
|
286
287
|
};
|
|
288
|
+
event.attributes = limitObject({
|
|
289
|
+
...(event.attributes ?? {}),
|
|
290
|
+
$exp_layer_id: layerId,
|
|
291
|
+
$exp_id: experimentId,
|
|
292
|
+
$exp_strategy_id: strategyId
|
|
293
|
+
});
|
|
287
294
|
eventConverter(event);
|
|
288
295
|
};
|
|
289
296
|
}
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
6
|
|
|
7
7
|
class GioCompress {
|
|
8
|
+
public pluginVersion: string;
|
|
8
9
|
private f;
|
|
9
10
|
private _compress;
|
|
10
11
|
constructor(public growingIO: GrowingIOType) {
|
|
12
|
+
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
11
13
|
this.f = String.fromCharCode;
|
|
12
14
|
this._compress = function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
13
15
|
if (uncompressed === null) return '';
|
|
@@ -10,8 +10,10 @@ import EMIT_MSG from '@@/constants/emitMsg';
|
|
|
10
10
|
|
|
11
11
|
let ut;
|
|
12
12
|
class GioEventAutoTracking {
|
|
13
|
+
public pluginVersion: string;
|
|
13
14
|
private prevEvent: any;
|
|
14
15
|
constructor(public growingIO: GrowingIOType) {
|
|
16
|
+
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
15
17
|
ut = this.growingIO.utils;
|
|
16
18
|
this.prevEvent = {};
|
|
17
19
|
}
|
|
@@ -88,7 +90,7 @@ class GioEventAutoTracking {
|
|
|
88
90
|
const xpath = this.getNodeXpath(e, eventName);
|
|
89
91
|
if (xpath) {
|
|
90
92
|
const {
|
|
91
|
-
dataStore: { eventContextBuilder, eventInterceptor }
|
|
93
|
+
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
92
94
|
} = this.growingIO;
|
|
93
95
|
const target = e.currentTarget || e.target;
|
|
94
96
|
let idx;
|
|
@@ -115,6 +117,11 @@ class GioEventAutoTracking {
|
|
|
115
117
|
],
|
|
116
118
|
...eventContextBuilder(trackingId)
|
|
117
119
|
};
|
|
120
|
+
// 合并页面属性
|
|
121
|
+
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
122
|
+
trackingId,
|
|
123
|
+
event
|
|
124
|
+
);
|
|
118
125
|
eventInterceptor(event);
|
|
119
126
|
}
|
|
120
127
|
};
|
|
@@ -122,7 +129,7 @@ class GioEventAutoTracking {
|
|
|
122
129
|
// 构建tab菜单点击事件
|
|
123
130
|
buildTabClickEvent = (trackingId: string, tabItem: any) => {
|
|
124
131
|
const {
|
|
125
|
-
dataStore: { eventContextBuilder, eventInterceptor }
|
|
132
|
+
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
126
133
|
} = this.growingIO;
|
|
127
134
|
const event = {
|
|
128
135
|
eventType: 'VIEW_CLICK',
|
|
@@ -136,6 +143,11 @@ class GioEventAutoTracking {
|
|
|
136
143
|
],
|
|
137
144
|
...eventContextBuilder(trackingId)
|
|
138
145
|
};
|
|
146
|
+
// 合并页面属性
|
|
147
|
+
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
148
|
+
trackingId,
|
|
149
|
+
event
|
|
150
|
+
);
|
|
139
151
|
eventInterceptor(event);
|
|
140
152
|
};
|
|
141
153
|
|
|
@@ -148,7 +160,7 @@ class GioEventAutoTracking {
|
|
|
148
160
|
const xpath = this.getNodeXpath(e, eventName);
|
|
149
161
|
if (xpath) {
|
|
150
162
|
const {
|
|
151
|
-
dataStore: { eventContextBuilder, eventInterceptor }
|
|
163
|
+
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
152
164
|
} = this.growingIO;
|
|
153
165
|
const target = e.currentTarget || e.target;
|
|
154
166
|
const event = {
|
|
@@ -163,6 +175,11 @@ class GioEventAutoTracking {
|
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
event.element = [event.element];
|
|
178
|
+
// 合并页面属性
|
|
179
|
+
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
180
|
+
trackingId,
|
|
181
|
+
event
|
|
182
|
+
);
|
|
166
183
|
eventInterceptor(event);
|
|
167
184
|
}
|
|
168
185
|
};
|
|
@@ -9,14 +9,21 @@ import {
|
|
|
9
9
|
isArray,
|
|
10
10
|
isEmpty,
|
|
11
11
|
isEqualArray,
|
|
12
|
+
isObject,
|
|
12
13
|
isString,
|
|
13
14
|
toString
|
|
14
15
|
} from '@@/utils/glodash';
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
eventNameValidate,
|
|
18
|
+
hashCode,
|
|
19
|
+
limitObject,
|
|
20
|
+
niceTry
|
|
21
|
+
} from '@@/utils/tools';
|
|
16
22
|
import EMIT_MSG from '@@/constants/emitMsg';
|
|
17
23
|
|
|
18
24
|
let ut;
|
|
19
25
|
class GioImpressionTracking {
|
|
26
|
+
public pluginVersion: string;
|
|
20
27
|
public observerIds: any;
|
|
21
28
|
public rects: any;
|
|
22
29
|
public pageImpObserver: any;
|
|
@@ -25,6 +32,7 @@ class GioImpressionTracking {
|
|
|
25
32
|
public componentQueryTarget: any;
|
|
26
33
|
public sentImps: any;
|
|
27
34
|
constructor(public growingIO: GrowingIOType) {
|
|
35
|
+
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
28
36
|
ut = this.growingIO.utils;
|
|
29
37
|
this.observerIds = {};
|
|
30
38
|
this.rects = {};
|
|
@@ -353,9 +361,12 @@ class GioImpressionTracking {
|
|
|
353
361
|
const event = {
|
|
354
362
|
eventType: 'CUSTOM',
|
|
355
363
|
eventName,
|
|
356
|
-
attributes: properties,
|
|
357
364
|
...eventContextBuilder(trackingId)
|
|
358
365
|
};
|
|
366
|
+
event.attributes = limitObject({
|
|
367
|
+
...(event.attributes ?? {}),
|
|
368
|
+
...(isObject(properties) && !isEmpty(properties) ? properties : {})
|
|
369
|
+
});
|
|
359
370
|
if (plugins.gioMultipleInstances && !isEmpty(sendTargets)) {
|
|
360
371
|
event['&&sendTo'] = sendTargets;
|
|
361
372
|
}
|
|
@@ -11,8 +11,10 @@ import { OriginOptions } from '@@/types/dataStore';
|
|
|
11
11
|
import EMIT_MSG from '@@/constants/emitMsg';
|
|
12
12
|
|
|
13
13
|
export class GioMultipleInstances {
|
|
14
|
+
public pluginVersion: string;
|
|
14
15
|
public subTrackingIds: string[];
|
|
15
16
|
constructor(public growingIO: GrowingIOType) {
|
|
17
|
+
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
16
18
|
this.subTrackingIds = [];
|
|
17
19
|
this.growingIO.emitter.on(EMIT_MSG.ON_SDK_INITIALIZE_BEFORE, () => {
|
|
18
20
|
// 自动重写部分代码以实现多实例功能
|
|
@@ -153,10 +155,19 @@ export class GioMultipleInstances {
|
|
|
153
155
|
unset(event, '&&sendTo');
|
|
154
156
|
sendTo.forEach((trackingId: string) => {
|
|
155
157
|
const { eventContextBuilder } = self.growingIO.dataStore;
|
|
156
|
-
|
|
158
|
+
const newEvent = {
|
|
157
159
|
...event,
|
|
158
|
-
...eventContextBuilder(
|
|
159
|
-
|
|
160
|
+
...eventContextBuilder(
|
|
161
|
+
trackingId,
|
|
162
|
+
undefined,
|
|
163
|
+
event.trackingId !== trackingId
|
|
164
|
+
)
|
|
165
|
+
};
|
|
166
|
+
newEvent.attributes = {
|
|
167
|
+
...newEvent.attributes,
|
|
168
|
+
...event.attributes
|
|
169
|
+
};
|
|
170
|
+
originFunction.call(this, newEvent);
|
|
160
171
|
});
|
|
161
172
|
} else {
|
|
162
173
|
// 其他事件直接发给指定调用实例
|
package/src/types/dataStore.ts
CHANGED
|
@@ -22,7 +22,11 @@ export interface DataStoreType {
|
|
|
22
22
|
buildAppMessageEvent: (trackingId: string, args: any) => void;
|
|
23
23
|
buildTimelineEvent: (trackingId: string, args: any) => void;
|
|
24
24
|
// 事件通用维度组装
|
|
25
|
-
eventContextBuilder?: (
|
|
25
|
+
eventContextBuilder?: (
|
|
26
|
+
trackingId: string,
|
|
27
|
+
params?: any,
|
|
28
|
+
executeAttributes?: boolean
|
|
29
|
+
) => any;
|
|
26
30
|
eventConverter?: (event) => void;
|
|
27
31
|
eventHooks: EventHooksType;
|
|
28
32
|
eventInterceptor?: (event: any | void) => void;
|
package/src/types/eventHooks.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EVENT } from './base';
|
|
2
|
+
|
|
1
3
|
export type AppHookLifeCircle = 'onShow' | 'onHide' | 'onError';
|
|
2
4
|
export type PageHookLifeCircle =
|
|
3
5
|
| 'onShow'
|
|
@@ -74,21 +76,21 @@ export interface PageShareResult {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
export interface MinipPageType {
|
|
77
|
-
|
|
78
|
-
time: number;
|
|
79
|
-
query: any;
|
|
79
|
+
queryOption: any;
|
|
80
80
|
settedTitle: any;
|
|
81
|
-
title: string;
|
|
82
81
|
pageProps: any;
|
|
83
82
|
lastLifecycle: string;
|
|
84
83
|
currentLifecycle: string;
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
getPagePath: () => string;
|
|
85
|
+
getPageQeury: () => string;
|
|
86
|
+
getPageTitle: (trackingId?: string) => string;
|
|
87
|
+
qsQuery: (query: any) => string;
|
|
87
88
|
getReferralPage: (trackingId: string) => string;
|
|
88
89
|
buildShareQuery: (result: PageShareResult) => [string, string];
|
|
89
90
|
updateAppMessageResult: (result: PageShareResult) => PageShareResult;
|
|
90
91
|
updateTimelineResult: (result: PageShareResult) => PageShareResult;
|
|
91
92
|
updateAddFavoritesResult: (result: PageShareResult) => PageShareResult;
|
|
93
|
+
eventSetPageProps: (trackingId: string, event: EVENT) => any;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export interface EventHooksType {
|
|
@@ -107,8 +109,7 @@ export interface EventHooksType {
|
|
|
107
109
|
supLifeFcs: (target: any, type: 'app' | 'page') => void;
|
|
108
110
|
// 对象的遍历
|
|
109
111
|
objectTraverse: (target: any, fn: any) => any;
|
|
110
|
-
|
|
111
|
-
initEventHooks: () => void;
|
|
112
|
+
|
|
112
113
|
// 生命周期方法effects
|
|
113
114
|
lifeFcEffects: (eventName: string, method: any, cType: 'App' | 'Page') => any;
|
|
114
115
|
// 自定义方法effects
|
|
@@ -137,4 +138,8 @@ export interface EventHooksType {
|
|
|
137
138
|
growingBehavior: (behavior: any) => any;
|
|
138
139
|
// 对原生的重写方法
|
|
139
140
|
nativeGrowing: (designated?: string[]) => void;
|
|
141
|
+
// 初始化原始值
|
|
142
|
+
initOriginalValue: () => void;
|
|
143
|
+
// 初始化事件钩子
|
|
144
|
+
initEventHooks: () => void;
|
|
140
145
|
}
|
package/src/types/growingIO.ts
CHANGED
|
@@ -6,6 +6,15 @@ import { UploaderType } from '@@/types/uploader';
|
|
|
6
6
|
import { UserStoreType } from '@@/types/userStore';
|
|
7
7
|
|
|
8
8
|
export interface GrowingIOType {
|
|
9
|
+
// 工具类
|
|
10
|
+
utils?: any;
|
|
11
|
+
// 监听器
|
|
12
|
+
emitter: {
|
|
13
|
+
emit?: (msg: string, args?: any) => void;
|
|
14
|
+
on?: (msg: string, method: (args?: any) => any) => void;
|
|
15
|
+
once?: (msg: string, method: (args?: any) => any) => void;
|
|
16
|
+
off?: (msg: string, method: (args?: any) => any) => void;
|
|
17
|
+
};
|
|
9
18
|
// 小程序平台
|
|
10
19
|
gioPlatform: PLATFORMTYPES;
|
|
11
20
|
// 标记当前小程序是什么框架
|
|
@@ -54,63 +63,73 @@ export interface GrowingIOType {
|
|
|
54
63
|
setOption: (trackingId: string, optionKey: string, value: any) => void;
|
|
55
64
|
// 运行中获取配置
|
|
56
65
|
getOption: (trackingId: string, optionKey?: string) => any;
|
|
57
|
-
//
|
|
58
|
-
|
|
66
|
+
// 设置页面属性
|
|
67
|
+
setPageAttributes: (trackingId: string, properties: any) => void;
|
|
68
|
+
// 清空已设置的页面属性
|
|
69
|
+
clearPageAttributes: (
|
|
59
70
|
trackingId: string,
|
|
60
|
-
|
|
61
|
-
properties: { [key: string]: string },
|
|
62
|
-
items?: { key: string; id: string; attributes?: { [key: string]: string } }
|
|
71
|
+
properties: string[] | undefined
|
|
63
72
|
) => void;
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
// 清除登录用户Id
|
|
67
|
-
clearUserId?: (trackingId: string) => void;
|
|
73
|
+
// 手动发page
|
|
74
|
+
sendPage: (trackingId: string, props?: any) => void;
|
|
68
75
|
// 设置openId作为uid
|
|
69
76
|
identify?: (trackingId: string, openId: string) => void;
|
|
70
77
|
// 发送用户变量
|
|
71
78
|
setUserAttributes?: (trackingId: string, userAttributes: any) => void;
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
utils?: any;
|
|
78
|
-
// 事件转换
|
|
79
|
-
eventConverter?: (event: any) => void;
|
|
80
|
-
// 事件拦截器
|
|
81
|
-
eventInterceptor?: (event: any) => void;
|
|
82
|
-
// 设置埋点通用属性
|
|
79
|
+
// 设置登录用户Id
|
|
80
|
+
setUserId?: (trackingId: string, userId: string, userKey?: string) => void;
|
|
81
|
+
// 清除登录用户Id
|
|
82
|
+
clearUserId?: (trackingId: string) => void;
|
|
83
|
+
// 设置全局通用属性
|
|
83
84
|
setGeneralProps?: (trackingId: string, properties: any) => void;
|
|
84
|
-
//
|
|
85
|
+
// 清除已设置的全局通用属性
|
|
85
86
|
clearGeneralProps?: (
|
|
86
87
|
trackingId: string,
|
|
87
88
|
properties: string[] | undefined
|
|
88
89
|
) => void;
|
|
89
|
-
//
|
|
90
|
-
|
|
90
|
+
// 创建自定义埋点事件
|
|
91
|
+
track?: (
|
|
92
|
+
trackingId: string,
|
|
93
|
+
name: string,
|
|
94
|
+
properties: { [key: string]: string },
|
|
95
|
+
items?: { key: string; id: string; attributes?: { [key: string]: string } }
|
|
96
|
+
) => void;
|
|
97
|
+
// 初始化事件计时器
|
|
98
|
+
trackTimerStart: (trackingId: string, eventName: string) => any;
|
|
99
|
+
// 暂停事件计时器
|
|
100
|
+
trackTimerPause: (trackingId: string, timerId: string) => boolean;
|
|
101
|
+
// 恢复事件计时器
|
|
102
|
+
trackTimerResume: (trackingId: string, timerId: string) => boolean;
|
|
103
|
+
// 停止事件计时器并上报事件
|
|
104
|
+
trackTimerEnd: (
|
|
105
|
+
trackingId: string,
|
|
106
|
+
timerId: string,
|
|
107
|
+
properties: any
|
|
108
|
+
) => boolean;
|
|
109
|
+
// 移除事件计时器
|
|
110
|
+
removeTimer: (trackingId: string, timerId: string) => boolean;
|
|
91
111
|
// 清除所有事件计时器
|
|
92
|
-
clearTrackTimer
|
|
112
|
+
clearTrackTimer: (trackingId: string) => void;
|
|
93
113
|
// 手动获取位置信息补发visit上报
|
|
94
114
|
setLocation: (
|
|
95
115
|
trackingId: string,
|
|
96
116
|
latitude: number,
|
|
97
117
|
longitude: number
|
|
98
118
|
) => void;
|
|
99
|
-
//
|
|
100
|
-
|
|
119
|
+
// 手动更新曝光监听
|
|
120
|
+
updateImpression?: (collect?: any) => void;
|
|
101
121
|
// 获取ABTest数据
|
|
102
122
|
getABTest?: (
|
|
103
123
|
trackingId: string,
|
|
104
124
|
layerId: string,
|
|
105
125
|
callback?: (arg: any) => any
|
|
106
126
|
) => void;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
127
|
+
// 获取打通信息
|
|
128
|
+
getGioInfo: (trackingId: string) => string;
|
|
129
|
+
// 初始化回调
|
|
130
|
+
initCallback?: () => void;
|
|
131
|
+
// 错误提示
|
|
132
|
+
callError?: (fn: string, type?: boolean, msg?: string) => void;
|
|
114
133
|
GioApp?: any;
|
|
115
134
|
GioPage?: any;
|
|
116
135
|
GioComponent?: any;
|
package/src/utils/tools.ts
CHANGED
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
compact,
|
|
4
4
|
find,
|
|
5
5
|
forEach,
|
|
6
|
+
formatDate,
|
|
6
7
|
head,
|
|
7
8
|
isArray,
|
|
9
|
+
isDate,
|
|
8
10
|
isEmpty,
|
|
9
11
|
isFunction,
|
|
10
12
|
isNil,
|
|
@@ -14,6 +16,7 @@ import {
|
|
|
14
16
|
split,
|
|
15
17
|
startsWith,
|
|
16
18
|
toString,
|
|
19
|
+
typeOf,
|
|
17
20
|
unset
|
|
18
21
|
} from '@@/utils/glodash';
|
|
19
22
|
|
|
@@ -237,11 +240,15 @@ export const getPlainConfig = (platform?: string) => {
|
|
|
237
240
|
case 'swan':
|
|
238
241
|
return appConfig;
|
|
239
242
|
case 'tt':
|
|
240
|
-
return
|
|
243
|
+
return (
|
|
244
|
+
niceTry(() => __ttConfig) ||
|
|
245
|
+
global?.TMAConfig ||
|
|
246
|
+
globalThis?.TMAConfig
|
|
247
|
+
); // 可能会拿不到
|
|
241
248
|
case 'qq':
|
|
242
249
|
return __qqConfig;
|
|
243
250
|
case 'ks':
|
|
244
|
-
return __ksConfig;
|
|
251
|
+
return __ksConfig; // 新版快手小程序已经拿不到了
|
|
245
252
|
case 'jd':
|
|
246
253
|
return __jdConfig;
|
|
247
254
|
// 第三方框架下自动获取实例
|
|
@@ -294,7 +301,10 @@ export const getAppInst = () => {
|
|
|
294
301
|
};
|
|
295
302
|
|
|
296
303
|
export const getGlobal = () => {
|
|
297
|
-
return
|
|
304
|
+
return (
|
|
305
|
+
niceTry(() => niceTry(() => niceTry(() => $global) ?? global) ?? window) ??
|
|
306
|
+
globalThis
|
|
307
|
+
);
|
|
298
308
|
};
|
|
299
309
|
|
|
300
310
|
// Object参数限制
|
|
@@ -310,6 +320,8 @@ export const limitObject = (o: any) => {
|
|
|
310
320
|
} else if (isArray(v)) {
|
|
311
321
|
ob[key] = compact(v.slice(0, 100), true);
|
|
312
322
|
ob[key] = ob[key].join('||').slice(0, 1000);
|
|
323
|
+
} else if (isDate(v)) {
|
|
324
|
+
ob[key] = formatDate(v);
|
|
313
325
|
} else {
|
|
314
326
|
ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
|
|
315
327
|
}
|
|
@@ -403,3 +415,14 @@ export const hashCode = (string: string, abs = false) => {
|
|
|
403
415
|
}
|
|
404
416
|
return abs ? Math.abs(hash) : hash;
|
|
405
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
|
+
};
|