gio-miniprogram-sdk 4.0.1 → 4.1.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/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 -0
- 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 +39 -42
- package/rollup.config.js +11 -6
- package/rollup.plugins.config.js +13 -10
- package/src/{pluginsOut/frameworks → adapters}/gioTaobaoAdapter.ts +47 -43
- package/src/{pluginsOut/frameworks → adapters}/gioTaroAdapter.ts +4 -4
- package/src/{pluginsOut/frameworks → adapters}/gioUniAppAdapter.ts +35 -6
- package/src/constants/config.ts +47 -18
- package/src/constants/emitMsg.ts +23 -0
- package/src/constants/regex.ts +0 -1
- package/src/core/dataStore/eventContextBuilder.ts +28 -17
- package/src/core/dataStore/eventHooks/appEffects.ts +50 -31
- package/src/core/dataStore/eventHooks/index.ts +7 -5
- package/src/core/dataStore/eventHooks/minipPage.ts +2 -11
- package/src/core/dataStore/eventHooks/pageEffects.ts +61 -27
- package/src/core/dataStore/index.ts +263 -185
- package/src/core/growingIO.ts +312 -178
- package/src/core/pluginsInstance/base.ts +157 -0
- package/src/core/pluginsInstance/taro.ts +15 -0
- package/src/core/pluginsInstance/tb.ts +15 -0
- package/src/core/pluginsInstance/uniapp.ts +15 -0
- package/src/core/uploader.ts +131 -82
- package/src/core/userStore.ts +160 -121
- package/src/index.ts +37 -28
- package/src/minipInstance/base.ts +2 -1
- package/src/minipInstance/quickapp.ts +5 -19
- package/src/platformConfig/base.ts +0 -4
- package/src/{pluginsOut/ordinary → plugins}/gioABTest.ts +74 -37
- package/src/{pluginsOut/ordinary → plugins}/gioEventAutoTracking.ts +25 -18
- package/src/{pluginsOut/ordinary → plugins}/gioImpressionTracking.ts +55 -22
- package/src/plugins/gioMultipleInstances.ts +176 -0
- package/src/types/base.ts +10 -3
- package/src/types/dataStore.ts +31 -16
- package/src/types/eventHooks.ts +5 -6
- package/src/types/growingIO.ts +30 -14
- package/src/types/platforms.ts +0 -4
- package/src/types/plugins.ts +1 -1
- package/src/types/uploader.ts +16 -10
- package/src/types/userStore.ts +21 -17
- package/src/utils/glodash.ts +10 -3
- package/src/utils/tools.ts +27 -6
- package/src/utils/verifiers.ts +25 -50
- package/typings/global.d.ts +5 -0
- package/.babelrc +0 -4
- package/bin/build/full.sh +0 -32
- package/bin/build/jd.sh +0 -14
- package/bin/build/ks.sh +0 -14
- package/bin/build/my.sh +0 -14
- package/bin/build/plugins.sh +0 -5
- package/bin/build/qq.sh +0 -14
- package/bin/build/quickapp.sh +0 -14
- package/bin/build/swan.sh +0 -14
- package/bin/build/taro.sh +0 -18
- package/bin/build/tb.sh +0 -18
- package/bin/build/tt.sh +0 -14
- package/bin/build/uniapp.sh +0 -18
- package/bin/build/wx.sh +0 -14
- package/src/core/plugins.ts +0 -152
- package/src/pluginsOut/ordinary/gioCustomTracking.ts +0 -71
- package/bin/{build/all.sh → build.sh} +3 -3
- /package/src/{pluginsOut/ordinary → plugins}/gioCompress.ts +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 名称:多实例插件
|
|
3
|
+
* 用途:用于提供多实例以向指定项目和数据源发数的插件。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EXTEND_EVENT } from '@@/types/base';
|
|
7
|
+
import { GrowingIOType } from '@@/types/growingIO';
|
|
8
|
+
import { isString, unset } from '@@/utils/glodash';
|
|
9
|
+
import { getGlobal, niceTry } from '@@/utils/tools';
|
|
10
|
+
import { OriginOptions } from '@@/types/dataStore';
|
|
11
|
+
import EMIT_MSG from '@@/constants/emitMsg';
|
|
12
|
+
|
|
13
|
+
export class GioMultipleInstances {
|
|
14
|
+
public subTrackingIds: string[];
|
|
15
|
+
constructor(public growingIO: GrowingIOType) {
|
|
16
|
+
this.subTrackingIds = [];
|
|
17
|
+
this.growingIO.emitter.on(EMIT_MSG.ON_SDK_INITIALIZE_BEFORE, () => {
|
|
18
|
+
// 自动重写部分代码以实现多实例功能
|
|
19
|
+
if (!this.growingIO.trackingId) {
|
|
20
|
+
this.rewriteDataStore();
|
|
21
|
+
}
|
|
22
|
+
// 挂载子实例集合对象
|
|
23
|
+
if (!this.growingIO.subInstance) {
|
|
24
|
+
this.growingIO.subInstance = {};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
this.growingIO.emitter.on(EMIT_MSG.OPTION_INITIALIZED, ({ trackingId }) => {
|
|
28
|
+
// 是子实例
|
|
29
|
+
if (
|
|
30
|
+
this.growingIO.trackingId &&
|
|
31
|
+
this.growingIO.trackingId !== trackingId
|
|
32
|
+
) {
|
|
33
|
+
// 把所有已初始化过的子实例trackingId保存下来方便预定义事件和无埋点事件广播时调用
|
|
34
|
+
this.subTrackingIds.push(trackingId);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 判断当前trackingId实例类型,为主实例还是子实例
|
|
40
|
+
getTrackerType = (trackingId: string, growingIO: GrowingIOType): number => {
|
|
41
|
+
return !growingIO.trackingId || growingIO.trackingId === trackingId ? 1 : 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 重写dataStore中的部分内容
|
|
45
|
+
rewriteDataStore = () => {
|
|
46
|
+
// 获取采集实例
|
|
47
|
+
this.growingIO.dataStore.getTrackerVds = (trackingId: string) => {
|
|
48
|
+
if (this.growingIO.trackingId === trackingId) {
|
|
49
|
+
const vds = { ...this.growingIO.vdsConfig };
|
|
50
|
+
unset(vds, 'subInstance');
|
|
51
|
+
if (!this.growingIO.plugins.gioTaobaoAdapter) {
|
|
52
|
+
unset(vds, 'tbConfig');
|
|
53
|
+
}
|
|
54
|
+
return vds;
|
|
55
|
+
} else {
|
|
56
|
+
return this.growingIO.subInstance[trackingId]
|
|
57
|
+
? { ...this.growingIO.subInstance[trackingId] }
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// 初始化实例配置的方法
|
|
63
|
+
this.growingIO.dataStore.initTrackerOptions = (options: OriginOptions) => {
|
|
64
|
+
const trackerOptions = this.growingIO.dataStore.initOptions(options);
|
|
65
|
+
const trackerType = this.getTrackerType(
|
|
66
|
+
options.trackingId,
|
|
67
|
+
this.growingIO
|
|
68
|
+
);
|
|
69
|
+
trackerOptions.trackingId = options.trackingId;
|
|
70
|
+
if (trackerType) {
|
|
71
|
+
// 当前初始化主实例时给主实例赋值trackingId
|
|
72
|
+
this.growingIO.trackingId = options.trackingId;
|
|
73
|
+
// 主实例的配置直接挂在growingIO上
|
|
74
|
+
this.growingIO.vdsConfig = trackerOptions;
|
|
75
|
+
// 把主实例挂到小程序全局对象上
|
|
76
|
+
getGlobal().vdsConfig = trackerOptions;
|
|
77
|
+
} else {
|
|
78
|
+
// 子实例无效的配置项删除
|
|
79
|
+
unset(trackerOptions, [
|
|
80
|
+
'autotrack',
|
|
81
|
+
'debug',
|
|
82
|
+
'forceLogin',
|
|
83
|
+
'keepAlive',
|
|
84
|
+
'originalSource',
|
|
85
|
+
'performance',
|
|
86
|
+
'pluginMode',
|
|
87
|
+
'taro',
|
|
88
|
+
'taroVue',
|
|
89
|
+
'tbConfig',
|
|
90
|
+
'uniVue'
|
|
91
|
+
]);
|
|
92
|
+
// 子实例的配置挂在subInstance下,以trackingId作为key值存储
|
|
93
|
+
this.growingIO.subInstance[options.trackingId] = trackerOptions;
|
|
94
|
+
// 把子实例挂到小程序全局对象上
|
|
95
|
+
if (!getGlobal().vdsConfig?.subInstance) {
|
|
96
|
+
getGlobal().vdsConfig.subInstance = {};
|
|
97
|
+
}
|
|
98
|
+
getGlobal().vdsConfig.subInstance[options.trackingId] = trackerOptions;
|
|
99
|
+
}
|
|
100
|
+
return trackerOptions;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 初始化实例的hooker
|
|
104
|
+
this.growingIO.dataStore.initTrackerHooker = (options: OriginOptions) => {
|
|
105
|
+
const trackerType = this.getTrackerType(
|
|
106
|
+
options.trackingId,
|
|
107
|
+
this.growingIO
|
|
108
|
+
);
|
|
109
|
+
if (trackerType) {
|
|
110
|
+
const { platformConfig, inPlugin, minipInstance, plugins, dataStore } =
|
|
111
|
+
this.growingIO;
|
|
112
|
+
const { uniVue, taro } = options;
|
|
113
|
+
// 如果是使用全量版本时,当前小程序不是框架的,要允许原生的hook
|
|
114
|
+
if (!(uniVue || taro)) {
|
|
115
|
+
platformConfig.canHook = true;
|
|
116
|
+
}
|
|
117
|
+
// 初始化核心钩子(重写全局)
|
|
118
|
+
if (!inPlugin || ['tbp', 'jdp'].includes(minipInstance.platform)) {
|
|
119
|
+
dataStore.eventHooks.initEventHooks();
|
|
120
|
+
}
|
|
121
|
+
/** 第三方框架重写 */
|
|
122
|
+
// uniapp
|
|
123
|
+
if (uniVue) {
|
|
124
|
+
plugins?.gioUniAppAdapter?.main();
|
|
125
|
+
}
|
|
126
|
+
// taro
|
|
127
|
+
if (taro) {
|
|
128
|
+
plugins?.gioTaroAdapter?.main();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// 多实例时处理复制发送
|
|
134
|
+
const originFunction = this.growingIO.dataStore.eventConverter;
|
|
135
|
+
const self = this;
|
|
136
|
+
this.growingIO.dataStore.eventConverter = function (...args) {
|
|
137
|
+
const event: EXTEND_EVENT = args[0];
|
|
138
|
+
// 埋点事件使用合并后的发送目标发送
|
|
139
|
+
if (event.eventType === 'CUSTOM') {
|
|
140
|
+
const sendTo = [event.trackingId];
|
|
141
|
+
niceTry(() => {
|
|
142
|
+
event['&&sendTo'].forEach((s) => {
|
|
143
|
+
// 合法且不重复的实例
|
|
144
|
+
if (
|
|
145
|
+
isString(s) &&
|
|
146
|
+
self.growingIO.dataStore.getTrackerVds(s) &&
|
|
147
|
+
!sendTo.includes(s)
|
|
148
|
+
) {
|
|
149
|
+
sendTo.push(s);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
unset(event, '&&sendTo');
|
|
154
|
+
sendTo.forEach((trackingId: string) => {
|
|
155
|
+
const { eventContextBuilder } = self.growingIO.dataStore;
|
|
156
|
+
originFunction.call(this, {
|
|
157
|
+
...event,
|
|
158
|
+
...eventContextBuilder(trackingId)
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
// 其他事件直接发给指定调用实例
|
|
163
|
+
originFunction.call(this, event);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
onSendBefore = ({ eventsQueue, requestData, trackingId }: any) => {
|
|
169
|
+
// 不是主实例的事件由多实例插件来提交请求
|
|
170
|
+
if (trackingId !== this.growingIO.trackingId) {
|
|
171
|
+
this.growingIO.uploader.sendEvent(eventsQueue, requestData);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export default { name: 'gioMultipleInstances', method: GioMultipleInstances };
|
package/src/types/base.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export interface StringObject {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
interface TBConfig {
|
|
2
6
|
cloud: any;
|
|
3
7
|
cloudFuncSend?: boolean;
|
|
@@ -35,8 +39,6 @@ export interface UserOptions {
|
|
|
35
39
|
requestTimeout?: number;
|
|
36
40
|
// 数据上报域名
|
|
37
41
|
serverUrl?: string;
|
|
38
|
-
// 是否标记为分包
|
|
39
|
-
subpackage: boolean;
|
|
40
42
|
// taro框架实例
|
|
41
43
|
taro?: any;
|
|
42
44
|
// taro框架vue实例
|
|
@@ -76,7 +78,7 @@ export type EventTypes =
|
|
|
76
78
|
| 'VIEW_CLICK'
|
|
77
79
|
| 'VIEW_CHANGE';
|
|
78
80
|
|
|
79
|
-
export interface
|
|
81
|
+
export interface EVENT {
|
|
80
82
|
appChannel: string;
|
|
81
83
|
appVersion: string;
|
|
82
84
|
attributes?: any;
|
|
@@ -112,6 +114,11 @@ export interface Event {
|
|
|
112
114
|
xpath?: string;
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
export interface EXTEND_EVENT extends EVENT {
|
|
118
|
+
requestId: string;
|
|
119
|
+
trackingId: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
export type Actions =
|
|
116
123
|
| 'tap'
|
|
117
124
|
| 'longpress'
|
package/src/types/dataStore.ts
CHANGED
|
@@ -1,43 +1,58 @@
|
|
|
1
1
|
import { UserOptions } from '@@/types/base';
|
|
2
2
|
import { EventHooksType } from '@@/types/eventHooks';
|
|
3
3
|
|
|
4
|
+
export type StorageKeyType =
|
|
5
|
+
| 'gsid'
|
|
6
|
+
| 'originalSource'
|
|
7
|
+
| 'uid'
|
|
8
|
+
| 'sessionId'
|
|
9
|
+
| 'userId'
|
|
10
|
+
| 'userKey'
|
|
11
|
+
| 'gioId';
|
|
12
|
+
|
|
4
13
|
export interface OriginOptions extends UserOptions {
|
|
5
14
|
appId: string;
|
|
6
15
|
dataSourceId?: string;
|
|
7
16
|
projectId: string;
|
|
17
|
+
trackingId: string;
|
|
8
18
|
}
|
|
9
19
|
|
|
10
20
|
export interface DataStoreType {
|
|
11
|
-
buildAddFavorites: (args: any) => void;
|
|
12
|
-
buildAppMessageEvent: (args: any) => void;
|
|
13
|
-
buildTimelineEvent: (args: any) => void;
|
|
14
|
-
|
|
21
|
+
buildAddFavorites: (trackingId: string, args: any) => void;
|
|
22
|
+
buildAppMessageEvent: (trackingId: string, args: any) => void;
|
|
23
|
+
buildTimelineEvent: (trackingId: string, args: any) => void;
|
|
24
|
+
// 事件通用维度组装
|
|
25
|
+
eventContextBuilder?: (trackingId: string, params?: any) => any;
|
|
15
26
|
eventConverter?: (event) => void;
|
|
16
27
|
eventHooks: EventHooksType;
|
|
17
28
|
eventInterceptor?: (event: any | void) => void;
|
|
18
29
|
eventReleaseInspector?: () => void;
|
|
19
30
|
generalProps: any;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
getStorageKey: (trackingId: string, name: StorageKeyType) => string;
|
|
32
|
+
getTrackerVds: (trackingId: string) => any;
|
|
33
|
+
getOption: (trackingId: string, k?: string) => OriginOptions;
|
|
34
|
+
getOriginalSource: (trackingId: string) => any;
|
|
35
|
+
getGsid: (trackingId: string) => number;
|
|
36
|
+
setGsid: (trackingId: string, value: number) => void;
|
|
37
|
+
initTrackerOptions: (userOptions: OriginOptions) => any;
|
|
38
|
+
initTrackerHooker: (trackerOptions: OriginOptions) => void;
|
|
39
|
+
initOptions: (userOptions: OriginOptions) => OriginOptions;
|
|
40
|
+
initStorageInfo: (trackingId: string) => void;
|
|
26
41
|
interceptEvents: any[];
|
|
27
|
-
keepAlive: number;
|
|
28
42
|
lastCloseTime: number;
|
|
29
43
|
lastPageEvent: any;
|
|
30
44
|
lastScene: number | string;
|
|
31
45
|
lastVisitEvent: any;
|
|
32
46
|
locationData: any;
|
|
33
|
-
originalSourceName: string;
|
|
34
47
|
saveStorageInfo: () => void;
|
|
35
48
|
scene: number | string;
|
|
36
|
-
sendPage: (props?: any) => void;
|
|
37
|
-
sendVisit: (props?: any) => void;
|
|
38
|
-
setOption: (k: string, v: any) => boolean;
|
|
39
|
-
setOriginalSource: (origins: any) => void;
|
|
49
|
+
sendPage: (trackingId: string, props?: any) => void;
|
|
50
|
+
sendVisit: (trackingId: string, props?: any) => void;
|
|
51
|
+
setOption: (trackingId: string, k: string, v: any) => boolean;
|
|
52
|
+
setOriginalSource: (trackingId: string, origins: any) => void;
|
|
40
53
|
shareOut: boolean;
|
|
41
54
|
toggleShareOut: (v?: boolean) => void;
|
|
42
55
|
trackTimers?: any;
|
|
56
|
+
initializedTrackingIds: string[];
|
|
57
|
+
trackersExecute: (callback: (trackingId: string) => void) => void;
|
|
43
58
|
}
|
package/src/types/eventHooks.ts
CHANGED
|
@@ -84,8 +84,7 @@ export interface MinipPageType {
|
|
|
84
84
|
currentLifecycle: string;
|
|
85
85
|
parsePage: (page: any, query: any) => void;
|
|
86
86
|
getQuery: (query: any) => string;
|
|
87
|
-
getReferralPage: () => string;
|
|
88
|
-
saveShareId: (query: string) => void;
|
|
87
|
+
getReferralPage: (trackingId: string) => string;
|
|
89
88
|
buildShareQuery: (result: PageShareResult) => [string, string];
|
|
90
89
|
updateAppMessageResult: (result: PageShareResult) => PageShareResult;
|
|
91
90
|
updateTimelineResult: (result: PageShareResult) => PageShareResult;
|
|
@@ -98,10 +97,6 @@ export interface EventHooksType {
|
|
|
98
97
|
appHandlers: string[];
|
|
99
98
|
pageHandlers: string[];
|
|
100
99
|
actionEventTypes: string[];
|
|
101
|
-
originalApp: (any: any) => any;
|
|
102
|
-
originalPage: (any: any) => any;
|
|
103
|
-
originalComponent: (any: any) => any;
|
|
104
|
-
originalBehavior: (any: any) => any;
|
|
105
100
|
appEffects: any;
|
|
106
101
|
pageEffects: any;
|
|
107
102
|
actionEffects: any;
|
|
@@ -128,6 +123,10 @@ export interface EventHooksType {
|
|
|
128
123
|
pageOverriding: (options: any) => any;
|
|
129
124
|
// Component/Behavior重写(重写除构造函数之外的所有方法)
|
|
130
125
|
componentOverriding: (options: any) => any;
|
|
126
|
+
// 挂载App生命周期的effect方法
|
|
127
|
+
setAppEffectCbs: () => void;
|
|
128
|
+
// 挂载Page/Component生命周期的effect方法
|
|
129
|
+
setPageEffectCbs: () => void;
|
|
131
130
|
// App属性重写复用方法
|
|
132
131
|
growingApp: (app: any) => any;
|
|
133
132
|
// Page属性重写复用方法
|
package/src/types/growingIO.ts
CHANGED
|
@@ -40,54 +40,70 @@ export interface GrowingIOType {
|
|
|
40
40
|
taro3VMs?: any;
|
|
41
41
|
// 分享数据
|
|
42
42
|
shareAppMessage?: any;
|
|
43
|
+
// 用于放在事件中区别于为其他功能而生成事件的跟踪器Id,默认为g0
|
|
44
|
+
trackingId: string;
|
|
45
|
+
// 存储子实例的配置和信息
|
|
46
|
+
subInstance: {
|
|
47
|
+
[key: string]: OriginOptions;
|
|
48
|
+
};
|
|
43
49
|
// 初始化方法
|
|
44
50
|
init: (args: any) => void;
|
|
45
51
|
// 注册插件
|
|
46
52
|
registerPlugins?: (path?: string) => void;
|
|
47
53
|
// 运行中修改配置
|
|
48
|
-
setOption: (optionKey: string, value: any) => void;
|
|
54
|
+
setOption: (trackingId: string, optionKey: string, value: any) => void;
|
|
49
55
|
// 运行中获取配置
|
|
50
|
-
getOption: (optionKey?: string) => any;
|
|
56
|
+
getOption: (trackingId: string, optionKey?: string) => any;
|
|
51
57
|
// 创建自定义埋点事件
|
|
52
58
|
track?: (
|
|
59
|
+
trackingId: string,
|
|
53
60
|
name: string,
|
|
54
61
|
properties: { [key: string]: string },
|
|
55
62
|
items?: { key: string; id: string; attributes?: { [key: string]: string } }
|
|
56
63
|
) => void;
|
|
57
64
|
// 设置登录用户Id
|
|
58
|
-
setUserId?: (userId: string, userKey?: string) => void;
|
|
65
|
+
setUserId?: (trackingId: string, userId: string, userKey?: string) => void;
|
|
59
66
|
// 清除登录用户Id
|
|
60
|
-
clearUserId?: () => void;
|
|
67
|
+
clearUserId?: (trackingId: string) => void;
|
|
61
68
|
// 设置openId作为uid
|
|
62
|
-
identify?: (openId: string) => void;
|
|
69
|
+
identify?: (trackingId: string, openId: string) => void;
|
|
63
70
|
// 发送用户变量
|
|
64
|
-
setUserAttributes?: (userAttributes: any) => void;
|
|
71
|
+
setUserAttributes?: (trackingId: string, userAttributes: any) => void;
|
|
65
72
|
// 初始化回调
|
|
66
73
|
initCallback?: () => void;
|
|
67
74
|
// 错误提示
|
|
68
75
|
callError?: (fn: string, type?: boolean, msg?: string) => void;
|
|
69
76
|
// 工具类
|
|
70
77
|
utils?: any;
|
|
71
|
-
// 事件通用维度组装
|
|
72
|
-
eventContextBuilder?: (updateTime?: boolean) => any;
|
|
73
78
|
// 事件转换
|
|
74
79
|
eventConverter?: (event: any) => void;
|
|
75
80
|
// 事件拦截器
|
|
76
81
|
eventInterceptor?: (event: any) => void;
|
|
77
82
|
// 设置埋点通用属性
|
|
78
|
-
setGeneralProps?: (properties: any) => void;
|
|
83
|
+
setGeneralProps?: (trackingId: string, properties: any) => void;
|
|
79
84
|
// 清除已设置的埋点通用属性
|
|
80
|
-
clearGeneralProps?: (
|
|
85
|
+
clearGeneralProps?: (
|
|
86
|
+
trackingId: string,
|
|
87
|
+
properties: string[] | undefined
|
|
88
|
+
) => void;
|
|
81
89
|
// 手动更新曝光监听
|
|
82
90
|
updateImpression?: (collect?: any) => void;
|
|
83
91
|
// 清除所有事件计时器
|
|
84
|
-
clearTrackTimer?: () => void;
|
|
92
|
+
clearTrackTimer?: (trackingId: string) => void;
|
|
85
93
|
// 手动获取位置信息补发visit上报
|
|
86
|
-
setLocation: (
|
|
94
|
+
setLocation: (
|
|
95
|
+
trackingId: string,
|
|
96
|
+
latitude: number,
|
|
97
|
+
longitude: number
|
|
98
|
+
) => void;
|
|
87
99
|
// 获取打通信息
|
|
88
|
-
getGioInfo: () => string;
|
|
100
|
+
getGioInfo: (trackingId: string) => string;
|
|
89
101
|
// 获取ABTest数据
|
|
90
|
-
getABTest?: (
|
|
102
|
+
getABTest?: (
|
|
103
|
+
trackingId: string,
|
|
104
|
+
layerId: string,
|
|
105
|
+
callback?: (arg: any) => any
|
|
106
|
+
) => void;
|
|
91
107
|
|
|
92
108
|
emitter: {
|
|
93
109
|
emit?: (msg: string, args?: any) => void;
|
package/src/types/platforms.ts
CHANGED
|
@@ -28,10 +28,6 @@ export interface PlatformConfigType {
|
|
|
28
28
|
appHandlers?: string[];
|
|
29
29
|
pageHandlers?: string[];
|
|
30
30
|
actionEventTypes?: string[];
|
|
31
|
-
originalPage?: (any) => any;
|
|
32
|
-
originalApp?: (any) => any;
|
|
33
|
-
originalComponent?: (any) => any;
|
|
34
|
-
originalBehavior?: (any) => any;
|
|
35
31
|
hooks?: {
|
|
36
32
|
App: boolean;
|
|
37
33
|
Page: boolean;
|
package/src/types/plugins.ts
CHANGED
|
@@ -9,11 +9,11 @@ export interface PluginsType {
|
|
|
9
9
|
gioCustomTracking?: any;
|
|
10
10
|
gioEventAutoTracking?: any;
|
|
11
11
|
gioImpressionTracking?: any;
|
|
12
|
-
gioMultiIntegrate?: any;
|
|
13
12
|
gioPerformance?: any;
|
|
14
13
|
gioTaobaoAdapter?: any;
|
|
15
14
|
gioTaroAdapter?: any;
|
|
16
15
|
gioUniAppAdapter?: any;
|
|
16
|
+
gioMultipleInstances?: any;
|
|
17
17
|
innerPluginInit: () => void;
|
|
18
18
|
outerPluginInit?: (folder?: string) => void;
|
|
19
19
|
install: (pluginName: string, showLog: boolean) => boolean;
|
package/src/types/uploader.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { EVENT, EXTEND_EVENT } from './base';
|
|
2
|
+
|
|
1
3
|
export interface UploaderType {
|
|
2
4
|
// 因forceLogin配置积压的事件请求队列
|
|
3
|
-
hoardingQueue: any
|
|
5
|
+
hoardingQueue: any;
|
|
4
6
|
// 请求队列
|
|
5
|
-
requestQueue: any
|
|
7
|
+
requestQueue: any;
|
|
6
8
|
// 请求限制最大数
|
|
7
9
|
requestLimit: number;
|
|
8
10
|
// 请求重试限制最大数
|
|
@@ -11,14 +13,18 @@ export interface UploaderType {
|
|
|
11
13
|
retryIds: any;
|
|
12
14
|
// 请求中的请求数
|
|
13
15
|
requestingNum: number;
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
+
// 获取积压列表
|
|
17
|
+
getHoardingQueue: (trackingId: string) => EXTEND_EVENT[];
|
|
18
|
+
// 获取请求列表
|
|
19
|
+
getRequestQueue: (trackingId: string) => EXTEND_EVENT[];
|
|
16
20
|
// 提交请求至队列
|
|
17
|
-
commitRequest: (
|
|
18
|
-
//
|
|
19
|
-
initiateRequest: (forceSend?: boolean) => void;
|
|
21
|
+
commitRequest: (commitData: EXTEND_EVENT) => void;
|
|
22
|
+
// 初始化请求
|
|
23
|
+
initiateRequest: (trackingId: string, forceSend?: boolean) => void;
|
|
24
|
+
// 发送事件
|
|
25
|
+
sendEvent: (eventsQueue: EXTEND_EVENT[], requestData: EVENT[]) => void;
|
|
20
26
|
// 请求错误回调
|
|
21
|
-
requestFailFn: (
|
|
22
|
-
//
|
|
23
|
-
generateURL
|
|
27
|
+
requestFailFn: (event: EXTEND_EVENT) => void;
|
|
28
|
+
// 生成上报地址
|
|
29
|
+
generateURL: (trackingId: string) => void;
|
|
24
30
|
}
|
package/src/types/userStore.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
export interface UserStoreType {
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
2
|
+
// 获取设备Id
|
|
3
|
+
getUid: () => string;
|
|
4
|
+
// 设置设备Id
|
|
5
|
+
setUid: (id: string) => void;
|
|
6
|
+
// 获取sessionId
|
|
7
|
+
getSessionId: (trackingId: string) => string;
|
|
8
|
+
// 设置sessionId
|
|
9
|
+
setSessionId: (trackingId: string, id?: string) => void;
|
|
10
|
+
// 获取userId
|
|
11
|
+
getUserId: (trackingId: string) => string;
|
|
12
|
+
// 设置userId
|
|
13
|
+
setUserId: (trackingId: string, id?: string) => void;
|
|
14
|
+
// 获取userKey
|
|
15
|
+
getUserKey: (trackingId: string) => string;
|
|
16
|
+
// 设置userKey
|
|
17
|
+
setUserKey: (trackingId: string, key?: string) => void;
|
|
18
|
+
// 获取gioId
|
|
19
|
+
getGioId: (trackingId: string) => string;
|
|
20
|
+
// 设置gioId
|
|
21
|
+
setGioId: (trackingId: string, id?: string) => void;
|
|
18
22
|
// 初始化用户信息
|
|
19
|
-
initUserInfo: () => void;
|
|
23
|
+
initUserInfo: (trackingId: string) => void;
|
|
20
24
|
// 退出小程序时在存储中同步用户信息
|
|
21
25
|
saveUserInfo: () => void;
|
|
22
26
|
}
|
package/src/utils/glodash.ts
CHANGED
|
@@ -96,7 +96,7 @@ export const dropWhile = (o: any, fn: (currentValue: any) => boolean): any => {
|
|
|
96
96
|
* @param o array
|
|
97
97
|
* @returns new array
|
|
98
98
|
*/
|
|
99
|
-
export const compact = (o: any): any => {
|
|
99
|
+
export const compact = (o: any, ignoreZero = false): any => {
|
|
100
100
|
if (isArray(o)) {
|
|
101
101
|
let resIndex = 0;
|
|
102
102
|
const result: any = [];
|
|
@@ -104,6 +104,9 @@ export const compact = (o: any): any => {
|
|
|
104
104
|
if (value && !isEmpty(value)) {
|
|
105
105
|
result[resIndex++] = value;
|
|
106
106
|
}
|
|
107
|
+
if (ignoreZero && value === 0) {
|
|
108
|
+
result[resIndex++] = value;
|
|
109
|
+
}
|
|
107
110
|
}
|
|
108
111
|
return result;
|
|
109
112
|
} else {
|
|
@@ -191,8 +194,12 @@ export const upperFirst = (s: any): string | any => {
|
|
|
191
194
|
* @param target string
|
|
192
195
|
* @returns boolean
|
|
193
196
|
*/
|
|
194
|
-
export const startsWith = (s: string, target: string): boolean =>
|
|
195
|
-
s
|
|
197
|
+
export const startsWith = (s: string, target: string): boolean => {
|
|
198
|
+
if (!isString(s)) {
|
|
199
|
+
s = toString(s);
|
|
200
|
+
}
|
|
201
|
+
return s.slice(0, target.length) === target;
|
|
202
|
+
};
|
|
196
203
|
|
|
197
204
|
/**
|
|
198
205
|
* 判断字符串是否以指定字符结尾
|
package/src/utils/tools.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { IMP_EVENTNAME_REG } from '@@/constants/regex';
|
|
1
2
|
import {
|
|
3
|
+
compact,
|
|
2
4
|
find,
|
|
3
5
|
forEach,
|
|
4
6
|
head,
|
|
@@ -11,7 +13,8 @@ import {
|
|
|
11
13
|
keys,
|
|
12
14
|
split,
|
|
13
15
|
startsWith,
|
|
14
|
-
toString
|
|
16
|
+
toString,
|
|
17
|
+
unset
|
|
15
18
|
} from '@@/utils/glodash';
|
|
16
19
|
|
|
17
20
|
// 控制台打印提示信息,包含错误、警告和信息3种形式
|
|
@@ -62,7 +65,7 @@ export const eventNameValidate = (eventName: string, callback: () => void) => {
|
|
|
62
65
|
if (
|
|
63
66
|
isString(eventName) &&
|
|
64
67
|
!isEmpty(eventName) &&
|
|
65
|
-
eventName.match(
|
|
68
|
+
eventName.match(IMP_EVENTNAME_REG)
|
|
66
69
|
) {
|
|
67
70
|
return callback();
|
|
68
71
|
} else {
|
|
@@ -74,6 +77,22 @@ export const eventNameValidate = (eventName: string, callback: () => void) => {
|
|
|
74
77
|
}
|
|
75
78
|
};
|
|
76
79
|
|
|
80
|
+
// 获取动态属性的值
|
|
81
|
+
export const getDynamicAttributes = (properties: any) => {
|
|
82
|
+
if (!isNil(properties)) {
|
|
83
|
+
keys(properties).forEach((k: string) => {
|
|
84
|
+
if (isFunction(properties[k])) {
|
|
85
|
+
properties[k] = niceTry(() => properties[k]());
|
|
86
|
+
} else if (isObject(properties[k])) {
|
|
87
|
+
unset(properties, k);
|
|
88
|
+
} else if (!isArray(properties[k])) {
|
|
89
|
+
properties[k] = toString(properties[k]);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return properties;
|
|
94
|
+
};
|
|
95
|
+
|
|
77
96
|
// 生成uuid
|
|
78
97
|
export const guid = () => {
|
|
79
98
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
@@ -132,7 +151,7 @@ export const compareVersion = (v1 = '', v2 = '') => {
|
|
|
132
151
|
// 获取vue的主版本号
|
|
133
152
|
export const getVueVersion = (vue) => {
|
|
134
153
|
if (vue) {
|
|
135
|
-
const mv = Number
|
|
154
|
+
const mv = Number(head(split(vue.version, '.')));
|
|
136
155
|
return Number.isNaN(mv) ? 0 : mv;
|
|
137
156
|
} else {
|
|
138
157
|
return 0;
|
|
@@ -282,12 +301,14 @@ export const getGlobal = () => {
|
|
|
282
301
|
export const limitObject = (o: any) => {
|
|
283
302
|
const ob = {};
|
|
284
303
|
if (isObject(o)) {
|
|
304
|
+
// 移除预置的'&&sendTo'字段
|
|
305
|
+
unset(o, '&&sendTo');
|
|
285
306
|
forEach(o, (v, k) => {
|
|
286
307
|
const key = toString(k).slice(0, 100);
|
|
287
308
|
if (isObject(v)) {
|
|
288
309
|
ob[key] = limitObject(v);
|
|
289
310
|
} else if (isArray(v)) {
|
|
290
|
-
ob[key] = v.slice(0, 100);
|
|
311
|
+
ob[key] = compact(v.slice(0, 100), true);
|
|
291
312
|
ob[key] = ob[key].join('||').slice(0, 1000);
|
|
292
313
|
} else {
|
|
293
314
|
ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
|
|
@@ -368,7 +389,7 @@ export const qsParse = (s: string) => {
|
|
|
368
389
|
};
|
|
369
390
|
|
|
370
391
|
// 将字符串转为hash
|
|
371
|
-
export const hashCode = (string) => {
|
|
392
|
+
export const hashCode = (string: string, abs = false) => {
|
|
372
393
|
let hash = 0;
|
|
373
394
|
if (isEmpty(string) || typeof string === 'boolean') {
|
|
374
395
|
return hash;
|
|
@@ -380,5 +401,5 @@ export const hashCode = (string) => {
|
|
|
380
401
|
hash = hash & hash; //Convert to 32bit integer
|
|
381
402
|
i++;
|
|
382
403
|
}
|
|
383
|
-
return hash;
|
|
404
|
+
return abs ? Math.abs(hash) : hash;
|
|
384
405
|
};
|