@bi_funsdata/js-sdk 1.0.0 → 1.0.1-beta.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,30 @@
1
+ ## [1.0.1-beta.1](https://gitlab.yeahmobi.com/gst/javascript-sdk/compare/v1.0.0...v1.0.1-beta.1) (2024-11-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * demo name ([c4e0261](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/c4e02612005ec8d0eb34f92b572b69b269691145))
7
+
8
+
9
+
10
+ # [1.0.0](https://gitlab.yeahmobi.com/gst/javascript-sdk/compare/3e10ecab0b67ae50ca3caed00f7ed23d59106d75...v1.0.0) (2024-11-12)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * serverUrl ([ef92f7f](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/ef92f7f546e7f7577f74f3bdcde2df204a70541f))
16
+
17
+
18
+ ### Features
19
+
20
+ * 打包 ([e311beb](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/e311beb1a55acdeb23018f82ab725397a4cd4513))
21
+ * 名称规范化 ([c04efb0](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/c04efb035a4e4317fb30f9556c55d398bf9648e8))
22
+ * debug mode track ([3e10eca](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/3e10ecab0b67ae50ca3caed00f7ed23d59106d75))
23
+ * default mode track ([825c106](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/825c1067e0ffa96b908d3ad3f925f5f4680866df))
24
+ * encrypt ([06e056b](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/06e056b3266a05728e96c98249d01c0123688839))
25
+ * getTrackData ([83f5cef](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/83f5cef423e69a6a0bfbd9145282d04a1b77ab94))
26
+ * Heartbeat ([e8f0e77](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/e8f0e7748ec53f31b035c72d786784044639bea7))
27
+ * rollup ([f5f4412](https://gitlab.yeahmobi.com/gst/javascript-sdk/commit/f5f441261674886b2bab10423fa58d69d02f07ce))
28
+
29
+
30
+
package/README.md CHANGED
@@ -1,3 +1,193 @@
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
+ ```html
14
+ <!DOCTYPE html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="UTF-8" />
18
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
19
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
20
+ <title>js-sdk sync</title>
21
+ </head>
22
+
23
+ <body>
24
+ <div>
25
+ <h3>设置访客ID</h3>
26
+ 访客ID:
27
+ <input id="distinctId" type="text" />
28
+ <button onclick="identify()">配置访客ID</button>
29
+ <button onclick="getDistinctId()">获取访客ID</button>
30
+ </div>
31
+ <div>
32
+ <h3>设置账号ID</h3>
33
+ 账号ID:
34
+ <input id="accountId" type="text" />
35
+ <button onclick="login()">设置账号ID</button>
36
+ <button onclick="logout()">清除账号ID</button>
37
+ </div>
38
+
39
+ <div>
40
+ <h3>获取设备ID</h3>
41
+ <button onclick="getDeviceId()">获取设备ID</button>
42
+ </div>
43
+
44
+ <div>
45
+ <h3>上传事件</h3>
46
+ <button onclick="track()">上传事件</button>
47
+ </div>
48
+
49
+ <div>
50
+ <h3>心跳</h3>
51
+ <button onclick="setHeartbeat()">开始心跳</button>
52
+ <button onclick="clearHeartbeat()">结束心跳</button>
53
+ <button onclick="setHeartbeatProps()">设置心跳参数</button>
54
+ <button onclick="removeHeartbeatProps()">删除心跳参数</button>
55
+ </div>
56
+ <script>
57
+ function initSDK() {
58
+ window.fa = window.funsdata;
59
+ // 创建 SDK 配置对象
60
+ const config = {
61
+ appId: "460",
62
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
63
+ showLog: false,
64
+ // debug模式,
65
+ mode: "debug",
66
+ // 开启上报加密
67
+ // encrypt: true
68
+ };
69
+ // 用配置对象初始化 SDK
70
+ fa.init(config);
71
+ }
72
+
73
+ // 配置访客ID
74
+ function identify() {
75
+ let distinctId = document.getElementById("distinctId").value;
76
+ fa.identify(distinctId);
77
+ }
78
+
79
+ // 获取访客ID
80
+ function getDistinctId() {
81
+ let distinctId = fa.getDistinctId();
82
+ alert(distinctId);
83
+ }
84
+
85
+ // 设置账号ID
86
+ function login() {
87
+ let accountId = document.getElementById("accountId").value;
88
+ fa.login(accountId);
89
+ }
90
+
91
+ // 清除账号ID
92
+ function logout() {
93
+ fa.logout();
94
+ document.getElementById("accountId").value = "";
95
+ }
96
+
97
+ // 获取设备ID
98
+ function getDeviceId() {
99
+ console.log(fa.getDeviceId());
100
+ }
101
+
102
+ // 开始心跳
103
+ function setHeartbeat() {
104
+ fa.startHeartbeat(3000);
105
+ }
106
+ // 结束心跳
107
+ function clearHeartbeat() {
108
+ fa.clearHeartbeat();
109
+ }
110
+ // 设置心跳参数
111
+ function setHeartbeatProps() {
112
+ fa.setHeartbeatProps({
113
+ test1: 1,
114
+ test2: 1,
115
+ });
116
+ fa.setHeartbeatProps({
117
+ test2: 2,
118
+ test3: 3,
119
+ });
120
+ }
121
+ // 删除心跳参数
122
+ function removeHeartbeatProps() {
123
+ // fa.removeHeartbeatProps() // 删除所有自定义心跳上报参数
124
+ // fa.removeHeartbeatProps('test1') // 删除单个心跳上报参数
125
+ fa.removeHeartbeatProps(["test1", "test3"]); // 删除多个心跳上报参数
126
+ }
127
+
128
+ // 上传事件
129
+ async function track() {
130
+ try {
131
+ const { res, req } = await fa.track(
132
+ "test", // 追踪事件的名称
133
+ {
134
+ exampleProp1: "testValue1",
135
+ exampleProp2: "testValue2",
136
+ } // 需要上传的事件属性
137
+ );
138
+ // 当前请求参数
139
+ console.log(JSON.parse(req));
140
+ // 响应参数
141
+ console.log(JSON.parse(res));
142
+ } catch (error) {
143
+ // 抛出错误
144
+ console.error(error);
145
+ }
146
+ }
147
+ </script>
148
+ <script onload="initSDK()" src="../dist/umd.min.js"></script>
149
+ </body>
150
+ </html>
151
+ ```
152
+
153
+ ### 异步载入
154
+
155
+ 增加`async`标记即可
156
+
157
+ ```html
158
+ <script async onload="initSDK()" src="../dist/umd.min.js"></script>
159
+ ```
160
+
161
+ ## esm
162
+
163
+ [esm demo](https://gitlab.yeahmobi.com/gst/javascript-sdk/-/blob/master/dist/esm.html)
164
+
165
+ ### install
166
+
167
+ ```bash
168
+ pnpm i @bi_funsdata/js-sdk
169
+ ```
170
+
171
+ ### do something
172
+
173
+ ```javascript
174
+ import fa from "../dist/esm.min.js";
175
+
176
+ const config = {
177
+ appId: "460",
178
+ serverUrl: "https://deapi.funsdata.com/v1/sdk/report",
179
+ showLog: false,
180
+ // debug模式,
181
+ mode: "debug",
182
+ // 开启上报加密
183
+ // encrypt: true
184
+ };
185
+ // 用配置对象初始化 SDK
186
+ fa.init(config);
187
+
188
+ console.log("getDeviceId", fa.getDeviceId());
189
+ ```
190
+
191
+ # 更多产品功能
192
+
193
+ [数眼智能埋点说明](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>