@bi_funsdata/js-sdk 1.0.0 → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ ## [1.0.1](https://gitlab.yeahmobi.com/gst/javascript-sdk/compare/v1.0.1-beta.1...v1.0.1) (2024-11-14)
2
+
3
+
4
+
5
+ ## [1.0.1-beta.1](https://gitlab.yeahmobi.com/gst/javascript-sdk/compare/v1.0.0...v1.0.1-beta.1) (2024-11-13)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * demo name ([c4e0261](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/c4e02612005ec8d0eb34f92b572b69b269691145))
11
+
12
+
13
+
14
+ # [1.0.0](https://gitlab.yeahmobi.com/gst/javascript-sdk/compare/3e10ecab0b67ae50ca3caed00f7ed23d59106d75...v1.0.0) (2024-11-12)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * serverUrl ([ef92f7f](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/ef92f7f546e7f7577f74f3bdcde2df204a70541f))
20
+
21
+
22
+ ### Features
23
+
24
+ * 打包 ([e311beb](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/e311beb1a55acdeb23018f82ab725397a4cd4513))
25
+ * 名称规范化 ([c04efb0](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/c04efb035a4e4317fb30f9556c55d398bf9648e8))
26
+ * debug mode track ([3e10eca](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/3e10ecab0b67ae50ca3caed00f7ed23d59106d75))
27
+ * default mode track ([825c106](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/825c1067e0ffa96b908d3ad3f925f5f4680866df))
28
+ * encrypt ([06e056b](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/06e056b3266a05728e96c98249d01c0123688839))
29
+ * getTrackData ([83f5cef](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/83f5cef423e69a6a0bfbd9145282d04a1b77ab94))
30
+ * Heartbeat ([e8f0e77](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/e8f0e7748ec53f31b035c72d786784044639bea7))
31
+ * rollup ([f5f4412](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/f5f441261674886b2bab10423fa58d69d02f07ce))
32
+
33
+
34
+
package/README.md CHANGED
@@ -1,3 +1,253 @@
1
- # 使用文档
2
- - 一个简单的demo示例:/example
3
- - 详情使用指南:https://www.yuque.com/maticoo/eetpxb/uuhu37cv782gp0x4
1
+ # @bi_funsdata/js-sdk
2
+
3
+ 数眼智能产品,埋点 js-sdk 功能介绍
4
+
5
+ # Usage
6
+
7
+ ## umd
8
+
9
+ [umd demo](https://gitlab.yeahmobi.com/gst/javascript-sdk/-/blob/master/dist/umd.html)
10
+
11
+ ### 同步载入
12
+
13
+ <details>
14
+ <summary>点击展开收起 HTML 代码</summary>
15
+
16
+ ```html
17
+ <!DOCTYPE html>
18
+ <html lang="en">
19
+ <head>
20
+ <meta charset="UTF-8" />
21
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
22
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
23
+ <title>js-sdk sync</title>
24
+ </head>
25
+
26
+ <body>
27
+ <div>
28
+ <h3>设置访客ID</h3>
29
+ 访客ID:
30
+ <input id="distinctId" type="text" />
31
+ <button onclick="identify()">配置访客ID</button>
32
+ <button onclick="getDistinctId()">获取访客ID</button>
33
+ </div>
34
+ <div>
35
+ <h3>设置账号ID</h3>
36
+ 账号ID:
37
+ <input id="accountId" type="text" />
38
+ <button onclick="login()">设置账号ID</button>
39
+ <button onclick="logout()">清除账号ID</button>
40
+ </div>
41
+
42
+ <div>
43
+ <h3>获取设备ID</h3>
44
+ <button onclick="getDeviceId()">获取设备ID</button>
45
+ </div>
46
+
47
+ <div>
48
+ <h3>上传事件</h3>
49
+ <button onclick="track()">上传事件</button>
50
+ </div>
51
+
52
+ <div>
53
+ <h3>心跳</h3>
54
+ <button onclick="setHeartbeat()">开始心跳</button>
55
+ <button onclick="clearHeartbeat()">结束心跳</button>
56
+ <button onclick="setHeartbeatProps()">设置心跳参数</button>
57
+ <button onclick="removeHeartbeatProps()">删除心跳参数</button>
58
+ </div>
59
+ <script>
60
+ function initSDK() {
61
+ window.fa = window.funsdata;
62
+ // 创建 SDK 配置对象
63
+ const config = {
64
+ appId: "460",
65
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
66
+ showLog: false,
67
+ // debug模式,
68
+ mode: "debug",
69
+ // 开启上报加密
70
+ // encrypt: true
71
+ };
72
+ // 用配置对象初始化 SDK
73
+ fa.init(config);
74
+ }
75
+
76
+ // 配置访客ID
77
+ function identify() {
78
+ let distinctId = document.getElementById("distinctId").value;
79
+ fa.identify(distinctId);
80
+ }
81
+
82
+ // 获取访客ID
83
+ function getDistinctId() {
84
+ let distinctId = fa.getDistinctId();
85
+ alert(distinctId);
86
+ }
87
+
88
+ // 设置账号ID
89
+ function login() {
90
+ let accountId = document.getElementById("accountId").value;
91
+ fa.login(accountId);
92
+ }
93
+
94
+ // 清除账号ID
95
+ function logout() {
96
+ fa.logout();
97
+ document.getElementById("accountId").value = "";
98
+ }
99
+
100
+ // 获取设备ID
101
+ function getDeviceId() {
102
+ console.log(fa.getDeviceId());
103
+ }
104
+
105
+ // 开始心跳
106
+ function setHeartbeat() {
107
+ fa.startHeartbeat(3000);
108
+ }
109
+ // 结束心跳
110
+ function clearHeartbeat() {
111
+ fa.clearHeartbeat();
112
+ }
113
+ // 设置心跳参数
114
+ function setHeartbeatProps() {
115
+ fa.setHeartbeatProps({
116
+ test1: 1,
117
+ test2: 1,
118
+ });
119
+ fa.setHeartbeatProps({
120
+ test2: 2,
121
+ test3: 3,
122
+ });
123
+ }
124
+ // 删除心跳参数
125
+ function removeHeartbeatProps() {
126
+ // fa.removeHeartbeatProps() // 删除所有自定义心跳上报参数
127
+ // fa.removeHeartbeatProps('test1') // 删除单个心跳上报参数
128
+ fa.removeHeartbeatProps(["test1", "test3"]); // 删除多个心跳上报参数
129
+ }
130
+
131
+ // 上传事件
132
+ async function track() {
133
+ try {
134
+ const { res, req } = await fa.track(
135
+ "test", // 追踪事件的名称
136
+ {
137
+ exampleProp1: "testValue1",
138
+ exampleProp2: "testValue2",
139
+ } // 需要上传的事件属性
140
+ );
141
+ // 当前请求参数
142
+ console.log(JSON.parse(req));
143
+ // 响应参数
144
+ console.log(JSON.parse(res));
145
+ } catch (error) {
146
+ // 抛出错误
147
+ console.error(error);
148
+ }
149
+ }
150
+ </script>
151
+ <script
152
+ onload="initSDK()"
153
+ src="https://unpkg.com/@bi_funsdata/js-sdk@latest/dist/umd.min.js"
154
+ ></script>
155
+ </body>
156
+ </html>
157
+ ```
158
+
159
+ </details>
160
+
161
+ ### 异步载入
162
+
163
+ 增加`async`标记即可
164
+
165
+ ```html
166
+ <script
167
+ async
168
+ onload="initSDK()"
169
+ src="https://unpkg.com/@bi_funsdata/js-sdk@latest/dist/umd.min.js"
170
+ ></script>
171
+ ```
172
+
173
+ ## esm
174
+
175
+ esm 引入,会将 dependencies 作为 external,如果项目安装了以下依赖,可以公用依赖,减少打包体积。
176
+
177
+ ```json
178
+ {
179
+ "dependencies": {
180
+ "crypto-js": "^4.2.0",
181
+ "jsencrypt": "^3.3.2",
182
+ "pako": "^2.1.0"
183
+ }
184
+ }
185
+ ```
186
+
187
+ <!-- [esm demo](https://gitlab.yeahmobi.com/gst/javascript-sdk/-/blob/master/dist/esm.html) -->
188
+
189
+ ### install
190
+
191
+ ```bash
192
+ pnpm i @bi_funsdata/js-sdk
193
+ ```
194
+
195
+ ### do something
196
+
197
+ ```javascript
198
+ import fa from "@bi_funsdata/js-sdk";
199
+
200
+ const config = {
201
+ appId: "460",
202
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
203
+ showLog: false,
204
+ // debug模式,
205
+ mode: "debug",
206
+ // 开启上报加密
207
+ // encrypt: true
208
+ };
209
+ // 用配置对象初始化 SDK
210
+ fa.init(config);
211
+
212
+ console.log("getDeviceId", fa.getDeviceId());
213
+ ```
214
+
215
+ # 常见问题
216
+
217
+ ## module not found, crypto resolve fallback
218
+
219
+ ![crypto resolve fallback](./images/crypto_resolve_fallback.png)
220
+ 这是一个加密工具,webpack5 中默认取消了 node 模块的 polyfill,按照提示处理即可。以下是一个不要 polyfill 的示例。
221
+
222
+ ```javascript
223
+ // webpack
224
+ module.exports = {
225
+ resolve: {
226
+ fallback: {
227
+ crypto: false,
228
+ },
229
+ },
230
+ };
231
+
232
+ // craco.config.js
233
+ const webpack = require("webpack");
234
+
235
+ module.exports = {
236
+ webpack: {
237
+ configure: (webpackConfig) => {
238
+ // 添加 fallback 配置
239
+ webpackConfig.resolve.fallback = {
240
+ ...webpackConfig.resolve.fallback,
241
+ events: require.resolve("events/"),
242
+ crypto: require.resolve("crypto-browserify"),
243
+ };
244
+
245
+ return webpackConfig;
246
+ },
247
+ },
248
+ };
249
+ ```
250
+
251
+ # 更多产品功能
252
+
253
+ [数眼智能埋点说明](https://www.yuque.com/maticoo/eetpxb/uuhu37cv782gp0x4)
package/demo/esm.html ADDED
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>js-sdk sync</title>
8
+ </head>
9
+
10
+ <body>
11
+ <script src="./esm.js" type="module"></script>
12
+ </body>
13
+ </html>
package/demo/esm.js ADDED
@@ -0,0 +1,15 @@
1
+ import fa from '../dist/esm.min.js'
2
+
3
+ const config = {
4
+ appId: "460",
5
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
6
+ showLog: false,
7
+ // debug模式,
8
+ mode: "debug",
9
+ // 开启上报加密
10
+ // encrypt: true
11
+ };
12
+ // 用配置对象初始化 SDK
13
+ fa.init(config);
14
+
15
+ console.log('getDeviceId', fa.getDeviceId());
package/demo/umd.html ADDED
@@ -0,0 +1,137 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>js-sdk sync</title>
8
+ </head>
9
+
10
+ <body>
11
+ <div>
12
+ <h3>设置访客ID</h3>
13
+ 访客ID:
14
+ <input id="distinctId" type="text" />
15
+ <button onclick="identify()">配置访客ID</button>
16
+ <button onclick="getDistinctId()">获取访客ID</button>
17
+ </div>
18
+ <div>
19
+ <h3>设置账号ID</h3>
20
+ 账号ID:
21
+ <input id="accountId" type="text" />
22
+ <button onclick="login()">设置账号ID</button>
23
+ <button onclick="logout()">清除账号ID</button>
24
+ </div>
25
+
26
+ <div>
27
+ <h3>获取设备ID</h3>
28
+ <button onclick="getDeviceId()">获取设备ID</button>
29
+ </div>
30
+
31
+ <div>
32
+ <h3>上传事件</h3>
33
+ <button onclick="track()">上传事件</button>
34
+ </div>
35
+
36
+ <div>
37
+ <h3>心跳</h3>
38
+ <button onclick="setHeartbeat()">开始心跳</button>
39
+ <button onclick="clearHeartbeat()">结束心跳</button>
40
+ <button onclick="setHeartbeatProps()">设置心跳参数</button>
41
+ <button onclick="removeHeartbeatProps()">删除心跳参数</button>
42
+ </div>
43
+ <script>
44
+ function initSDK() {
45
+ window.fa = window.funsdata;
46
+ // 创建 SDK 配置对象
47
+ const config = {
48
+ appId: "460",
49
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
50
+ showLog: false,
51
+ // debug模式,
52
+ mode: "debug",
53
+ // 开启上报加密
54
+ // encrypt: true
55
+ };
56
+ // 用配置对象初始化 SDK
57
+ fa.init(config);
58
+ }
59
+
60
+ // 配置访客ID
61
+ function identify() {
62
+ let distinctId = document.getElementById("distinctId").value;
63
+ fa.identify(distinctId);
64
+ }
65
+
66
+ // 获取访客ID
67
+ function getDistinctId() {
68
+ let distinctId = fa.getDistinctId();
69
+ alert(distinctId);
70
+ }
71
+
72
+ // 设置账号ID
73
+ function login() {
74
+ let accountId = document.getElementById("accountId").value;
75
+ fa.login(accountId);
76
+ }
77
+
78
+ // 清除账号ID
79
+ function logout() {
80
+ fa.logout();
81
+ document.getElementById("accountId").value = "";
82
+ }
83
+
84
+ // 获取设备ID
85
+ function getDeviceId() {
86
+ console.log(fa.getDeviceId());
87
+ }
88
+
89
+ // 开始心跳
90
+ function setHeartbeat() {
91
+ fa.startHeartbeat(3000);
92
+ }
93
+ // 结束心跳
94
+ function clearHeartbeat() {
95
+ fa.clearHeartbeat();
96
+ }
97
+ // 设置心跳参数
98
+ function setHeartbeatProps() {
99
+ fa.setHeartbeatProps({
100
+ test1: 1,
101
+ test2: 1,
102
+ });
103
+ fa.setHeartbeatProps({
104
+ test2: 2,
105
+ test3: 3,
106
+ });
107
+ }
108
+ // 删除心跳参数
109
+ function removeHeartbeatProps() {
110
+ // fa.removeHeartbeatProps() // 删除所有自定义心跳上报参数
111
+ // fa.removeHeartbeatProps('test1') // 删除单个心跳上报参数
112
+ fa.removeHeartbeatProps(["test1", "test3"]); // 删除多个心跳上报参数
113
+ }
114
+
115
+ // 上传事件
116
+ async function track() {
117
+ try {
118
+ const { res, req } = await fa.track(
119
+ "test", // 追踪事件的名称
120
+ {
121
+ exampleProp1: "testValue1",
122
+ exampleProp2: "testValue2",
123
+ } // 需要上传的事件属性
124
+ );
125
+ // 当前请求参数
126
+ console.log(JSON.parse(req));
127
+ // 响应参数
128
+ console.log(JSON.parse(res));
129
+ } catch (error) {
130
+ // 抛出错误
131
+ console.error(error);
132
+ }
133
+ }
134
+ </script>
135
+ <script async onload="initSDK()" src="../dist/umd.min.js"></script>
136
+ </body>
137
+ </html>