gio-miniprogram-sdk 4.4.2 → 4.5.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/README.md +13 -11
- 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/mpx.js +1 -0
- 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 +13 -2
- 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
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 名称:数据加密插件
|
|
3
|
-
* 用途:用于提供上报数据加密。
|
|
4
|
-
*/
|
|
5
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
|
-
|
|
7
|
-
class GioCompress {
|
|
8
|
-
public pluginVersion: string;
|
|
9
|
-
private f;
|
|
10
|
-
private _compress;
|
|
11
|
-
constructor(public growingIO: GrowingIOType) {
|
|
12
|
-
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
13
|
-
this.f = String.fromCharCode;
|
|
14
|
-
this._compress = function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
15
|
-
if (uncompressed === null) return '';
|
|
16
|
-
let i,
|
|
17
|
-
value,
|
|
18
|
-
context_dictionary = {},
|
|
19
|
-
context_dictionaryToCreate = {},
|
|
20
|
-
context_c = '',
|
|
21
|
-
context_wc = '',
|
|
22
|
-
context_w = '',
|
|
23
|
-
context_enlargeIn = 2, // Compensate for the first entry which should not count
|
|
24
|
-
context_dictSize = 3,
|
|
25
|
-
context_numBits = 2,
|
|
26
|
-
context_data = [],
|
|
27
|
-
context_data_val = 0,
|
|
28
|
-
context_data_position = 0,
|
|
29
|
-
ii;
|
|
30
|
-
|
|
31
|
-
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
32
|
-
context_c = uncompressed.charAt(ii);
|
|
33
|
-
if (
|
|
34
|
-
!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)
|
|
35
|
-
) {
|
|
36
|
-
context_dictionary[context_c] = context_dictSize++;
|
|
37
|
-
context_dictionaryToCreate[context_c] = true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
context_wc = context_w + context_c;
|
|
41
|
-
if (
|
|
42
|
-
Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)
|
|
43
|
-
) {
|
|
44
|
-
context_w = context_wc;
|
|
45
|
-
} else {
|
|
46
|
-
if (
|
|
47
|
-
Object.prototype.hasOwnProperty.call(
|
|
48
|
-
context_dictionaryToCreate,
|
|
49
|
-
context_w
|
|
50
|
-
)
|
|
51
|
-
) {
|
|
52
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
53
|
-
for (i = 0; i < context_numBits; i++) {
|
|
54
|
-
context_data_val = context_data_val << 1;
|
|
55
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
56
|
-
context_data_position = 0;
|
|
57
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
58
|
-
context_data_val = 0;
|
|
59
|
-
} else {
|
|
60
|
-
context_data_position++;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
value = context_w.charCodeAt(0);
|
|
64
|
-
for (i = 0; i < 8; i++) {
|
|
65
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
66
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
67
|
-
context_data_position = 0;
|
|
68
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
69
|
-
context_data_val = 0;
|
|
70
|
-
} else {
|
|
71
|
-
context_data_position++;
|
|
72
|
-
}
|
|
73
|
-
value = value >> 1;
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
value = 1;
|
|
77
|
-
for (i = 0; i < context_numBits; i++) {
|
|
78
|
-
context_data_val = (context_data_val << 1) | value;
|
|
79
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
80
|
-
context_data_position = 0;
|
|
81
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
82
|
-
context_data_val = 0;
|
|
83
|
-
} else {
|
|
84
|
-
context_data_position++;
|
|
85
|
-
}
|
|
86
|
-
value = 0;
|
|
87
|
-
}
|
|
88
|
-
value = context_w.charCodeAt(0);
|
|
89
|
-
for (i = 0; i < 16; i++) {
|
|
90
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
91
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
92
|
-
context_data_position = 0;
|
|
93
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
94
|
-
context_data_val = 0;
|
|
95
|
-
} else {
|
|
96
|
-
context_data_position++;
|
|
97
|
-
}
|
|
98
|
-
value = value >> 1;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
context_enlargeIn--;
|
|
102
|
-
if (context_enlargeIn === 0) {
|
|
103
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
104
|
-
context_numBits++;
|
|
105
|
-
}
|
|
106
|
-
delete context_dictionaryToCreate[context_w];
|
|
107
|
-
} else {
|
|
108
|
-
value = context_dictionary[context_w];
|
|
109
|
-
for (i = 0; i < context_numBits; i++) {
|
|
110
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
111
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
112
|
-
context_data_position = 0;
|
|
113
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
114
|
-
context_data_val = 0;
|
|
115
|
-
} else {
|
|
116
|
-
context_data_position++;
|
|
117
|
-
}
|
|
118
|
-
value = value >> 1;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
context_enlargeIn--;
|
|
122
|
-
if (context_enlargeIn === 0) {
|
|
123
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
124
|
-
context_numBits++;
|
|
125
|
-
}
|
|
126
|
-
// Add wc to the dictionary.
|
|
127
|
-
context_dictionary[context_wc] = context_dictSize++;
|
|
128
|
-
context_w = String(context_c);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Output the code for w.
|
|
133
|
-
if (context_w !== '') {
|
|
134
|
-
if (
|
|
135
|
-
Object.prototype.hasOwnProperty.call(
|
|
136
|
-
context_dictionaryToCreate,
|
|
137
|
-
context_w
|
|
138
|
-
)
|
|
139
|
-
) {
|
|
140
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
141
|
-
for (i = 0; i < context_numBits; i++) {
|
|
142
|
-
context_data_val = context_data_val << 1;
|
|
143
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
144
|
-
context_data_position = 0;
|
|
145
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
146
|
-
context_data_val = 0;
|
|
147
|
-
} else {
|
|
148
|
-
context_data_position++;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
value = context_w.charCodeAt(0);
|
|
152
|
-
for (i = 0; i < 8; i++) {
|
|
153
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
154
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
155
|
-
context_data_position = 0;
|
|
156
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
157
|
-
context_data_val = 0;
|
|
158
|
-
} else {
|
|
159
|
-
context_data_position++;
|
|
160
|
-
}
|
|
161
|
-
value = value >> 1;
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
value = 1;
|
|
165
|
-
for (i = 0; i < context_numBits; i++) {
|
|
166
|
-
context_data_val = (context_data_val << 1) | value;
|
|
167
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
168
|
-
context_data_position = 0;
|
|
169
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
170
|
-
context_data_val = 0;
|
|
171
|
-
} else {
|
|
172
|
-
context_data_position++;
|
|
173
|
-
}
|
|
174
|
-
value = 0;
|
|
175
|
-
}
|
|
176
|
-
value = context_w.charCodeAt(0);
|
|
177
|
-
for (i = 0; i < 16; i++) {
|
|
178
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
179
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
180
|
-
context_data_position = 0;
|
|
181
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
182
|
-
context_data_val = 0;
|
|
183
|
-
} else {
|
|
184
|
-
context_data_position++;
|
|
185
|
-
}
|
|
186
|
-
value = value >> 1;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
context_enlargeIn--;
|
|
190
|
-
if (context_enlargeIn === 0) {
|
|
191
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
192
|
-
context_numBits++;
|
|
193
|
-
}
|
|
194
|
-
delete context_dictionaryToCreate[context_w];
|
|
195
|
-
} else {
|
|
196
|
-
value = context_dictionary[context_w];
|
|
197
|
-
for (i = 0; i < context_numBits; i++) {
|
|
198
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
199
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
200
|
-
context_data_position = 0;
|
|
201
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
202
|
-
context_data_val = 0;
|
|
203
|
-
} else {
|
|
204
|
-
context_data_position++;
|
|
205
|
-
}
|
|
206
|
-
value = value >> 1;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
context_enlargeIn--;
|
|
210
|
-
if (context_enlargeIn === 0) {
|
|
211
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
212
|
-
context_numBits++;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Mark the end of the stream
|
|
217
|
-
value = 2;
|
|
218
|
-
for (i = 0; i < context_numBits; i++) {
|
|
219
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
220
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
221
|
-
context_data_position = 0;
|
|
222
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
223
|
-
context_data_val = 0;
|
|
224
|
-
} else {
|
|
225
|
-
context_data_position++;
|
|
226
|
-
}
|
|
227
|
-
value = value >> 1;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Flush the last char
|
|
231
|
-
while (true) {
|
|
232
|
-
context_data_val = context_data_val << 1;
|
|
233
|
-
if (context_data_position === bitsPerChar - 1) {
|
|
234
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
235
|
-
break;
|
|
236
|
-
} else context_data_position++;
|
|
237
|
-
}
|
|
238
|
-
return context_data.join('');
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
compressToUTF16 = (input) => {
|
|
243
|
-
const self = this;
|
|
244
|
-
if (input === null) return '';
|
|
245
|
-
return (
|
|
246
|
-
this._compress(input, 15, function (a) {
|
|
247
|
-
return self.f(a + 32);
|
|
248
|
-
}) + ' '
|
|
249
|
-
);
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export default { name: 'gioCompress', method: GioCompress };
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 名称:无埋点插件
|
|
3
|
-
* 用途:用于提供无埋点的事件构建方法。
|
|
4
|
-
*/
|
|
5
|
-
import { ID_REG, SWAN_XID_REG, TARO_XID_REG } from '@@/constants/regex';
|
|
6
|
-
import { EventTarget } from '@@/types/eventHooks';
|
|
7
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
8
|
-
import { consoleText, getExtraData, isTaro3, niceTry } from '@@/utils/tools';
|
|
9
|
-
import EMIT_MSG from '@@/constants/emitMsg';
|
|
10
|
-
import { isEmpty } from '@@/utils/glodash';
|
|
11
|
-
import qs from 'querystringify';
|
|
12
|
-
|
|
13
|
-
let ut;
|
|
14
|
-
class GioEventAutoTracking {
|
|
15
|
-
public pluginVersion: string;
|
|
16
|
-
private prevEvent: any;
|
|
17
|
-
public circleServerUrl: string;
|
|
18
|
-
public circleOpen = false;
|
|
19
|
-
constructor(public growingIO: GrowingIOType) {
|
|
20
|
-
this.pluginVersion = '__PLUGIN_VERSION__';
|
|
21
|
-
ut = this.growingIO.utils;
|
|
22
|
-
this.prevEvent = {};
|
|
23
|
-
this.listenForLunchEvent();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
main = (e: EventTarget, eventName: string) => {
|
|
27
|
-
const {
|
|
28
|
-
vdsConfig,
|
|
29
|
-
platformConfig,
|
|
30
|
-
plugins,
|
|
31
|
-
emitter,
|
|
32
|
-
trackingId
|
|
33
|
-
}: GrowingIOType = this.growingIO;
|
|
34
|
-
if (
|
|
35
|
-
// 无埋点事件拦截
|
|
36
|
-
!vdsConfig.autotrack ||
|
|
37
|
-
// 无事件名称拦截
|
|
38
|
-
!eventName ||
|
|
39
|
-
// 标记忽略的节点拦截
|
|
40
|
-
ut.get(e, 'currentTarget.dataset.growingIgnore') ||
|
|
41
|
-
ut.get(e, 'target.dataset.growingIgnore') ||
|
|
42
|
-
// 没有标记强制采集且是自动播放的组件(例如轮播、视频播放)事件拦截
|
|
43
|
-
(!ut.get(e, 'target.dataset.growingTrack') &&
|
|
44
|
-
ut.get(e, 'detail.source') === 'autoplay') ||
|
|
45
|
-
// 防止重写页面后可能出现重复的事件
|
|
46
|
-
(e.type === this.prevEvent?.type &&
|
|
47
|
-
// uniapp中后产生事件的时间戳可能比前序的小导致相减为负值,所以要取绝对值保证两个事件不是重复触发即可。事件重复触发是taro才会出现的
|
|
48
|
-
Math.abs(Number(e.timeStamp) - Number(this.prevEvent?.timeStamp)) < 10)
|
|
49
|
-
) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// taro3多余事件过滤
|
|
53
|
-
if (vdsConfig.taro && [('#eh', 'eh')].includes(eventName)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
this.prevEvent = e;
|
|
57
|
-
// uniapp
|
|
58
|
-
if (vdsConfig.uniVue) {
|
|
59
|
-
eventName = plugins?.gioUniAppAdapter.getHandlerName(eventName, e);
|
|
60
|
-
}
|
|
61
|
-
// 事件逻辑
|
|
62
|
-
if (vdsConfig.debug) {
|
|
63
|
-
console.log('Action:', e.type, Date.now());
|
|
64
|
-
}
|
|
65
|
-
// 向其他插件广播事件
|
|
66
|
-
emitter.emit(EMIT_MSG.ON_COMPOSE_BEFORE, {
|
|
67
|
-
event: eventName,
|
|
68
|
-
params: e ?? {}
|
|
69
|
-
});
|
|
70
|
-
const actionListeners = platformConfig.listeners.actions;
|
|
71
|
-
if (actionListeners.click.includes(e.type)) {
|
|
72
|
-
this.buildClickEvent(trackingId, e, eventName);
|
|
73
|
-
} else if (actionListeners.change.includes(e.type)) {
|
|
74
|
-
this.buildChangeEvent(trackingId, e, eventName);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// 获取触发节点xpath信息
|
|
79
|
-
getNodeXpath = (e: EventTarget, eventName: string) => {
|
|
80
|
-
const { gioPlatform, vdsConfig } = this.growingIO;
|
|
81
|
-
const target = e.currentTarget || e.target;
|
|
82
|
-
let id = target.id;
|
|
83
|
-
if (
|
|
84
|
-
!id ||
|
|
85
|
-
(gioPlatform === 'swan' && SWAN_XID_REG.test(id)) ||
|
|
86
|
-
(isTaro3(vdsConfig.taro) && TARO_XID_REG.test(id))
|
|
87
|
-
) {
|
|
88
|
-
id = '';
|
|
89
|
-
}
|
|
90
|
-
return `${id}#${eventName}`;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// 构建点击事件
|
|
94
|
-
buildClickEvent = (trackingId: string, e: EventTarget, eventName: string) => {
|
|
95
|
-
const xpath = this.getNodeXpath(e, eventName);
|
|
96
|
-
if (xpath) {
|
|
97
|
-
const {
|
|
98
|
-
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
99
|
-
} = this.growingIO;
|
|
100
|
-
const target = e.currentTarget || e.target;
|
|
101
|
-
let idx;
|
|
102
|
-
if (ut.has(target?.dataset, 'index') && target?.dataset?.index !== '') {
|
|
103
|
-
const index: any = ut.toString(target.dataset.index);
|
|
104
|
-
if (ID_REG.test(index) && index - 0 > 0 && index - 0 < 2147483647) {
|
|
105
|
-
idx = +index;
|
|
106
|
-
} else {
|
|
107
|
-
consoleText(
|
|
108
|
-
`${target.dataset.index},index标记应为 大于 0 且小于 2147483647 的整数!`,
|
|
109
|
-
'warn'
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const event = {
|
|
114
|
-
eventType: 'VIEW_CLICK',
|
|
115
|
-
element: [
|
|
116
|
-
{
|
|
117
|
-
xpath,
|
|
118
|
-
index: idx,
|
|
119
|
-
textValue: target?.dataset?.title,
|
|
120
|
-
hyperlink: target?.dataset?.src
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
...eventContextBuilder(trackingId)
|
|
124
|
-
};
|
|
125
|
-
// 合并页面属性
|
|
126
|
-
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
127
|
-
trackingId,
|
|
128
|
-
event
|
|
129
|
-
);
|
|
130
|
-
eventInterceptor(event);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// 构建tab菜单点击事件
|
|
135
|
-
buildTabClickEvent = (trackingId: string, tabItem: any) => {
|
|
136
|
-
const {
|
|
137
|
-
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
138
|
-
} = this.growingIO;
|
|
139
|
-
const event = {
|
|
140
|
-
eventType: 'VIEW_CLICK',
|
|
141
|
-
element: [
|
|
142
|
-
{
|
|
143
|
-
xpath: '#onTabItemTap',
|
|
144
|
-
textValue: tabItem.text,
|
|
145
|
-
index: tabItem.index + 1,
|
|
146
|
-
hyperlink: ut.toString(tabItem.pagePath)
|
|
147
|
-
}
|
|
148
|
-
],
|
|
149
|
-
...eventContextBuilder(trackingId)
|
|
150
|
-
};
|
|
151
|
-
// 合并页面属性
|
|
152
|
-
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
153
|
-
trackingId,
|
|
154
|
-
event
|
|
155
|
-
);
|
|
156
|
-
eventInterceptor(event);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// 构建表单变化事件
|
|
160
|
-
buildChangeEvent = (
|
|
161
|
-
trackingId: string,
|
|
162
|
-
e: EventTarget,
|
|
163
|
-
eventName: string
|
|
164
|
-
) => {
|
|
165
|
-
const xpath = this.getNodeXpath(e, eventName);
|
|
166
|
-
if (xpath) {
|
|
167
|
-
const {
|
|
168
|
-
dataStore: { eventContextBuilder, eventInterceptor, eventHooks }
|
|
169
|
-
} = this.growingIO;
|
|
170
|
-
const target = e.currentTarget || e.target;
|
|
171
|
-
const event = {
|
|
172
|
-
eventType: 'VIEW_CHANGE',
|
|
173
|
-
element: { xpath },
|
|
174
|
-
...eventContextBuilder(trackingId)
|
|
175
|
-
};
|
|
176
|
-
const ev = ut.get(e, 'detail.value') || ut.get(e, 'target.attr.value');
|
|
177
|
-
if (target?.dataset?.growingTrack || target?.dataset?.growingtrack) {
|
|
178
|
-
if (!ut.isNil(ev)) {
|
|
179
|
-
event.element.textValue = ut.toString(ev);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
event.element = [event.element];
|
|
183
|
-
// 合并页面属性
|
|
184
|
-
event.attributes = eventHooks.currentPage.eventSetPageProps(
|
|
185
|
-
trackingId,
|
|
186
|
-
event
|
|
187
|
-
);
|
|
188
|
-
eventInterceptor(event);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// --------------------- 以下内容是对新版小程序圈选的支持 ---------------------
|
|
193
|
-
|
|
194
|
-
// 监听小程序的onLunch事件
|
|
195
|
-
listenForLunchEvent = () => {
|
|
196
|
-
const { emitter } = this.growingIO;
|
|
197
|
-
emitter.on(EMIT_MSG.MINIP_LIFECYCLE, ({ event, params }) => {
|
|
198
|
-
if (['App onLaunch', 'App onShow'].includes(event)) {
|
|
199
|
-
this.circleInit(params);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// 抖音小程序获取圈选地址
|
|
205
|
-
getCircleUrlByTT = ({ query }: any) => {
|
|
206
|
-
if (query.q && query.url) {
|
|
207
|
-
const urlFromQ = niceTry(
|
|
208
|
-
() => JSON.parse(query.q)?.gdpCircleRoomCollectUrl
|
|
209
|
-
);
|
|
210
|
-
if (urlFromQ) {
|
|
211
|
-
return urlFromQ;
|
|
212
|
-
} else {
|
|
213
|
-
return (
|
|
214
|
-
niceTry(
|
|
215
|
-
() => qs.parse(query.url.split('?')[1])?.gdpCircleRoomCollectUrl
|
|
216
|
-
) ?? ''
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// 初始化圈选
|
|
223
|
-
circleInit = (params: any) => {
|
|
224
|
-
const { emitter } = this.growingIO;
|
|
225
|
-
const extraData = getExtraData(
|
|
226
|
-
params.referrerInfo?.extraData || params.query || {}
|
|
227
|
-
);
|
|
228
|
-
// 额外参数中存在gdpCircleRoomCollectUrl,则表示是圈选的跳转,进入圈选状态
|
|
229
|
-
const gdpCircleRoomCollectUrl =
|
|
230
|
-
extraData?.gdpCircleRoomCollectUrl || this.getCircleUrlByTT(params);
|
|
231
|
-
if (gdpCircleRoomCollectUrl) {
|
|
232
|
-
// 圈选初始化
|
|
233
|
-
if (this.circleServerUrl !== gdpCircleRoomCollectUrl) {
|
|
234
|
-
this.circleServerUrl = gdpCircleRoomCollectUrl;
|
|
235
|
-
// 提前移除一次事件发送监听,防止重复监听
|
|
236
|
-
emitter.off(EMIT_MSG.ON_SEND_AFTER, this.collectorSendFn);
|
|
237
|
-
// 添加事件发送监听,用于发送圈选事件
|
|
238
|
-
emitter.on(EMIT_MSG.ON_SEND_AFTER, this.collectorSendFn);
|
|
239
|
-
this.showPromptModal('enter');
|
|
240
|
-
}
|
|
241
|
-
this.circleOpen = true;
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// 数据采集发送监听回调
|
|
246
|
-
collectorSendFn = ({ requestData, trackingId }) => {
|
|
247
|
-
const { uploader } = this.growingIO;
|
|
248
|
-
if (this.circleOpen) {
|
|
249
|
-
// 过滤仅主实例的非CUSTOM事件可以圈选
|
|
250
|
-
const filteredEvents = requestData.filter(
|
|
251
|
-
(e) =>
|
|
252
|
-
e.eventType !== 'CUSTOM' && trackingId === this.growingIO.trackingId
|
|
253
|
-
);
|
|
254
|
-
if (!isEmpty(filteredEvents)) {
|
|
255
|
-
// 同时请求数在3个以下直接发起请求
|
|
256
|
-
if (uploader.requestingNum < uploader.requestLimit) {
|
|
257
|
-
this.circleRequest(filteredEvents);
|
|
258
|
-
} else {
|
|
259
|
-
// 同时有3个请求在发送时,设轮询延时直到请求数在3个以下
|
|
260
|
-
let t = setInterval(() => {
|
|
261
|
-
if (uploader.requestingNum < uploader.requestLimit) {
|
|
262
|
-
this.circleRequest(filteredEvents);
|
|
263
|
-
clearInterval(t);
|
|
264
|
-
t = undefined;
|
|
265
|
-
}
|
|
266
|
-
}, 500);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
// 圈选结束
|
|
273
|
-
circleClose = () => {
|
|
274
|
-
this.circleOpen = false;
|
|
275
|
-
this.circleServerUrl = '';
|
|
276
|
-
this.growingIO.emitter.off(EMIT_MSG.ON_SEND_AFTER, this.collectorSendFn);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
// 展示圈选提示
|
|
280
|
-
showPromptModal = (type: 'enter' | 'error', msg?: string) => {
|
|
281
|
-
this.growingIO.minipInstance.minip.showModal({
|
|
282
|
-
title: 'GrowingIO提示',
|
|
283
|
-
content: type === 'error' ? msg : '您已进入圈选模式',
|
|
284
|
-
showCancel: false
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
// 发起圈选请求
|
|
289
|
-
circleRequest = (requestData: any) => {
|
|
290
|
-
const { minipInstance } = this.growingIO;
|
|
291
|
-
minipInstance.request({
|
|
292
|
-
url: this.circleServerUrl,
|
|
293
|
-
header: { 'content-type': 'application/json;charset=UTF-8' },
|
|
294
|
-
method: 'POST',
|
|
295
|
-
data: requestData,
|
|
296
|
-
complete: ({ statusCode, data, errMsg }: any) => {
|
|
297
|
-
if (![200, 204].includes(statusCode) || !data?.success) {
|
|
298
|
-
this.showPromptModal(
|
|
299
|
-
'error',
|
|
300
|
-
data?.message || data || errMsg || '圈选请求失败,请重试!'
|
|
301
|
-
);
|
|
302
|
-
this.circleClose();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
console.log(requestData, '----->circleRequest');
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export default { name: 'gioEventAutoTracking', method: GioEventAutoTracking };
|