visual-buried-point-platform-h5 1.3.6 → 2.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/README.md CHANGED
@@ -2,14 +2,16 @@
2
2
  # 可视化埋点JS SDK接入指南
3
3
 
4
4
  ### SDK更新日志
5
- - 1.2.0 新增页面浏览时长统计功能、优化埋点精度、统计事件绑定用户标识等;
6
- - 1.2.7 新增可自定义事件埋点接口、增加元素名称、访问途径等采集;
7
- - 1.2.8 新增PV/UV统计、元数据配置,访问链路追踪等;
8
- - 1.3.2 新的数据结构和修改PV/UV流量上报方式;
9
- - 1.3.3 自定义埋点数据结构增加page对象和事件标识符eventCode;
10
- - 1.3.4 调整SDK上报接口入参、删除appkey参数配置;
11
- - 1.3.5 上报数据结构增加url;
12
- - 1.3.6 调整上报数据结构circulation和duration计算规则;
5
+ - v1.2.0 新增页面浏览时长统计功能、优化埋点精度、统计事件绑定用户标识等;
6
+ - v1.2.7 新增可自定义事件埋点接口、增加元素名称、访问途径等采集;
7
+ - v1.2.8 新增PV/UV统计、元数据配置,访问链路追踪等;
8
+ - v1.3.2 新的数据结构和修改PV/UV流量上报方式;
9
+ - v1.3.3 自定义埋点数据结构增加page对象和事件标识符eventCode;
10
+ - v1.3.4 调整SDK上报接口入参、删除appkey参数配置;
11
+ - v1.3.5 上报数据结构增加url;
12
+ - v1.3.6 调整上报数据结构circulation和duration计算规则;
13
+ - v2.0.0 调整SDK内部PVUV采集模式,分原有start方法采集及自动采集,支持获取埋点sdk内的跟踪ID;【详见1,3,4,7,10】
14
+
13
15
 
14
16
  ### 1.基本原理
15
17
 
@@ -41,112 +43,59 @@ Web SDK 的原理,主要是通过原生 JavaScript 代码,去监控页面的
41
43
 
42
44
  <!-- // TODO:lodash -->
43
45
 
44
- ## 用法
46
+ ## 1.用法
45
47
 
46
- token在可视化埋点后台申请
48
+ ### 一、 npm | yarn、并添加配置文件 buried-point.ts ,或者直接导入 buried-point-h5.js 包
47
49
 
48
- ### 方法一 npm | yarn、并添加配置文件 buried-point.ts
49
50
  ```javascript
50
- npm i visual-buried-point-platform-h5 -S --registry=http://verdaccio.gogdev.cn/
51
-
52
51
  yarn add visual-buried-point-platform-h5 --registry=http://verdaccio.gogdev.cn/
53
- ```
54
52
 
55
- ### 方法二 、导入 buried-point-h5.js 包,并添加配置文件 buried-point.ts【推荐】
56
- ```js
57
- import * as BuriedPointH5 from 'visual-buried-point-platform-h5';
58
- ts declare module 'visual-buried-point-platform-h5';
59
-
60
- export const buriedPoint = new BuriedPointH5({
61
- //配置
62
- token: 'xxx',
63
- environment: 'test',
64
- reportUrl: ''
65
- ...
66
- ...
67
- })
68
-
69
- // uniapp兼容写法
70
- import * as BuriedPointH5 from 'visual-buried-point-platform-h5';
71
- const BP = BuriedPointH5.default || BuriedPointH5
72
- export const buriedPoint = new BP({
73
- //配置
74
- token: 'xxx',
75
- environment: 'test',
76
- reportUrl: ''
77
- ...
78
- ...
79
- })
53
+ npm i visual-buried-point-platform-h5 -S --registry=http://verdaccio.gogdev.cn/
80
54
  ```
81
55
 
82
- ## 添加buried-point.ts配置文件
56
+ ### 二 、添加buried-point.ts配置文件
83
57
 
84
58
  - 注:t_name、token、t_version 对应修改
85
59
 
86
- ```js
87
- // import * as BuriedPointH5 from 'visual-buried-point-platform-h5';
88
- // eslint-disable-next-line @typescript-eslint/no-var-requires
89
- const BuriedPointH5 = require("./buried-point-h5.js");
90
- export const BuriedPoint = new BuriedPointH5({
91
- /** 上报地址(可选) */
92
- reportUrl: 'http://localhost:8000',
60
+ ```javascript
61
+ // eslint-disable-next-line
62
+ // const BuriedPointH5 = require("./buried-point-h5.js");
63
+ import BuriedPointH5 from "visual-buried-point-platform-h5";
64
+ export const buriedPoint = new BuriedPointH5({
93
65
  /** 上报参数。需填入管理端生成的token 与 ·enableJavaScriptBridge·字段互斥 */
94
66
  token: '',
95
- /** appkey (可选)*/
96
- appkey: '';
67
+ // 页面载体环境
68
+ ecology: "",
69
+ /** domain */
70
+ domain: "",
97
71
  /** 业务板块 (可选)*/
98
72
  busSegment: '';
99
73
  /** 业务模块 (可选)*/
100
74
  module: '';
101
- // app版本
102
- appVersion: '1.0.0',
103
- // 环境 取值 `dev` `test` `prod`。当开启环境配置参数后上报地址随环境变化 可以不配置上报地址
104
- environment: 'dev',
105
- // 脚本延迟上报时间
106
- outtime: 3000,
75
+ // 环境 取值 `test` `prod`。当开启环境配置参数后上报地址随环境变化 可以不配置上报地址
76
+ environment: 'test',
107
77
  // 开启单页面?
108
78
  enableSPA: true,
109
- // 是否自动上报pv
110
- autoSendPv: true,
111
- // 是否上报页面性能数据
112
- isPage: true,
113
- // 是否上报ajax性能数据
114
- isAjax: true,
115
- // 是否上报页面资源数据
116
- isResource: true,
117
- // 是否上报错误信息
118
- isError: true,
119
- // 是否录屏
120
- isRecord: true,
121
- // 是否上报行为
122
- isBehavior: true,
123
- // 是否开启了CSS HASH值,(默认开启) [针对商品列表情况埋点,建议false]
79
+ // 是否开启了CSS HASH值,(默认开启) [针对有商品列表多的情况,建议false]
124
80
  isOpenCSSHash: true,
125
81
  // 业务线流量上报的应用 name
126
82
  t_name: '购物',
127
83
  // 业务线流量上报的当前应用 version
128
84
  t_version: 'v1.0.0',
129
- ignore: {
130
- ignoreErrors: [],
131
- ignoreUrls: [],
132
- ignoreApis: ['/api/v1/report/web', 'livereload.js?snipver=1', '/sockjs-node/info'],
133
- },
134
- behavior: {
135
- console: ['log', 'error'], // 取值可以是"debug", "info", "warn", "log", "error"
136
- click: true,
137
- },
138
- // 最长上报数据长度
139
- maxLength: 1000,
140
85
  // Web JS SDK 的 H5 页面,在嵌入到 App 后,H5 内的事件可以通过 App 进行发送 默认关闭
141
86
  // 当开启次字段配置 token字段失效 打通APP上报数据依据所在环境判断 必须配置 androidToken与iosToken字段
142
87
  enableJavaScriptBridge: false,
143
88
  // 打通H5与APP通信后,上报数据ID
144
89
  androidToken: null,
145
- iosToken: null
90
+ iosToken: null,
91
+ // 是否兼容已埋点方案,true兼容(业务方需调用start方法采集PV流量),false不兼容(SDK内部自动采集,但前提业务方需要预置参数)
92
+ isCompatible: true
93
+ // 需要单独采集的页面path,设置isCompatible为false使用
94
+ signTrackPathArray: ["/home", "/personal-auth"],
146
95
  });
147
96
  ```
148
97
 
149
- ## 初始化
98
+ ## 2.初始化【可省略】
150
99
 
151
100
  ```javascript
152
101
  // buried-point-h5.js和buried-point.ts放入utils文件夹中
@@ -154,24 +103,57 @@ export const BuriedPoint = new BuriedPointH5({
154
103
  import "./utils/buried-point";
155
104
  ```
156
105
 
157
- ## 3.设置绑定用户ID
106
+ ## 3.设置当前页面自动采集PVUV数据
158
107
 
159
108
  ```js
109
+ //在任意页面
110
+ import { buriedPoint } from '@/utils/buried-point';
111
+ //vue
112
+ onMounted(async () => {
113
+ buriedPoint.setPageExtraObj(
114
+ {
115
+ properties: {test: '123'}, //扩展参数
116
+ busSegment: '8', //业务板块
117
+ module: '4', //业务模块
118
+ }
119
+ )
120
+ })
121
+ //react
122
+ useEffect(() => {
123
+ buriedPoint.setPageExtraObj({
124
+ properties: {test: '123'}, //扩展参数
125
+ busSegment: '8', //业务板块
126
+ module: '4', //业务模块
127
+ })
128
+ }, [])
129
+ ```
130
+
131
+ ## 4.获取埋点SDK内跟踪ID
132
+
133
+ ```js
134
+ import { buriedPoint } from '@/utils/buried-point';
135
+ buriedPoint.getTrackId()
136
+ ```
137
+
138
+ ## 5.设置绑定用户ID
139
+
140
+ ```js
141
+ import { buriedPoint } from '@/utils/buried-point';
160
142
  // 应用登录成功后,调用下面API设置用户ID,后续产生的统计事件将会与该用户关联起来
161
143
  buriedPoint.setUserInfo(xxxx)
162
144
  ```
163
145
 
164
- ## 4.自定义上报
146
+ ## 6.自定义上报
165
147
 
166
- ### 4.1 自定义埋点事件对接可视化埋点平台说明
148
+ ### 6.1 自定义埋点事件对接可视化埋点平台说明
167
149
 
168
- #### 4.1.1 事件名称规范:
150
+ #### 6.1.1 事件名称规范:
169
151
 
170
152
  - 事件名称需按照事件类型_元素名称/页面名称_平台规则填写,例如“浏览_首页_ web”“点击_xxx商品_ web”
171
153
 
172
154
  - 事件名称需唯一
173
155
 
174
- #### 4.1.2 事件类型:
156
+ #### 6.1.2 事件类型:
175
157
 
176
158
  - 事件类型仅能选择可视化埋点提供的事件类型,各个事件类型的触发、上报由各自定义埋点业务平台自行确认,事件类型包括以下四种:
177
159
 
@@ -183,7 +165,7 @@ buriedPoint.setUserInfo(xxxx)
183
165
 
184
166
  - **浏览事件【 browse 】**
185
167
 
186
- #### 4.1.3自定义埋点事件包含事件内容说明:
168
+ #### 6.1.3自定义埋点事件包含事件内容说明:
187
169
 
188
170
  - 事件ID
189
171
 
@@ -195,7 +177,7 @@ buriedPoint.setUserInfo(xxxx)
195
177
 
196
178
  - 扩展参数,参数内容为自定义埋点平台自行定义,该事件需要额外传到可视化平台上的事件内容,以json字符串方式上传;json字符串长度限制为500字符,大于500字符参数可正常上报,做截断展示。
197
179
 
198
- ## 5.设置自定义上报
180
+ ## 7.设置自定义上报
199
181
 
200
182
  ```javascript
201
183
  // 调用自定义上报
@@ -209,25 +191,23 @@ data: json字符串
209
191
  $extend_param: 扩展参数(JSON) [ 非必填字段(建议根据业务需求填上) ]
210
192
  $event_code: 事件标识符 【必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
211
193
  $page: 当前页对象 【非必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
212
- $path: 埋点组件的路径 【必填字段,建议根据业务填上, 否则数据统计可能出现缺失】
213
194
  }
214
195
  // 参考例子:【搜素事件】
215
196
  import { BuriedPoint } from "@/utils/buried-point";
216
197
  const params = {
217
198
  $event_id: "3156566905601572864",
199
+ $event_code: "",
218
200
  $busSegment: 1,
219
201
  $module: 1,
220
202
  $extend_param: {
221
203
  title: "自定义[搜索事件]上报-搜索_首页搜索框",
222
204
  searchContent: "猕猴桃"
223
205
  },
224
- $event_code: "",
225
206
  $page: {
226
207
  domain: "",
227
208
  path: "",
228
209
  title: "",
229
210
  },
230
- $path: "",
231
211
  }
232
212
  buriedPoint.setCustomEvent(params)
233
213
  ```
@@ -242,7 +222,7 @@ busSegment module
242
222
  2.民宿/酒店 1.民宿 2.酒店
243
223
  ```
244
224
 
245
- ## 6、流量上报
225
+ ## 8、流量上报
246
226
 
247
227
  - sdk初始化后,可通过**onStartTrack(params)** 方法注册上报流量,并为上报添加属性值:
248
228
 
@@ -287,7 +267,7 @@ buriedPoint.onStartTrack(params)
287
267
  buriedPoint.onDestroyTrack()
288
268
  ```
289
269
 
290
- ## 6、批量创建事件ID
270
+ ## 9、批量创建事件ID
291
271
 
292
272
  ## main.py
293
273
 
@@ -331,9 +311,9 @@ pip install requests
331
311
 
332
312
  先执行 `batchCreate` 方法将数据推到埋点后台管理系统中,再执行 `batchWrite` 方法,将后台管理中的数据写入到本地文件中
333
313
 
334
- #### 4、执行脚本
314
+ ### 4、执行脚本
335
315
 
336
- ##### 方式一(推荐)
316
+ #### 方式一(推荐)
337
317
 
338
318
  在命令后增加**业务模块文件夹**名称,自动执行该文件夹下的参数文件
339
319
 
@@ -427,11 +407,20 @@ export default connect(({trade}) => {
427
407
 
428
408
  ##### 云测管理端地址
429
409
 
430
- - chameleon.gcongo.com.cn
410
+ - https://chameleon.gcongo.com.cn
431
411
 
432
412
  #### 8、SDK 文档
433
413
 
434
414
  http://verdaccio.gogdev.cn/-/web/detail/visual-buried-point-platform-miniprogram
435
415
 
416
+ ## 10 问题记录
417
+
418
+ 1、在buried-point.ts配置文件中,提示无法找到模块“visual-buried-point-platform-h5”的声明文件。
419
+
420
+ 在src下创建文件shims-vue.d.ts或者typings.d.ts,写入如下:
421
+
422
+ declare module '@/utils/buried-point-h5.js';
423
+ declare module 'visual-buried-point-platform-h5';
424
+
436
425
 
437
426