gio-miniprogram-sdk 4.1.0 → 4.2.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 -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.plugins.config.js +5 -0
- package/src/adapters/gioTaobaoAdapter.ts +2 -0
- package/src/adapters/gioTaroAdapter.ts +2 -0
- package/src/adapters/gioUniAppAdapter.ts +2 -0
- package/src/constants/config.ts +1 -0
- package/src/core/dataStore/eventContextBuilder.ts +28 -10
- package/src/core/dataStore/eventHooks/index.ts +6 -1
- package/src/core/dataStore/eventHooks/minipPage.ts +39 -2
- package/src/core/dataStore/eventHooks/pageEffects.ts +2 -13
- package/src/core/dataStore/index.ts +24 -20
- package/src/core/growingIO.ts +89 -33
- 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 +3 -0
- package/src/types/growingIO.ts +52 -33
- package/src/utils/tools.ts +4 -0
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
consoleText,
|
|
26
26
|
getGlobal,
|
|
27
27
|
guid,
|
|
28
|
+
limitObject,
|
|
28
29
|
niceTry
|
|
29
30
|
} from '@@/utils/tools';
|
|
30
31
|
import {
|
|
@@ -548,16 +549,17 @@ class DataStore implements DataStoreType {
|
|
|
548
549
|
const event = {
|
|
549
550
|
eventType: 'CUSTOM',
|
|
550
551
|
eventName: '$mp_on_share',
|
|
551
|
-
attributes: {
|
|
552
|
-
$from: originResult.from,
|
|
553
|
-
$target: originResult?.target?.id,
|
|
554
|
-
$share_title: updateResult?.title,
|
|
555
|
-
$share_path: head(uri),
|
|
556
|
-
$share_query: uri[1],
|
|
557
|
-
...updateResult?.attributes
|
|
558
|
-
},
|
|
559
552
|
...eventContextBuilder(trackingId)
|
|
560
553
|
};
|
|
554
|
+
event.attributes = limitObject({
|
|
555
|
+
...(event.attributes ?? {}),
|
|
556
|
+
$from: originResult.from,
|
|
557
|
+
$target: originResult?.target?.id,
|
|
558
|
+
$share_title: updateResult?.title,
|
|
559
|
+
$share_path: head(uri),
|
|
560
|
+
$share_query: uri[1],
|
|
561
|
+
...updateResult?.attributes
|
|
562
|
+
});
|
|
561
563
|
eventInterceptor(event);
|
|
562
564
|
};
|
|
563
565
|
|
|
@@ -577,15 +579,16 @@ class DataStore implements DataStoreType {
|
|
|
577
579
|
const event = {
|
|
578
580
|
eventType: 'CUSTOM',
|
|
579
581
|
eventName: '$mp_share_timeline',
|
|
580
|
-
attributes: {
|
|
581
|
-
$target: originResult?.target?.id,
|
|
582
|
-
$share_title: updateResult?.title,
|
|
583
|
-
$share_path: head(uri),
|
|
584
|
-
$share_query: uri[1],
|
|
585
|
-
...updateResult?.attributes
|
|
586
|
-
},
|
|
587
582
|
...eventContextBuilder(trackingId)
|
|
588
583
|
};
|
|
584
|
+
event.attributes = limitObject({
|
|
585
|
+
...(event.attributes ?? {}),
|
|
586
|
+
$target: originResult?.target?.id,
|
|
587
|
+
$share_title: updateResult?.title,
|
|
588
|
+
$share_path: head(uri),
|
|
589
|
+
$share_query: uri[1],
|
|
590
|
+
...updateResult?.attributes
|
|
591
|
+
});
|
|
589
592
|
eventInterceptor(event);
|
|
590
593
|
};
|
|
591
594
|
|
|
@@ -605,13 +608,14 @@ class DataStore implements DataStoreType {
|
|
|
605
608
|
const event = {
|
|
606
609
|
eventType: 'CUSTOM',
|
|
607
610
|
eventName: '$mp_add_favorites',
|
|
608
|
-
attributes: {
|
|
609
|
-
$share_title: updateResult?.title,
|
|
610
|
-
$share_path: head(uri),
|
|
611
|
-
$share_query: uri[1]
|
|
612
|
-
},
|
|
613
611
|
...eventContextBuilder(trackingId)
|
|
614
612
|
};
|
|
613
|
+
event.attributes = limitObject({
|
|
614
|
+
...(event.attributes ?? {}),
|
|
615
|
+
$share_title: updateResult?.title,
|
|
616
|
+
$share_path: head(uri),
|
|
617
|
+
$share_query: uri[1]
|
|
618
|
+
});
|
|
615
619
|
eventInterceptor(event);
|
|
616
620
|
};
|
|
617
621
|
|
package/src/core/growingIO.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
forEach,
|
|
2
3
|
isArray,
|
|
3
4
|
isEmpty,
|
|
4
5
|
isFunction,
|
|
@@ -205,15 +206,58 @@ class GrowingIO implements GrowingIOType {
|
|
|
205
206
|
|
|
206
207
|
// 设置页面属性
|
|
207
208
|
setPageAttributes = (trackingId: string, properties: any) => {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
currentPage.pageProps[trackingId]
|
|
209
|
+
if (isObject(properties) && !isEmpty(properties)) {
|
|
210
|
+
const { currentPage } = this.dataStore.eventHooks;
|
|
211
|
+
if (isEmpty(currentPage.pageProps[trackingId])) {
|
|
212
|
+
currentPage.pageProps[trackingId] = {};
|
|
213
|
+
}
|
|
214
|
+
if (isEmpty(currentPage.pageProps[trackingId][currentPage.path])) {
|
|
215
|
+
currentPage.pageProps[trackingId][currentPage.path] = {};
|
|
216
|
+
}
|
|
217
|
+
// 结果合并,动态属性不作处理
|
|
218
|
+
if (!isEmpty(properties)) {
|
|
219
|
+
forEach(properties, (v, k) => {
|
|
220
|
+
if (
|
|
221
|
+
!isFunction(
|
|
222
|
+
currentPage.pageProps[trackingId][currentPage.path][k]
|
|
223
|
+
) ||
|
|
224
|
+
isFunction(v)
|
|
225
|
+
) {
|
|
226
|
+
currentPage.pageProps[trackingId][currentPage.path][k] = v;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
} else {
|
|
232
|
+
callError('setPageAttributes');
|
|
233
|
+
return false;
|
|
211
234
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// 清空已设置的页面属性
|
|
238
|
+
clearPageAttributes = (
|
|
239
|
+
trackingId: string,
|
|
240
|
+
properties: string[] | undefined
|
|
241
|
+
) => {
|
|
242
|
+
try {
|
|
243
|
+
if (
|
|
244
|
+
!isEmpty(this.dataStore.eventHooks.currentPage.pageProps[trackingId])
|
|
245
|
+
) {
|
|
246
|
+
const { currentPage } = this.dataStore.eventHooks;
|
|
247
|
+
if (isArray(properties) && !isEmpty(properties)) {
|
|
248
|
+
properties.forEach((propName: string) => {
|
|
249
|
+
unset(
|
|
250
|
+
currentPage.pageProps[trackingId][currentPage.path],
|
|
251
|
+
propName
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
currentPage.pageProps[trackingId][currentPage.path] = {};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} catch (error) {
|
|
259
|
+
callError('clearPageAttributes');
|
|
260
|
+
return false;
|
|
217
261
|
}
|
|
218
262
|
};
|
|
219
263
|
|
|
@@ -261,14 +305,17 @@ class GrowingIO implements GrowingIOType {
|
|
|
261
305
|
|
|
262
306
|
// 发送用户属性
|
|
263
307
|
setUserAttributes = (trackingId: string, userAttributes: any) => {
|
|
264
|
-
if (
|
|
308
|
+
if (isObject(userAttributes) && !isEmpty(userAttributes)) {
|
|
265
309
|
const { eventContextBuilder, eventInterceptor, lastVisitEvent } =
|
|
266
310
|
this.dataStore;
|
|
267
311
|
const event = {
|
|
268
312
|
eventType: 'LOGIN_USER_ATTRIBUTES',
|
|
269
|
-
attributes: limitObject(userAttributes),
|
|
270
313
|
...eventContextBuilder(trackingId)
|
|
271
314
|
};
|
|
315
|
+
event.attributes = limitObject({
|
|
316
|
+
...(event.attributes ?? {}),
|
|
317
|
+
...getDynamicAttributes(userAttributes)
|
|
318
|
+
});
|
|
272
319
|
// 该方法很可能被放在在app的onShow中的wx.login异步回调中,
|
|
273
320
|
// 此时页面的path和query可能还没取到,就拿visit事件的path和query补上
|
|
274
321
|
if (!event.path) {
|
|
@@ -321,13 +368,20 @@ class GrowingIO implements GrowingIOType {
|
|
|
321
368
|
this.userStore.setUserKey(trackingId, undefined);
|
|
322
369
|
};
|
|
323
370
|
|
|
324
|
-
//
|
|
371
|
+
// 设置全局通用属性(即每个事件都会带上的属性值)
|
|
325
372
|
setGeneralProps = (trackingId: string, properties: any) => {
|
|
326
|
-
if (!isEmpty(properties)) {
|
|
327
|
-
this.dataStore.generalProps[trackingId]
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
373
|
+
if (isObject(properties) && !isEmpty(properties)) {
|
|
374
|
+
if (isEmpty(this.dataStore.generalProps[trackingId])) {
|
|
375
|
+
this.dataStore.generalProps[trackingId] = {};
|
|
376
|
+
}
|
|
377
|
+
forEach(properties, (v, k) => {
|
|
378
|
+
if (
|
|
379
|
+
!isFunction(this.dataStore.generalProps[trackingId][k]) ||
|
|
380
|
+
isFunction(v)
|
|
381
|
+
) {
|
|
382
|
+
this.dataStore.generalProps[trackingId][k] = v;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
331
385
|
return true;
|
|
332
386
|
} else {
|
|
333
387
|
callError('setGeneralProps');
|
|
@@ -335,14 +389,13 @@ class GrowingIO implements GrowingIOType {
|
|
|
335
389
|
}
|
|
336
390
|
};
|
|
337
391
|
|
|
338
|
-
//
|
|
392
|
+
// 清空已设置的全局通用属性
|
|
339
393
|
clearGeneralProps = (
|
|
340
394
|
trackingId: string,
|
|
341
395
|
properties: string[] | undefined
|
|
342
396
|
) => {
|
|
343
397
|
try {
|
|
344
398
|
if (!isEmpty(this.dataStore.generalProps[trackingId])) {
|
|
345
|
-
// 获取目标tracker的引用
|
|
346
399
|
if (isArray(properties) && !isEmpty(properties)) {
|
|
347
400
|
properties.forEach((propName: string) => {
|
|
348
401
|
unset(this.dataStore.generalProps[trackingId], propName);
|
|
@@ -352,7 +405,7 @@ class GrowingIO implements GrowingIOType {
|
|
|
352
405
|
}
|
|
353
406
|
}
|
|
354
407
|
} catch (error) {
|
|
355
|
-
callError('
|
|
408
|
+
callError('clearGeneralProps');
|
|
356
409
|
return false;
|
|
357
410
|
}
|
|
358
411
|
};
|
|
@@ -360,22 +413,22 @@ class GrowingIO implements GrowingIOType {
|
|
|
360
413
|
// 自定义埋点事件
|
|
361
414
|
track = (
|
|
362
415
|
trackingId: string,
|
|
363
|
-
|
|
416
|
+
eventName: string,
|
|
364
417
|
properties: { [key: string]: string | string[] }
|
|
365
418
|
) => {
|
|
366
|
-
eventNameValidate(
|
|
367
|
-
const { eventContextBuilder, eventInterceptor
|
|
368
|
-
this.dataStore;
|
|
369
|
-
const mergedProperties = {
|
|
370
|
-
...(generalProps[trackingId] ?? {}),
|
|
371
|
-
...(isObject(properties) && !isEmpty(properties) ? properties : {})
|
|
372
|
-
};
|
|
419
|
+
eventNameValidate(eventName, () => {
|
|
420
|
+
const { eventContextBuilder, eventInterceptor } = this.dataStore;
|
|
373
421
|
const event = {
|
|
374
422
|
eventType: 'CUSTOM',
|
|
375
|
-
eventName
|
|
376
|
-
attributes: limitObject(getDynamicAttributes(mergedProperties)),
|
|
423
|
+
eventName,
|
|
377
424
|
...eventContextBuilder(trackingId)
|
|
378
425
|
};
|
|
426
|
+
event.attributes = limitObject({
|
|
427
|
+
...(event.attributes ?? {}),
|
|
428
|
+
...getDynamicAttributes({
|
|
429
|
+
...(isObject(properties) && !isEmpty(properties) ? properties : {})
|
|
430
|
+
})
|
|
431
|
+
});
|
|
379
432
|
// 埋点事件要保留'&&sendTo'字段用于多实例复制发送
|
|
380
433
|
if (
|
|
381
434
|
this.plugins.gioMultipleInstances &&
|
|
@@ -453,12 +506,15 @@ class GrowingIO implements GrowingIOType {
|
|
|
453
506
|
const event = {
|
|
454
507
|
eventType: 'CUSTOM',
|
|
455
508
|
eventName: timer.eventName,
|
|
456
|
-
attributes: limitObject({
|
|
457
|
-
...properties,
|
|
458
|
-
event_duration: timer.leng > maxEnd ? 0 : timer.leng / 1000
|
|
459
|
-
}),
|
|
460
509
|
...eventContextBuilder(trackingId)
|
|
461
510
|
};
|
|
511
|
+
event.attributes = limitObject({
|
|
512
|
+
...(event.attributes ?? {}),
|
|
513
|
+
...getDynamicAttributes({
|
|
514
|
+
...(isObject(properties) && !isEmpty(properties) ? properties : {}),
|
|
515
|
+
event_duration: timer.leng > maxEnd ? 0 : timer.leng / 1000
|
|
516
|
+
})
|
|
517
|
+
});
|
|
462
518
|
// 埋点事件要保留'&&sendTo'字段用于多实例复制发送
|
|
463
519
|
if (
|
|
464
520
|
this.plugins.gioMultipleInstances &&
|
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'
|
|
@@ -89,6 +91,7 @@ export interface MinipPageType {
|
|
|
89
91
|
updateAppMessageResult: (result: PageShareResult) => PageShareResult;
|
|
90
92
|
updateTimelineResult: (result: PageShareResult) => PageShareResult;
|
|
91
93
|
updateAddFavoritesResult: (result: PageShareResult) => PageShareResult;
|
|
94
|
+
eventSetPageProps: (trackingId: string, event: EVENT) => any;
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
export interface EventHooksType {
|
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,
|
|
@@ -310,6 +312,8 @@ export const limitObject = (o: any) => {
|
|
|
310
312
|
} else if (isArray(v)) {
|
|
311
313
|
ob[key] = compact(v.slice(0, 100), true);
|
|
312
314
|
ob[key] = ob[key].join('||').slice(0, 1000);
|
|
315
|
+
} else if (isDate(v)) {
|
|
316
|
+
ob[key] = formatDate(v);
|
|
313
317
|
} else {
|
|
314
318
|
ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
|
|
315
319
|
}
|