@cloudcare/browser-logs 3.2.19 → 3.2.24

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.
Files changed (39) hide show
  1. package/README.md +392 -123
  2. package/bundle/dataflux-logs.js +1 -1
  3. package/cjs/boot/buildEnv.js +2 -3
  4. package/cjs/boot/buildEnv.js.map +1 -1
  5. package/cjs/boot/logsPublicApi.js.map +1 -1
  6. package/cjs/boot/preStartLogs.js.map +1 -1
  7. package/cjs/boot/startLogs.js +3 -0
  8. package/cjs/boot/startLogs.js.map +1 -1
  9. package/cjs/domain/configuration.js +1 -2
  10. package/cjs/domain/configuration.js.map +1 -1
  11. package/cjs/domain/contexts/internalContext.js.map +1 -1
  12. package/cjs/domain/logger.js +3 -6
  13. package/cjs/domain/logger.js.map +1 -1
  14. package/cjs/domain/logsCollection/console/consoleCollection.js +5 -6
  15. package/cjs/domain/logsCollection/console/consoleCollection.js.map +1 -1
  16. package/cjs/domain/logsCollection/logger/loggerCollection.js +1 -2
  17. package/cjs/domain/logsCollection/logger/loggerCollection.js.map +1 -1
  18. package/cjs/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
  19. package/cjs/domain/logsCollection/report/reportCollection.js.map +1 -1
  20. package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
  21. package/cjs/domain/logsSessionManager.js +2 -4
  22. package/cjs/domain/logsSessionManager.js.map +1 -1
  23. package/cjs/entries/main.js +1 -2
  24. package/cjs/entries/main.js.map +1 -1
  25. package/esm/boot/buildEnv.js +1 -1
  26. package/esm/boot/logsPublicApi.js.map +1 -1
  27. package/esm/boot/preStartLogs.js.map +1 -1
  28. package/esm/boot/startLogs.js +3 -0
  29. package/esm/boot/startLogs.js.map +1 -1
  30. package/esm/domain/contexts/internalContext.js.map +1 -1
  31. package/esm/domain/logger.js.map +1 -1
  32. package/esm/domain/logsCollection/console/consoleCollection.js +5 -6
  33. package/esm/domain/logsCollection/console/consoleCollection.js.map +1 -1
  34. package/esm/domain/logsCollection/networkError/networkErrorCollection.js.map +1 -1
  35. package/esm/domain/logsCollection/report/reportCollection.js.map +1 -1
  36. package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js.map +1 -1
  37. package/esm/domain/logsSessionManager.js.map +1 -1
  38. package/package.json +33 -33
  39. package/src/boot/startLogs.js +3 -0
package/README.md CHANGED
@@ -1,43 +1,46 @@
1
- # DataFlux Browser Logs SDK
2
-
3
- ## 简介
4
- 通过web浏览器或者javascript客户端主动发送不同等级的[日志数据](https://www.yuque.com/dataflux/datakit/logging)(`对应的source:browser_log
5
- `指标类型日志数据)到[DataFlux](https://dataflux.cn)。
6
-
7
- ## 功能简介
8
- - 自定义日志数据采集,通过sdk接入客户端应用中,针对不同场景采集不同日志数据。
9
- - 可以自动收集应用端的错误信息(包括网络错误,console错误,以及js错误)上报到DataFlux。
10
- - 自定义错误等级(`debug`,`critical`,`error`,`info`,`warn`),自定义Logger对象,以及自定义log字段
11
- - 可以自动收集[RUM](https://www.yuque.com/dataflux/doc/eqs7v2)相关数据,关联RUM业务场景
12
-
13
- ## 开始使用
14
- ### 前置条件
15
- **datakit** 通过[datakit](https://www.yuque.com/dataflux/doc/oolclw)日志采集API发送日志数据到DataFlux平台
16
-
17
- **引入SDK** 可通过`NPM`,`CDN同步`或`CDN异步`的方式引入SDK到应用中
18
-
19
- **支持的浏览器** 支持所有pc端,移动端的浏览器
20
-
21
- ### 你可以从下面几种方式中选择一种接入到你的 Web 应用中
22
-
23
- | 接入方式 | 简介 |
24
- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25
- | NPM | 通过把 SDK 代码一起打包到你的前端项目中,此方式可以确保对前端页面的性能不会有任何影响,不过可能会错过 SDK 初始化之前的的请求、错误的收集。 |
26
- | CDN 异步加载 | 通过 CDN 加速缓存,以异步脚本引入的方式,引入 SDK 脚本,此方式可以确保 SDK 脚本的下载不会影响页面的加载性能,不过可能会错过 SDK 初始化之前的的请求、错误的收集。 |
27
- | CDN 同步加载 | 通过 CDN 加速缓存,以同步脚本引入的方式,引入 SDK 脚本,此方式可以确保能够收集到所有的错误,资源,请求,性能指标。不过可能会影响页面的加载性能。 |
1
+ # Browser Log Collection
28
2
 
29
- ### NPM
3
+ ---
4
+
5
+ Send log data of different levels (`corresponding source:browser_log` Metrics type log data) actively through a Web browser or Javascript client to [Guance](https://guance.com/).
6
+
7
+ - Custom log data collection, by integrating the SDK into the client application, collects different log data for different scenarios;
8
+ - Automatically collect error information from the application (including network errors, console errors, and js errors) and report it to Guance;
9
+ - Customize error levels (`debug`, `critical`, `error`, `info`, `warn`), customize Logger objects, and customize Log fields;
10
+ - Automatically collect [RUM](../../docs/rum/app-access.md) related data and associate it with RUM business scenarios.
11
+
12
+ ## Getting Started
13
+
14
+ ### Prerequisites
15
+
16
+ - **DataKit**: Send log data to the Guance platform via the DataKit Log Collection API;
17
+
18
+ - **Integrate SDK**: The SDK can be integrated into the application using methods such as `NPM`, `CDN synchronous`, or `CDN asynchronous`;
19
+
20
+ - **Supported Browsers**: Supports all PC and mobile browsers.
21
+
22
+ ### Choose Integration Method
23
+
24
+ | Integration Method | Introduction |
25
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26
+ | NPM | By bundling the SDK code into your frontend project, this method ensures no impact on the performance of the frontend page. However, requests and errors before SDK initialization may be missed. |
27
+ | CDN Asynchronous Loading | Through CDN accelerated caching, the SDK script is introduced asynchronously. This method ensures that the download of the SDK script does not affect the loading performance of the page, but it might miss requests and errors collected before the SDK initialization. |
28
+ | CDN Synchronous Loading | Through CDN accelerated caching, the SDK script is introduced synchronously. This method ensures the collection of all errors, resources, requests, and performance metrics. However, it might affect the loading performance of the page. |
29
+
30
+ #### NPM
30
31
 
31
32
  ```javascript
32
33
  import { datafluxLogs } from '@cloudcare/browser-logs'
33
34
  datafluxLogs.init({
34
- datakitOrigin: '<DATAKIT ORIGIN>'
35
+ datakitOrigin: '<DataKit domain or IP>', // DK integration requires configuration
36
+ clientToken: 'clientToken', // Public OpenWay integration requires filling out
37
+ site: 'Public OpenWay address' // Public OpenWay integration requires filling out
35
38
  //service: 'browser',
36
39
  //forwardErrorsToLogs:true
37
40
  })
38
41
  ```
39
42
 
40
- ### CDN 异步加载
43
+ #### CDN Asynchronous Loading
41
44
 
42
45
  ```html
43
46
  <script>
@@ -57,12 +60,14 @@ datafluxLogs.init({
57
60
  window,
58
61
  document,
59
62
  'script',
60
- 'https://static.dataflux.cn/browser-sdk/v1/dataflux-logs.js',
63
+ 'https://static.guance.com/browser-sdk/v3/dataflux-logs.js',
61
64
  'DATAFLUX_LOGS'
62
65
  )
63
66
  DATAFLUX_LOGS.onReady(function () {
64
67
  DATAFLUX_LOGS.init({
65
- datakitOrigin: '<DATAKIT ORIGIN>'
68
+ datakitOrigin: '<DataKit domain or IP>', // DK integration requires configuration
69
+ clientToken: 'clientToken', // Public OpenWay integration requires filling out
70
+ site: 'Public OpenWay address' // Public OpenWay integration requires filling out
66
71
  //service: 'browser',
67
72
  //forwardErrorsToLogs:true
68
73
  })
@@ -70,150 +75,414 @@ datafluxLogs.init({
70
75
  </script>
71
76
  ```
72
77
 
73
- ### CDN 同步加载
78
+ #### CDN Synchronous Loading
74
79
 
75
80
  ```html
76
81
  <script
77
- src="https://static.dataflux.cn/browser-sdk/v1/dataflux-logs.js"
82
+ src="https://static.guance.com/browser-sdk/v3/dataflux-logs.js"
78
83
  type="text/javascript"
79
84
  ></script>
80
85
  <script>
81
86
  window.DATAFLUX_LOGS &&
82
87
  window.DATAFLUX_LOGS.init({
83
- datakitOrigin: '<DATAKIT ORIGIN>'
88
+ datakitOrigin: '<DataKit domain or IP>', // DK integration requires configuration
89
+ clientToken: 'clientToken', // Public OpenWay integration requires filling out
90
+ site: 'Public OpenWay address' // Public OpenWay integration requires filling out
84
91
  //service: 'browser',
85
92
  //forwardErrorsToLogs:true
86
93
  })
87
94
  </script>
88
95
  ```
89
96
 
90
- ## 配置
97
+ ## Configuration
98
+
99
+ ### Initialization Parameters
91
100
 
92
- ### 初始化参数
101
+ | **Parameter** | **Type** | **Required** | **Default Value** | **Description** |
102
+ | ---------------------- | ------------ | ------------ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
+ | `datakitOrigin` | String | Yes | | DataKit data reporting Origin Note: `protocol (including: //), domain name (or IP address) [and port number]` Example: https://www.datakit.com, http://100.20.34.3:8088. |
104
+ | `clientToken` | String | Yes | | Data token for reporting in the openway method, obtained from the Guance console, required (public openway method access). |
105
+ | `site` | String | Yes | | Data reporting address for public openway method, obtained from the Guance console, required (public openway method access). |
106
+ | `service` | String | No | `browser` | Log Service Name |
107
+ | `env` | String | No | | Current environment of the Web application, such as Prod: production environment; Gray: gray environment; Pre: pre-release environment Common: daily environment; Local: local environment; |
108
+ | `version` | String | No | | Version number of the Web application |
109
+ | `sessionSampleRate` | Number | No | `100` | Percentage of Metrics data collection: `100` means full collection, `0` means no collection |
110
+ | `forwardErrorsToLogs` | Boolean | No | `true` | Setting to `false` stops collecting console.error, js, and network errors reported to Guance log data |
111
+ | `silentMultipleInit` | Boolean | No | `false` | Does not allow multiple log objects to be initialized |
112
+ | `forwardConsoleLogs` | String/Array | No | | Browser console log types to collect, optional values: `error`, `log`, `info`, `warn`, `error` |
113
+ | `storeContextsToLocal` | Boolean | No | | Version requirement:`>3.1.2`. Whether to cache user-defined data locally in localstorage, for example: `setUser`, `addGlobalContext` api added custom data. |
114
+ | `storeContextsKey` | String | No | | Version requirement:`>3.1.18`. Defines the key stored in localstorage, default not filled, auto-generated, this parameter mainly solves the problem of shared store under the same domain for different sub-paths |
93
115
 
94
- | 参数 | 类型 | 是否必须 | 默认值 | 描述 |
95
- | --------------------- | ------- | -------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
96
- | `datakitOrigin` | String | 是 | | datakit 数据上报 Origin 注释: `协议(包括://),域名(或IP地址)[和端口号]` 例如:https://www.datakit.com, http://100.20.34.3:8088 |
97
- | `service` | String | 否 | `browser` | 日志service名称 |
98
- | `env` | String | 否 | | web 应用当前环境, 如 prod:线上环境;gray:灰度环境;pre:预发布环境 common:日常环境;local:本地环境; |
99
- | `version` | String | 否 | | web 应用的版本号 |
100
- | `sessionSampleRate` | Number | 否 | `100` | 指标数据收集百分比: `100`表示全收集,`0`表示不收集 |
101
- | `forwardErrorsToLogs` | Boolean | 否 | `true` | 设置为`false` 表示停止采集console.error、 js、以及网络错误上报到DataFlux日志数据中 |
102
- | `silentMultipleInit` | Boolean | 否 | `false` | 不允许有多个日志对象被初始化 |
116
+ ## Usage
103
117
 
104
- ## 使用
105
- SDK在应用中初始化后,通过暴露的JS API 可以自定义配置日志数据
106
- ```js
118
+ After initializing the SDK in the application, you can customize log data configurations via exposed JS APIs.
119
+
120
+ ```javascript
107
121
  logger.debug | info | warn | error | critical (message: string, messageContext = Context)
108
122
  ```
123
+
109
124
  ### NPM
110
- ```js
125
+
126
+ ```javascript
111
127
  import { datafluxLogs } from '@cloudcare/browser-logs'
112
128
 
113
129
  datafluxLogs.logger.info('Button clicked', { name: 'buttonName', id: 123 })
114
130
  ```
115
131
 
116
- ### CDN 异步
117
- ```js
132
+ ### CDN Asynchronous
133
+
134
+ ```javascript
118
135
  DATAFLUX_LOGS.onReady(function () {
119
136
  DATAFLUX_LOGS.logger.info('Button clicked', { name: 'buttonName', id: 123 })
120
137
  })
121
138
  ```
122
139
 
123
- ### CDN 同步
124
- ```js
125
- window.DATAFLUX_LOGS && DATAFLUX_LOGS.logger.info('Button clicked', { name: 'buttonName', id: 123 })
140
+ ### CDN Synchronous
141
+
142
+ ```javascript
143
+ window.DATAFLUX_LOGS &&
144
+ DATAFLUX_LOGS.logger.info('Button clicked', { name: 'buttonName', id: 123 })
126
145
  ```
127
146
 
128
- ## 返回数据结构
129
- ```JSON
147
+ ## Returned Data Structure
148
+
149
+ ```json
130
150
  {
131
- "service": "browser",
132
- "session": {
133
- "id": "c549c2b8-4955-4f74-b7f8-a5f42fc6e79b"
134
- },
135
- "type": "logger",
136
- "_dd": {
137
- "sdk_name": "Web LOG SDK",
138
- "sdk_version": "1.0.0",
139
-
140
- },
151
+ "service": "browser",
152
+ "session": {
153
+ "id": "c549c2b8-4955-4f74-b7f8-a5f42fc6e79b"
154
+ },
155
+ "type": "logger",
156
+ "_dd": {
157
+ "sdk_name": "Web LOG SDK",
158
+ "sdk_version": "1.0.0",
141
159
  "env": "",
142
- "version": "",
143
- "device": {
144
- "os": "Mac OS",
145
- "os_version": "10.14.6",
146
- "os_version_major": "10",
147
- "browser": "Chrome",
148
- "browser_version": "90.0.4430.85",
149
- "browser_version_major": "90",
150
- "screen_size": "2560*1440",
151
- "network_type": "3g",
152
- "divice": "PC"
153
- },
154
- "user": {},
155
- "date": 1621321916756,
156
- "view": {
157
- "referrer": "",
158
- "url": "http://localhost:8080/",
159
- "host": "localhost:8080",
160
- "path": "/",
161
- "path_group": "/",
162
- "url_query": "{}",
163
- "id": "5dce64f4-8d6d-411a-af84-c41653ccd94a"
164
- },
165
- "application": {
166
- "id": "app_idxxxxxx"
167
- },
168
- "message": "XHR error get http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
169
- "status": "error",
170
- "error": {
171
- "source": "network",
172
- "stack": "Failed to load"
173
- },
174
- "http": {
175
- "method": "get",
176
- "status_code": 0,
177
- "status_group": 0,
178
- "url": "http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
179
- "url_host": "testing-ft2x-api.cloudcare.cn",
180
- "url_path": "/api/v1/workspace/xxx",
181
- "url_path_group": "/api/?/workspace/xxx"
182
- }
160
+ "version": ""
161
+ },
162
+ "device": {
163
+ "os": "Mac OS",
164
+ "os_version": "10.14.6",
165
+ "os_version_major": "10",
166
+ "browser": "Chrome",
167
+ "browser_version": "90.0.4430.85",
168
+ "browser_version_major": "90",
169
+ "screen_size": "2560*1440",
170
+ "network_type": "3g",
171
+ "divice": "PC"
172
+ },
173
+ "user": {},
174
+ "date": 1621321916756,
175
+ "view": {
176
+ "referrer": "",
177
+ "url": "http://localhost:8080/",
178
+ "host": "localhost:8080",
179
+ "path": "/",
180
+ "path_group": "/",
181
+ "url_query": "{}",
182
+ "id": "5dce64f4-8d6d-411a-af84-c41653ccd94a"
183
+ },
184
+ "application": {
185
+ "id": "app_idxxxxxx"
186
+ },
187
+ "message": "XHR error get http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
188
+ "status": "error",
189
+ "tags": {},
190
+ "error": {
191
+ "source": "network",
192
+ "stack": "Failed to load"
193
+ },
194
+ "resource": {
195
+ "method": "get",
196
+ "status": 0,
197
+ "status_group": 0,
198
+ "url": "http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
199
+ "url_host": "testing-ft2x-api.cloudcare.cn",
200
+ "url_path": "/api/v1/workspace/xxx",
201
+ "url_path_group": "/api/?/workspace/xxx"
202
+ }
183
203
  }
184
204
  ```
185
- ## Status 参数
186
- 初始化SDk后,可以使用提供`log` API,定义不同类型的状态
187
- ```js
205
+
206
+ ## Status Parameter
207
+
208
+ After initializing the SDK, you can use the provided `log` API to define different types of statuses.
209
+
210
+ ```javascript
188
211
  log (message: string, messageContext: Context, status? = 'debug' | 'info' | 'warn' | 'error' | 'critical')
189
212
  ```
190
213
 
191
214
  ### NPM
192
- ```js
215
+
216
+ ```javascript
193
217
  import { datafluxLogs } from '@cloudcare/browser-logs'
194
218
 
195
219
  datafluxLogs.logger.log(<MESSAGE>,<JSON_ATTRIBUTES>,<STATUS>);
196
-
197
220
  ```
198
221
 
199
- ### CDN 异步
200
- ```js
222
+ ### CDN Asynchronous
223
+
224
+ ```javascript
201
225
  DATAFLUX_LOGS.onReady(function () {
202
226
  DATAFLUX_LOGS.logger.log(<MESSAGE>,<JSON_ATTRIBUTES>,<STATUS>);
203
227
  })
204
228
  ```
205
229
 
206
- ### CDN 同步
207
- ```js
230
+ ### CDN Synchronous
231
+
232
+ ```javascript
208
233
  window.DATAFLUX_LOGS && DATAFLUX_LOGS.logger.log(<MESSAGE>,<JSON_ATTRIBUTES>,<STATUS>);
209
234
  ```
210
235
 
211
- ## 参数说明
236
+ ## Parameter Description
237
+
238
+ | **Parameter** | **Description** |
239
+ | ------------------- | ------------------------------------------------------------------- |
240
+ | `<MESSAGE>` | Message field in Guance logs |
241
+ | `<JSON_ATTRIBUTES>` | Additional data describing the Message, as a JSON object |
242
+ | `<STATUS>` | Log level, optional values `debug`,`info`,`warn`,`error`,`critical` |
243
+
244
+ ## Adding Custom TAG Data
245
+
246
+ ---
247
+
248
+ After initializing LOG, use the `setGlobalContextProperty(key:string, value:any)` API to add extra TAGs to all LOG events collected from the application.
249
+
250
+ ### Add TAG
251
+
252
+ === "CDN Synchronous"
253
+
254
+ ```javascript
255
+ window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.setGlobalContextProperty('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
256
+
257
+ // Code example
258
+ window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.setGlobalContextProperty('isvip', 'xxxx');
259
+ window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.setGlobalContextProperty('activity', {
260
+ hasPaid: true,
261
+ amount: 23.42
262
+ });
263
+ ```
264
+
265
+ === "CDN Asynchronous"
266
+
267
+ ```javascript
268
+ DATAFLUX_LOGS.onReady(function() {
269
+ DATAFLUX_LOGS.setGlobalContextProperty('<CONTEXT_KEY>', '<CONTEXT_VALUE>');
270
+ })
271
+
272
+ // Code example
273
+ DATAFLUX_LOGS.onReady(function() {
274
+ DATAFLUX_LOGS.setGlobalContextProperty('isvip', 'xxxx');
275
+ })
276
+ DATAFLUX_LOGS.onReady(function() {
277
+ DATAFLUX_LOGS.setGlobalContextProperty('activity', {
278
+ hasPaid: true,
279
+ amount: 23.42
280
+ });
281
+ })
282
+
283
+ ```
284
+
285
+ === "NPM"
286
+
287
+ ```javascript
288
+ import { datafluxLogs } from '@cloudcare/browser-logs'
289
+ datafluxLogs.setGlobalContextProperty('<CONTEXT_KEY>', <CONTEXT_VALUE>);
290
+
291
+ // Code example
292
+ datafluxLogs && datafluxLogs.setGlobalContextProperty('isvip', 'xxxx');
293
+ datafluxLogs.setGlobalContextProperty('activity', {
294
+ hasPaid: true,
295
+ amount: 23.42
296
+ });
297
+ ```
298
+
299
+ ### Replace TAG (Override)
300
+
301
+ === "CDN Synchronous"
302
+
303
+ ```javascript
304
+ window.DATAFLUX_LOGS &&
305
+ window.DATAFLUX_LOGS.setGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
306
+
307
+ // Code example
308
+ window.DATAFLUX_LOGS &&
309
+ window.DATAFLUX_LOGS.setGlobalContext({
310
+ codeVersion: 34,
311
+ });
312
+ ```
212
313
 
213
- | 参数 | 描述 |
214
- | -------------------- | ---------------------------------------------------------------- |
215
- | `<MESSAGE>` | Dataflux 日志中的 message 字段 |
216
- | `<JSON_ATTRIBUTES> ` | 描述message的额外数据,是一个json对象 |
217
- | `<STATUS> ` | 日志的等级,可选值:`debug`, `info`, `warn`, `error`, `critical` |
314
+ === "CDN Asynchronous"
315
+
316
+ ```javascript
317
+ window.DATAFLUX_LOGS.onReady(function() {
318
+ window.DATAFLUX_LOGS.setGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
319
+ })
320
+
321
+ // Code example
322
+ window.DATAFLUX_LOGS.onReady(function() {
323
+ window.DATAFLUX_LOGS.setGlobalContext({
324
+ codeVersion: 34,
325
+ })
326
+ })
327
+ ```
328
+
329
+ === "NPM"
330
+
331
+ ```javascript
332
+ import { datafluxLogs } from '@cloudcare/browser-logs'
333
+
334
+ datafluxLogs.setGlobalContext({ '<CONTEXT_KEY>': '<CONTEXT_VALUE>' });
335
+
336
+ // Code example
337
+ datafluxLogs.setGlobalContext({
338
+ codeVersion: 34,
339
+ });
340
+ ```
341
+
342
+ ### Get All Set Custom TAGs
343
+
344
+ === "CDN Synchronous"
345
+
346
+ ```javascript
347
+ var context = window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.getGlobalContext();
348
+
349
+ ```
350
+
351
+ === "CDN Asynchronous"
352
+
353
+ ```javascript
354
+ window.DATAFLUX_LOGS.onReady(function() {
355
+ var context = window.DATAFLUX_LOGS.getGlobalContext();
356
+ });
357
+ ```
358
+
359
+ === "NPM"
360
+
361
+ ```javascript
362
+ import { datafluxLogs } from '@cloudcare/browser-logs'
363
+
364
+ const context = datafluxLogs.getGlobalContext();
365
+
366
+ ```
367
+
368
+ ### Remove Specific Key Corresponding Custom TAG
369
+
370
+ === "CDN Synchronous"
371
+
372
+ ```javascript
373
+ var context = window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.removeGlobalContextProperty('<CONTEXT_KEY>');
374
+
375
+ ```
376
+
377
+ === "CDN Asynchronous"
378
+
379
+ ```javascript
380
+ window.DATAFLUX_LOGS.onReady(function() {
381
+ var context = window.DATAFLUX_LOGS.removeGlobalContextProperty('<CONTEXT_KEY>');
382
+ });
383
+ ```
384
+
385
+ === "NPM"
386
+
387
+ ```javascript
388
+ import { datafluxLogs } from '@cloudcare/browser-logs'
389
+
390
+ const context = datafluxLogs.removeGlobalContextProperty('<CONTEXT_KEY>');
391
+ ```
392
+
393
+ ### Remove All Custom TAGs
394
+
395
+ === "CDN Synchronous"
396
+
397
+ ```javascript
398
+ var context = window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.clearGlobalContext();
399
+
400
+ ```
401
+
402
+ === "CDN Asynchronous"
403
+
404
+ ```javascript
405
+ window.DATAFLUX_LOGS.onReady(function() {
406
+ var context = window.DATAFLUX_LOGS.clearGlobalContext();
407
+ });
408
+ ```
409
+
410
+ === "NPM"
411
+
412
+ ```javascript
413
+ import { datafluxLogs } from '@cloudcare/browser-logs'
414
+
415
+ const context = datafluxLogs.clearGlobalContext();
416
+ ```
417
+
418
+ ## Custom User Identification
419
+
420
+ ---
421
+
422
+ By default, the SDK automatically generates a unique ID for users. This ID has no identifying attributes and can only distinguish between different user properties. To address this, we provide additional APIs to add various identifying attributes to the current user.
423
+
424
+ | Attribute | Type | Description |
425
+ | ---------- | ------ | -------------------- |
426
+ | user.id | string | User ID |
427
+ | user.name | string | Username or Nickname |
428
+ | user.email | string | Email Address |
429
+
430
+ **Note**: The following attributes are optional, but it is recommended to provide at least one.
431
+
432
+ ### Add User Identification
433
+
434
+ === "CDN Synchronous"
435
+
436
+ ```javascript
437
+ window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.setUser({
438
+ id: '1234',
439
+ name: 'John Doe',
440
+ email: 'john@doe.com',
441
+ })
442
+ ```
443
+
444
+ === "CDN Asynchronous"
445
+
446
+ ```javascript
447
+ window.DATAFLUX_LOGS.onReady(function() {
448
+ window.DATAFLUX_LOGS.setUser({
449
+ id: '1234',
450
+ name: 'John Doe',
451
+ email: 'john@doe.com',
452
+ })
453
+ })
454
+ ```
455
+
456
+ === "NPM"
457
+
458
+ ```javascript
459
+ import { datafluxLogs } from '@cloudcare/browser-logs'
460
+ datafluxLogs.setUser({
461
+ id: '1234',
462
+ name: 'John Doe',
463
+ email: 'john@doe.com',
464
+ })
465
+ ```
466
+
467
+ ### Remove User Identification
468
+
469
+ === "CDN Synchronous"
470
+
471
+ ```javascript
472
+ window.DATAFLUX_LOGS && window.DATAFLUX_LOGS.clearUser()
473
+ ```
474
+
475
+ === "CDN Asynchronous"
476
+
477
+ ```javascript
478
+ window.DATAFLUX_LOGS.onReady(function() {
479
+ window.DATAFLUX_LOGS.clearUser()
480
+ })
481
+ ```
218
482
 
483
+ === "NPM"
219
484
 
485
+ ```javascript
486
+ import { datafluxLogs } from '@cloudcare/browser-logs'
487
+ datafluxLogs.clearUser()
488
+ ```