gio-miniprogram-sdk 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/gioImpressionTracking.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/src/constants/config.ts +2 -2
- package/src/constants/regex.ts +15 -0
- package/src/core/dataStore/index.ts +8 -1
- package/src/core/growingIO.ts +1 -2
- package/src/core/uploader.ts +2 -7
- package/src/pluginsOut/frameworks/gioTaobaoAdapter.ts +0 -1
- package/src/pluginsOut/frameworks/gioTaroAdapter.ts +291 -190
- package/src/pluginsOut/ordinary/gioImpressionTracking.ts +56 -21
- package/src/types/base.ts +2 -0
- package/src/types/eventHooks.ts +3 -3
- package/src/types/uploader.ts +0 -2
- package/src/pluginsOut/README.md +0 -50
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* 用途:用于提供半自动浏览埋点事件的自动注册、参数检验构建和创建事件方法。
|
|
4
4
|
*/
|
|
5
5
|
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
|
-
import { isEqualArray } from '@@/utils/glodash';
|
|
7
6
|
import { hashCode } from '@@/utils/tools';
|
|
7
|
+
import { isEmpty, isEqualArray, toString } from '@@/utils/glodash';
|
|
8
8
|
|
|
9
9
|
let ut;
|
|
10
10
|
class GioImpressionTracking {
|
|
@@ -68,13 +68,47 @@ class GioImpressionTracking {
|
|
|
68
68
|
return isEqualArray(controlGroup, comparisonGroup);
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
// 获取nodeId
|
|
72
|
+
getNodeId = (collectTarget: any) => {
|
|
73
|
+
const { gioPlatform } = this.growingIO;
|
|
74
|
+
switch (gioPlatform) {
|
|
75
|
+
case 'wx':
|
|
76
|
+
case 'qq':
|
|
77
|
+
case 'ks':
|
|
78
|
+
case 'jd':
|
|
79
|
+
return collectTarget.__wxExparserNodeId__; // wx page/component
|
|
80
|
+
case 'my':
|
|
81
|
+
return collectTarget.$page
|
|
82
|
+
? `${collectTarget.$page.$id}-${collectTarget.$id}` //my component
|
|
83
|
+
: collectTarget.$id; // my page
|
|
84
|
+
case 'swan':
|
|
85
|
+
return collectTarget.route
|
|
86
|
+
? toString(hashCode(collectTarget.route)) // swan page
|
|
87
|
+
: collectTarget.nodeId; // swan component
|
|
88
|
+
case 'tt':
|
|
89
|
+
return collectTarget.route
|
|
90
|
+
? toString(hashCode(collectTarget.route)) // swan page
|
|
91
|
+
: collectTarget.__nodeId__; // swan component
|
|
92
|
+
default:
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
71
97
|
// 获取到可监听节点后校验节点信息
|
|
72
98
|
rectobserve = (rect, collectTarget, optionKey) => {
|
|
73
|
-
const
|
|
99
|
+
const { gioPlatform } = this.growingIO;
|
|
100
|
+
if (
|
|
101
|
+
(gioPlatform === 'tt' && collectTarget.__nodeId__) ||
|
|
102
|
+
(gioPlatform === 'ks' && collectTarget.is)
|
|
103
|
+
) {
|
|
104
|
+
// 字节和快手小程序页面监听时可以拿到自定义组件一次性完成监听,所以组件的节点实例不再处理
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const nodeId = this.getNodeId(collectTarget);
|
|
74
108
|
const page = collectTarget.route
|
|
75
109
|
? collectTarget
|
|
76
110
|
: this.growingIO.minipInstance.getCurrentPage();
|
|
77
|
-
//
|
|
111
|
+
// 监听的目标页面和上一次的不一致,或者监听的组件或页面的监听已经被注销时,可以继续生成新的监听
|
|
78
112
|
let observerNeedNew = false;
|
|
79
113
|
if (page.route) {
|
|
80
114
|
const isEqualRects = this.isEqualRects(rect, page.route, nodeId);
|
|
@@ -109,15 +143,21 @@ class GioImpressionTracking {
|
|
|
109
143
|
?.createSelectorQuery()
|
|
110
144
|
.in(collectTarget);
|
|
111
145
|
if (['ks', 'qq'].includes(gioPlatform)) {
|
|
112
|
-
query
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
query
|
|
147
|
+
.selectAll('.growing_collect_imp')
|
|
148
|
+
.boundingClientRect(([rect = []]) => {
|
|
149
|
+
rect = ut.isArray(rect) ? rect : [rect];
|
|
150
|
+
if (!isEmpty(rect)) {
|
|
151
|
+
this.rectobserve(rect, collectTarget, optionKey);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
116
154
|
query.exec();
|
|
117
155
|
} else {
|
|
118
156
|
query.selectAll('.growing_collect_imp').boundingClientRect();
|
|
119
157
|
query.exec(([rect]) => {
|
|
120
|
-
|
|
158
|
+
if (!isEmpty(rect)) {
|
|
159
|
+
this.rectobserve(rect, collectTarget, optionKey);
|
|
160
|
+
}
|
|
121
161
|
});
|
|
122
162
|
}
|
|
123
163
|
};
|
|
@@ -136,8 +176,7 @@ class GioImpressionTracking {
|
|
|
136
176
|
) {
|
|
137
177
|
observerOption.dataset = true;
|
|
138
178
|
}
|
|
139
|
-
|
|
140
|
-
const nodeId = collectTarget.__wxExparserNodeId__;
|
|
179
|
+
const nodeId = this.getNodeId(collectTarget);
|
|
141
180
|
let page = collectTarget;
|
|
142
181
|
// uniapp是组件和页面一体,所以要分两次尝试监听;原生是组件和页面互相独立,按类型监听
|
|
143
182
|
// 自定义组件是不能直接在页面上被拿到,所以直接监听页面不会监听到自定义组件
|
|
@@ -148,7 +187,6 @@ class GioImpressionTracking {
|
|
|
148
187
|
) {
|
|
149
188
|
page = minipInstance.getCurrentPage();
|
|
150
189
|
}
|
|
151
|
-
|
|
152
190
|
if (!this.observerIds[page.route]) {
|
|
153
191
|
this.observerIds[page.route] = {};
|
|
154
192
|
}
|
|
@@ -158,13 +196,12 @@ class GioImpressionTracking {
|
|
|
158
196
|
originObserver.disconnect();
|
|
159
197
|
}
|
|
160
198
|
// 创建一个新的监听
|
|
161
|
-
let observer =
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
: collectTarget.createIntersectionObserver(observerOption);
|
|
199
|
+
let observer = ['swan', 'jd'].includes(gioPlatform)
|
|
200
|
+
? minipInstance.minip?.createIntersectionObserver(
|
|
201
|
+
collectTarget,
|
|
202
|
+
observerOption
|
|
203
|
+
)
|
|
204
|
+
: collectTarget.createIntersectionObserver(observerOption);
|
|
168
205
|
observer = observer.relativeToViewport();
|
|
169
206
|
// 不管原先是否创建过,直接覆盖(obeserverId会更新)
|
|
170
207
|
this.observerIds[page.route][nodeId] = observer;
|
|
@@ -193,7 +230,6 @@ class GioImpressionTracking {
|
|
|
193
230
|
}
|
|
194
231
|
}
|
|
195
232
|
if (dataProperties.eventId) {
|
|
196
|
-
// 要直接构建custom事件,不要去调用埋点插件的方法,万一插件没有加载就发不出去了
|
|
197
233
|
this.buildImpEvent(dataProperties);
|
|
198
234
|
} else {
|
|
199
235
|
ut.consoleText(
|
|
@@ -288,8 +324,7 @@ class GioImpressionTracking {
|
|
|
288
324
|
eventType: 'CUSTOM',
|
|
289
325
|
eventName: eventId,
|
|
290
326
|
attributes: properties,
|
|
291
|
-
...eventContextBuilder()
|
|
292
|
-
customEventType: 0
|
|
327
|
+
...eventContextBuilder()
|
|
293
328
|
};
|
|
294
329
|
eventInterceptor(event);
|
|
295
330
|
};
|
package/src/types/base.ts
CHANGED
package/src/types/eventHooks.ts
CHANGED
|
@@ -102,9 +102,9 @@ export interface EventHooksType {
|
|
|
102
102
|
originalPage: (any: any) => any;
|
|
103
103
|
originalComponent: (any: any) => any;
|
|
104
104
|
originalBehavior: (any: any) => any;
|
|
105
|
-
appEffects:
|
|
106
|
-
pageEffects:
|
|
107
|
-
actionEffects:
|
|
105
|
+
appEffects: any;
|
|
106
|
+
pageEffects: any;
|
|
107
|
+
actionEffects: any;
|
|
108
108
|
currentPage: MinipPageType;
|
|
109
109
|
// 判断是否为非构造函数的一个函数
|
|
110
110
|
isNormalFc: (key: string, method: any) => any;
|
package/src/types/uploader.ts
CHANGED
package/src/pluginsOut/README.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
## 目录说明
|
|
2
|
-
|
|
3
|
-
本目录下有多个文件夹,其中`ordinary`是主要的一些内置插件,`frameworks`是小程序开发框架的适配,其他文件夹为特殊场景适配。
|
|
4
|
-
|
|
5
|
-
## 插件名称命名规则
|
|
6
|
-
|
|
7
|
-
`gio`开头表明是gio的插件;
|
|
8
|
-
|
|
9
|
-
名称带`Adapter`表明是某个场景下的适配;
|
|
10
|
-
|
|
11
|
-
短横线加环境`-cdp`、`-saas`表明是cdp或者是saas专有的插件;不会被单独打包插件;
|
|
12
|
-
|
|
13
|
-
除`ordinary`目录下的插件打包会打在`dist/plugins`根目录下,`frameworks`不会被单独打包,其他带文件夹的插件会打包在保留文件夹路径且与`plugins`同级的目录下。
|
|
14
|
-
|
|
15
|
-
如果新增目录,发布时需要在jekins上修改配置添加路径。
|
|
16
|
-
|
|
17
|
-
## 开发插件
|
|
18
|
-
|
|
19
|
-
- 这里提供一个Demo供参考:
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
/**
|
|
23
|
-
* 名称:插件Demo
|
|
24
|
-
* 用途:用于提供编写插件的模板。
|
|
25
|
-
*/
|
|
26
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
27
|
-
|
|
28
|
-
class GioDemoPlugin {
|
|
29
|
-
constructor(public growingIO: GrowingIOType) {}
|
|
30
|
-
|
|
31
|
-
onComposeBefore(args) {
|
|
32
|
-
// console.log('onComposeBefore', args);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onComposeAfter(args) {
|
|
36
|
-
// console.log('onComposeAfter', args);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
onSendBefore(args) {
|
|
40
|
-
// console.log('onSendBefore', args);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
onSendAfter(args) {
|
|
44
|
-
// console.log('onSendAfter', args);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default { name: 'gioDemoPlugin', method: GioDemoPlugin };
|
|
49
|
-
|
|
50
|
-
```
|