@cloudcare/browser-core 1.0.9 → 1.0.13

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.
@@ -83,7 +83,6 @@ function commonInit(userConfiguration, buildEnv) {
83
83
  sdkName: buildEnv.sdkName,
84
84
  datakitUrl: getDatakitUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
85
85
  logsEndpoint: getLogsEndPoint(userConfiguration.datakitOrigin),
86
- tags: userConfiguration.tags || [],
87
86
  isEnabled: function isEnabled(feature) {
88
87
  return (0, _tools.includes)(enableExperimentalFeatures, feature);
89
88
  },
@@ -106,7 +105,7 @@ function commonInit(userConfiguration, buildEnv) {
106
105
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
107
106
  }
108
107
 
109
- return (0, _tools.extend2Lev)(DEFAULT_CONFIGURATION, transportConfiguration);
108
+ return (0, _tools.extend2Lev)({}, DEFAULT_CONFIGURATION, transportConfiguration);
110
109
  }
111
110
 
112
111
  function mustUseSecureCookie(userConfiguration) {
package/cjs/dataMap.js CHANGED
@@ -13,7 +13,9 @@ var commonTags = {
13
13
  app_id: 'application.id',
14
14
  env: '_dd.env',
15
15
  version: '_dd.version',
16
- userid: 'user.user_id',
16
+ userid: 'user.id',
17
+ user_email: 'user.email',
18
+ user_name: 'user.name',
17
19
  session_id: 'session.id',
18
20
  session_type: 'session.type',
19
21
  is_signin: 'user.is_signin',
@@ -1805,13 +1805,21 @@ function createContextManager() {
1805
1805
  return context;
1806
1806
  },
1807
1807
  add: function add(key, value) {
1808
- context[key] = value;
1808
+ if (isString(key)) {
1809
+ context[key] = value;
1810
+ } else {
1811
+ console.error('key 需要传递字符串类型');
1812
+ }
1809
1813
  },
1810
1814
  remove: function remove(key) {
1811
1815
  delete context[key];
1812
1816
  },
1813
1817
  set: function set(newContext) {
1814
- context = newContext;
1818
+ if (isObject(newContext)) {
1819
+ context = newContext;
1820
+ } else {
1821
+ console.error('content 需要传递对象类型数据');
1822
+ }
1815
1823
  }
1816
1824
  };
1817
1825
  }
@@ -1879,7 +1887,12 @@ function toSnakeCase(word) {
1879
1887
  }
1880
1888
 
1881
1889
  function escapeRowData(str) {
1882
- if (!isString(str)) return str;
1890
+ if (_typeof(str) === 'object' && str) {
1891
+ str = jsonStringify(str);
1892
+ } else if (!isString(str)) {
1893
+ return str;
1894
+ }
1895
+
1883
1896
  var reg = /[\s=,"]/g;
1884
1897
  return String(str).replace(reg, function (word) {
1885
1898
  return '\\' + word;
@@ -50,7 +50,8 @@ function startSessionManagement(options, productKey, computeSessionState) {
50
50
  var anonymousCookie = cacheAnonymousID(options);
51
51
  var sessionCookie = (0, _cookie.cacheCookieAccess)(SESSION_COOKIE_NAME, options);
52
52
  var renewObservable = new _observable.Observable();
53
- var currentSessionId = retrieveActiveSession(sessionCookie).id;
53
+ var currentSession = retrieveActiveSession(sessionCookie);
54
+ var currentSessionId = currentSession.id;
54
55
  var expandOrRenewSession = (0, _tools.throttle)(function () {
55
56
  var session = retrieveActiveSession(sessionCookie);
56
57
  var state = computeSessionState(session[productKey]);
@@ -83,11 +84,44 @@ function startSessionManagement(options, productKey, computeSessionState) {
83
84
  return anonymousCookie.get();
84
85
  },
85
86
  getId: function getId() {
86
- return retrieveActiveSession(sessionCookie).id;
87
+ // 先获取debug id
88
+ var session = retrieveActiveSession(sessionCookie);
89
+ return session.did || session.id;
87
90
  },
88
91
  getTrackingType: function getTrackingType() {
89
92
  return retrieveActiveSession(sessionCookie)[productKey];
90
93
  },
94
+ getDebugSession: function getDebugSession() {
95
+ var session = retrieveActiveSession(sessionCookie);
96
+
97
+ if ((0, _tools.isEmptyObject)(session) || !session.did) {
98
+ return {};
99
+ }
100
+
101
+ return {
102
+ id: session.did,
103
+ created: session.dcreated
104
+ };
105
+ },
106
+ addDebugSession: function addDebugSession(id, created) {
107
+ var session = retrieveActiveSession(sessionCookie);
108
+
109
+ if (!(0, _tools.isEmptyObject)(session)) {
110
+ session.did = id || _tools.UUID;
111
+ session.dcreated = created || String(Date.now());
112
+ persistSession(session, sessionCookie);
113
+ }
114
+ },
115
+ clearDebugSession: function clearDebugSession() {
116
+ var session = retrieveActiveSession(sessionCookie);
117
+ var newSession = {};
118
+ (0, _tools.each)((0, _tools.objectEntries)(session), function (item) {
119
+ if (item[0] !== 'did' && item[0] !== 'dcreated') {
120
+ newSession[item[0]] = item[1];
121
+ }
122
+ });
123
+ persistSession(newSession, sessionCookie);
124
+ },
91
125
  renewObservable: renewObservable
92
126
  };
93
127
  }
package/cjs/transport.js CHANGED
@@ -13,6 +13,7 @@ var _dataMap = require("./dataMap");
13
13
 
14
14
  // https://en.wikipedia.org/wiki/UTF-8
15
15
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
16
+ var CUSTOM_KEYS = 'custom_keys';
16
17
 
17
18
  function addBatchPrecision(url) {
18
19
  if (!url) return url;
@@ -64,7 +65,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
64
65
  (0, _tools.each)(tags, function (value_path, _key) {
65
66
  var _value = (0, _tools.findByPath)(message, value_path);
66
67
 
67
- filterFileds.push(value_path);
68
+ filterFileds.push(_key);
68
69
 
69
70
  if (_value || (0, _tools.isNumber)(_value)) {
70
71
  rowData.tags[_key] = _value;
@@ -72,16 +73,26 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
72
73
  }
73
74
  });
74
75
 
75
- if (message.tags.length) {
76
+ if (message.tags && (0, _tools.isObject)(message.tags) && !(0, _tools.isEmptyObject)(message.tags)) {
76
77
  // 自定义tag
78
+ var _tagKeys = [];
77
79
  (0, _tools.each)(message.tags, function (_value, _key) {
80
+ // 如果和之前tag重名,则舍弃
81
+ if (filterFileds.indexOf(_key) > -1) return;
78
82
  filterFileds.push(_key);
79
83
 
80
84
  if (_value || (0, _tools.isNumber)(_value)) {
85
+ _tagKeys.push(_key);
86
+
81
87
  rowData.tags[_key] = _value;
82
88
  tagsStr.push((0, _tools.escapeRowData)(_key) + '=' + (0, _tools.escapeRowData)(_value));
83
89
  }
84
90
  });
91
+
92
+ if (_tagKeys.length) {
93
+ rowData.tags[CUSTOM_KEYS] = _tagKeys;
94
+ tagsStr.push((0, _tools.escapeRowData)(CUSTOM_KEYS) + '=' + (0, _tools.escapeRowData)(_tagKeys));
95
+ }
85
96
  }
86
97
 
87
98
  var fieldsStr = [];
@@ -92,7 +103,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
92
103
 
93
104
  var _valueData = (0, _tools.findByPath)(message, value_path);
94
105
 
95
- filterFileds.push(value_path);
106
+ filterFileds.push(_key);
96
107
 
97
108
  if (_valueData || (0, _tools.isNumber)(_valueData)) {
98
109
  rowData.fields[_key] = _valueData; // 这里不需要转译
@@ -103,7 +114,7 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
103
114
  } else if ((0, _tools.isString)(_value)) {
104
115
  var _valueData = (0, _tools.findByPath)(message, _value);
105
116
 
106
- filterFileds.push(_value);
117
+ filterFileds.push(_key);
107
118
 
108
119
  if (_valueData || (0, _tools.isNumber)(_valueData)) {
109
120
  rowData.fields[_key] = _valueData; // 这里不需要转译
package/cjs/xhrProxy.js CHANGED
@@ -85,6 +85,8 @@ function proxyXhr() {
85
85
  var hasBeenReported = false;
86
86
 
87
87
  var reportXhr = function reportXhr() {
88
+ _this.removeEventListener('loadend', reportXhr);
89
+
88
90
  if (hasBeenReported) {
89
91
  return;
90
92
  }
@@ -69,8 +69,9 @@ export function commonInit(userConfiguration, buildEnv) {
69
69
  sdkName: buildEnv.sdkName,
70
70
  datakitUrl: getDatakitUrl(userConfiguration.datakitUrl || userConfiguration.datakitOrigin),
71
71
  logsEndpoint: getLogsEndPoint(userConfiguration.datakitOrigin),
72
- tags: userConfiguration.tags || [],
73
- isEnabled: feature => includes(enableExperimentalFeatures, feature),
72
+ isEnabled: function isEnabled(feature) {
73
+ return includes(enableExperimentalFeatures, feature);
74
+ },
74
75
  cookieOptions: buildCookieOptions(userConfiguration)
75
76
  };
76
77
 
@@ -90,7 +91,7 @@ export function commonInit(userConfiguration, buildEnv) {
90
91
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
91
92
  }
92
93
 
93
- return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
94
+ return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration);
94
95
  }
95
96
 
96
97
  function mustUseSecureCookie(userConfiguration) {
package/esm/dataMap.js CHANGED
@@ -5,7 +5,9 @@ export var commonTags = {
5
5
  app_id: 'application.id',
6
6
  env: '_dd.env',
7
7
  version: '_dd.version',
8
- userid: 'user.user_id',
8
+ userid: 'user.id',
9
+ user_email: 'user.email',
10
+ user_name: 'user.name',
9
11
  session_id: 'session.id',
10
12
  session_type: 'session.type',
11
13
  is_signin: 'user.is_signin',
@@ -1530,13 +1530,21 @@ export function createContextManager() {
1530
1530
  return context;
1531
1531
  },
1532
1532
  add: function add(key, value) {
1533
- context[key] = value;
1533
+ if (isString(key)) {
1534
+ context[key] = value;
1535
+ } else {
1536
+ console.error('key 需要传递字符串类型');
1537
+ }
1534
1538
  },
1535
1539
  remove: function remove(key) {
1536
1540
  delete context[key];
1537
1541
  },
1538
1542
  set: function set(newContext) {
1539
- context = newContext;
1543
+ if (isObject(newContext)) {
1544
+ context = newContext;
1545
+ } else {
1546
+ console.error('content 需要传递对象类型数据');
1547
+ }
1540
1548
  }
1541
1549
  };
1542
1550
  }
@@ -1596,7 +1604,12 @@ export function toSnakeCase(word) {
1596
1604
  }).replace(/-/g, '_');
1597
1605
  }
1598
1606
  export function escapeRowData(str) {
1599
- if (!isString(str)) return str;
1607
+ if (typeof str === 'object' && str) {
1608
+ str = jsonStringify(str);
1609
+ } else if (!isString(str)) {
1610
+ return str;
1611
+ }
1612
+
1600
1613
  var reg = /[\s=,"]/g;
1601
1614
  return String(str).replace(reg, function (word) {
1602
1615
  return '\\' + word;
@@ -28,7 +28,8 @@ export function startSessionManagement(options, productKey, computeSessionState)
28
28
  var anonymousCookie = cacheAnonymousID(options);
29
29
  var sessionCookie = cacheCookieAccess(SESSION_COOKIE_NAME, options);
30
30
  var renewObservable = new Observable();
31
- var currentSessionId = retrieveActiveSession(sessionCookie).id;
31
+ var currentSession = retrieveActiveSession(sessionCookie);
32
+ var currentSessionId = currentSession.id;
32
33
  var expandOrRenewSession = throttle(function () {
33
34
  var session = retrieveActiveSession(sessionCookie);
34
35
  var state = computeSessionState(session[productKey]);
@@ -61,11 +62,44 @@ export function startSessionManagement(options, productKey, computeSessionState)
61
62
  return anonymousCookie.get();
62
63
  },
63
64
  getId: function getId() {
64
- return retrieveActiveSession(sessionCookie).id;
65
+ // 先获取debug id
66
+ var session = retrieveActiveSession(sessionCookie);
67
+ return session.did || session.id;
65
68
  },
66
69
  getTrackingType: function getTrackingType() {
67
70
  return retrieveActiveSession(sessionCookie)[productKey];
68
71
  },
72
+ getDebugSession: function getDebugSession() {
73
+ var session = retrieveActiveSession(sessionCookie);
74
+
75
+ if (isEmptyObject(session) || !session.did) {
76
+ return {};
77
+ }
78
+
79
+ return {
80
+ id: session.did,
81
+ created: session.dcreated
82
+ };
83
+ },
84
+ addDebugSession: function addDebugSession(id, created) {
85
+ var session = retrieveActiveSession(sessionCookie);
86
+
87
+ if (!isEmptyObject(session)) {
88
+ session.did = id || UUID;
89
+ session.dcreated = created || String(Date.now());
90
+ persistSession(session, sessionCookie);
91
+ }
92
+ },
93
+ clearDebugSession: function clearDebugSession() {
94
+ var session = retrieveActiveSession(sessionCookie);
95
+ var newSession = {};
96
+ each(objectEntries(session), function (item) {
97
+ if (item[0] !== 'did' && item[0] !== 'dcreated') {
98
+ newSession[item[0]] = item[1];
99
+ }
100
+ });
101
+ persistSession(newSession, sessionCookie);
102
+ },
69
103
  renewObservable: renewObservable
70
104
  };
71
105
  }
package/esm/transport.js CHANGED
@@ -1,8 +1,9 @@
1
- import { addEventListener, values, findByPath, escapeRowData, each, isNumber, isArray, extend, isString, keys, toServerDuration, isBoolean } from './helper/tools';
1
+ import { addEventListener, values, findByPath, escapeRowData, each, isNumber, isArray, extend, isString, toServerDuration, isBoolean, isEmptyObject, isObject } from './helper/tools';
2
2
  import { DOM_EVENT, RumEventType } from './helper/enums';
3
3
  import { commonTags, dataMap } from './dataMap'; // https://en.wikipedia.org/wiki/UTF-8
4
4
 
5
5
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/;
6
+ var CUSTOM_KEYS = 'custom_keys';
6
7
 
7
8
  function addBatchPrecision(url) {
8
9
  if (!url) return url;
@@ -52,7 +53,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
52
53
  each(tags, function (value_path, _key) {
53
54
  var _value = findByPath(message, value_path);
54
55
 
55
- filterFileds.push(value_path);
56
+ filterFileds.push(_key);
56
57
 
57
58
  if (_value || isNumber(_value)) {
58
59
  rowData.tags[_key] = _value;
@@ -60,16 +61,26 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
60
61
  }
61
62
  });
62
63
 
63
- if (message.tags.length) {
64
+ if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
64
65
  // 自定义tag
66
+ var _tagKeys = [];
65
67
  each(message.tags, function (_value, _key) {
68
+ // 如果和之前tag重名,则舍弃
69
+ if (filterFileds.indexOf(_key) > -1) return;
66
70
  filterFileds.push(_key);
67
71
 
68
72
  if (_value || isNumber(_value)) {
73
+ _tagKeys.push(_key);
74
+
69
75
  rowData.tags[_key] = _value;
70
76
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value));
71
77
  }
72
78
  });
79
+
80
+ if (_tagKeys.length) {
81
+ rowData.tags[CUSTOM_KEYS] = _tagKeys;
82
+ tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys));
83
+ }
73
84
  }
74
85
 
75
86
  var fieldsStr = [];
@@ -80,7 +91,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
80
91
 
81
92
  var _valueData = findByPath(message, value_path);
82
93
 
83
- filterFileds.push(value_path);
94
+ filterFileds.push(_key);
84
95
 
85
96
  if (_valueData || isNumber(_valueData)) {
86
97
  rowData.fields[_key] = _valueData; // 这里不需要转译
@@ -91,7 +102,7 @@ export var processedMessageByDataMap = function processedMessageByDataMap(messag
91
102
  } else if (isString(_value)) {
92
103
  var _valueData = findByPath(message, _value);
93
104
 
94
- filterFileds.push(_value);
105
+ filterFileds.push(_key);
95
106
 
96
107
  if (_valueData || isNumber(_valueData)) {
97
108
  rowData.fields[_key] = _valueData; // 这里不需要转译
package/esm/xhrProxy.js CHANGED
@@ -73,6 +73,8 @@ function proxyXhr() {
73
73
  var hasBeenReported = false;
74
74
 
75
75
  var reportXhr = function reportXhr() {
76
+ _this.removeEventListener('loadend', reportXhr);
77
+
76
78
  if (hasBeenReported) {
77
79
  return;
78
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-core",
3
- "version": "1.0.9",
3
+ "version": "1.0.13",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "scripts": {
@@ -14,12 +14,11 @@
14
14
  "sdk"
15
15
  ],
16
16
  "repository": {
17
- "url": "https://github.com/CloudCare/dataflux-rum-sdk-javascript",
17
+ "url": "https://github.com/DataFlux-cn/datakit-js",
18
18
  "type": "git"
19
19
  },
20
20
  "author": "dataflux",
21
21
  "license": "MIT",
22
- "homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
23
22
  "description": "DataFlux RUM Web 端数据指标监控",
24
- "gitHead": "9adc492491227f95b92dde62e19aa6492fe5370b"
23
+ "gitHead": "666c0183f62de2c65313ff5cc2be75843aa95c25"
25
24
  }
@@ -54,7 +54,8 @@ function getDatakitUrl(url) {
54
54
  return trim(url) + '/v1/write/rum'
55
55
  }
56
56
  function getLogsEndPoint(url) {
57
- if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/logging'
57
+ if (url.lastIndexOf('/') === url.length - 1)
58
+ return trim(url) + 'v1/write/logging'
58
59
  return trim(url) + '/v1/write/logging'
59
60
  }
60
61
  export function commonInit(userConfiguration, buildEnv) {
@@ -73,8 +74,7 @@ export function commonInit(userConfiguration, buildEnv) {
73
74
  userConfiguration.datakitUrl || userConfiguration.datakitOrigin
74
75
  ),
75
76
  logsEndpoint: getLogsEndPoint(userConfiguration.datakitOrigin),
76
- tags: userConfiguration.tags || [],
77
- isEnabled: (feature) => includes(enableExperimentalFeatures, feature),
77
+ isEnabled: function(feature) {return includes(enableExperimentalFeatures, feature)},
78
78
  cookieOptions: buildCookieOptions(userConfiguration)
79
79
  }
80
80
  if ('allowedDDTracingOrigins' in userConfiguration) {
@@ -94,7 +94,7 @@ export function commonInit(userConfiguration, buildEnv) {
94
94
  if ('trackInteractions' in userConfiguration) {
95
95
  transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions
96
96
  }
97
- return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration)
97
+ return extend2Lev({}, DEFAULT_CONFIGURATION, transportConfiguration)
98
98
  }
99
99
  function mustUseSecureCookie(userConfiguration) {
100
100
  return (
package/src/dataMap.js CHANGED
@@ -5,7 +5,9 @@ export var commonTags = {
5
5
  app_id: 'application.id',
6
6
  env: '_dd.env',
7
7
  version: '_dd.version',
8
- userid: 'user.user_id',
8
+ userid: 'user.id',
9
+ user_email: 'user.email',
10
+ user_name: 'user.name',
9
11
  session_id: 'session.id',
10
12
  session_type: 'session.type',
11
13
  is_signin: 'user.is_signin',
@@ -1507,7 +1507,11 @@ export function createContextManager() {
1507
1507
  },
1508
1508
 
1509
1509
  add: function (key, value) {
1510
- context[key] = value
1510
+ if (isString(key)) {
1511
+ context[key] = value
1512
+ } else {
1513
+ console.error('key 需要传递字符串类型')
1514
+ }
1511
1515
  },
1512
1516
 
1513
1517
  remove: function (key) {
@@ -1515,7 +1519,12 @@ export function createContextManager() {
1515
1519
  },
1516
1520
 
1517
1521
  set: function (newContext) {
1518
- context = newContext
1522
+ if (isObject(newContext)) {
1523
+ context = newContext
1524
+ } else {
1525
+ console.error('content 需要传递对象类型数据')
1526
+ }
1527
+
1519
1528
  }
1520
1529
  }
1521
1530
  }
@@ -1578,7 +1587,11 @@ export function toSnakeCase(word) {
1578
1587
  }
1579
1588
 
1580
1589
  export function escapeRowData(str) {
1581
- if (!isString(str)) return str
1590
+ if (typeof str === 'object' && str) {
1591
+ str = jsonStringify(str)
1592
+ } else if (!isString(str)) {
1593
+ return str
1594
+ }
1582
1595
  var reg = /[\s=,"]/g
1583
1596
  return String(str).replace(reg, function (word) {
1584
1597
  return '\\' + word
@@ -38,7 +38,8 @@ export function startSessionManagement(
38
38
  var anonymousCookie = cacheAnonymousID(options)
39
39
  var sessionCookie = cacheCookieAccess(SESSION_COOKIE_NAME, options)
40
40
  var renewObservable = new Observable()
41
- var currentSessionId = retrieveActiveSession(sessionCookie).id
41
+ var currentSession = retrieveActiveSession(sessionCookie)
42
+ var currentSessionId = currentSession.id
42
43
  var expandOrRenewSession = throttle(function () {
43
44
  var session = retrieveActiveSession(sessionCookie)
44
45
  var state = computeSessionState(session[productKey])
@@ -71,11 +72,41 @@ export function startSessionManagement(
71
72
  return anonymousCookie.get()
72
73
  },
73
74
  getId: function () {
74
- return retrieveActiveSession(sessionCookie).id
75
+ // 先获取debug id
76
+ var session = retrieveActiveSession(sessionCookie)
77
+ return session.did || session.id
75
78
  },
76
79
  getTrackingType: function () {
77
80
  return retrieveActiveSession(sessionCookie)[productKey]
78
81
  },
82
+ getDebugSession: function () {
83
+ var session = retrieveActiveSession(sessionCookie)
84
+ if (isEmptyObject(session) || !session.did) {
85
+ return {}
86
+ }
87
+ return {
88
+ id: session.did,
89
+ created: session.dcreated
90
+ }
91
+ },
92
+ addDebugSession: function (id, created) {
93
+ var session = retrieveActiveSession(sessionCookie)
94
+ if (!isEmptyObject(session)) {
95
+ session.did = id || UUID
96
+ session.dcreated = created || String(Date.now())
97
+ persistSession(session, sessionCookie)
98
+ }
99
+ },
100
+ clearDebugSession: function () {
101
+ var session = retrieveActiveSession(sessionCookie)
102
+ var newSession = {}
103
+ each(objectEntries(session), function (item) {
104
+ if (item[0] !== 'did' && item[0] !== 'dcreated') {
105
+ newSession[item[0]] = item[1]
106
+ }
107
+ })
108
+ persistSession(newSession, sessionCookie)
109
+ },
79
110
  renewObservable: renewObservable
80
111
  }
81
112
  }
package/src/transport.js CHANGED
@@ -8,14 +8,16 @@ import {
8
8
  isArray,
9
9
  extend,
10
10
  isString,
11
- keys,
12
11
  toServerDuration,
13
- isBoolean
12
+ isBoolean,
13
+ isEmptyObject,
14
+ isObject
14
15
  } from './helper/tools'
15
16
  import { DOM_EVENT, RumEventType } from './helper/enums'
16
17
  import { commonTags, dataMap } from './dataMap'
17
18
  // https://en.wikipedia.org/wiki/UTF-8
18
19
  var HAS_MULTI_BYTES_CHARACTERS = /[^\u0000-\u007F]/
20
+ var CUSTOM_KEYS = 'custom_keys'
19
21
  function addBatchPrecision(url) {
20
22
  if (!url) return url
21
23
  return url + (url.indexOf('?') === -1 ? '?' : '&') + 'precision=ms'
@@ -55,21 +57,29 @@ export var processedMessageByDataMap = function (message) {
55
57
  var filterFileds = ['date', 'type'] // 已经在datamap中定义过的fields和tags
56
58
  each(tags, function (value_path, _key) {
57
59
  var _value = findByPath(message, value_path)
58
- filterFileds.push(value_path)
60
+ filterFileds.push(_key)
59
61
  if (_value || isNumber(_value)) {
60
62
  rowData.tags[_key] = _value
61
63
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
62
64
  }
63
65
  })
64
- if (message.tags.length) {
66
+ if (message.tags && isObject(message.tags) && !isEmptyObject(message.tags)) {
65
67
  // 自定义tag
68
+ const _tagKeys = []
66
69
  each(message.tags, function (_value, _key) {
70
+ // 如果和之前tag重名,则舍弃
71
+ if (filterFileds.indexOf(_key) > -1) return
67
72
  filterFileds.push(_key)
68
73
  if (_value || isNumber(_value)) {
74
+ _tagKeys.push(_key)
69
75
  rowData.tags[_key] = _value
70
76
  tagsStr.push(escapeRowData(_key) + '=' + escapeRowData(_value))
71
77
  }
72
78
  })
79
+ if (_tagKeys.length) {
80
+ rowData.tags[CUSTOM_KEYS] = _tagKeys
81
+ tagsStr.push(escapeRowData(CUSTOM_KEYS) + '=' + escapeRowData(_tagKeys))
82
+ }
73
83
  }
74
84
  var fieldsStr = []
75
85
  each(value.fields, function (_value, _key) {
@@ -77,7 +87,7 @@ export var processedMessageByDataMap = function (message) {
77
87
  var type = _value[0],
78
88
  value_path = _value[1]
79
89
  var _valueData = findByPath(message, value_path)
80
- filterFileds.push(value_path)
90
+ filterFileds.push(_key)
81
91
  if (_valueData || isNumber(_valueData)) {
82
92
  rowData.fields[_key] = _valueData // 这里不需要转译
83
93
  _valueData =
@@ -90,7 +100,7 @@ export var processedMessageByDataMap = function (message) {
90
100
  }
91
101
  } else if (isString(_value)) {
92
102
  var _valueData = findByPath(message, _value)
93
- filterFileds.push(_value)
103
+ filterFileds.push(_key)
94
104
  if (_valueData || isNumber(_valueData)) {
95
105
  rowData.fields[_key] = _valueData // 这里不需要转译
96
106
  _valueData = escapeRowData(_valueData)
package/src/xhrProxy.js CHANGED
@@ -71,6 +71,7 @@ function proxyXhr() {
71
71
 
72
72
  var hasBeenReported = false
73
73
  var reportXhr = function () {
74
+ _this.removeEventListener('loadend', reportXhr)
74
75
  if (hasBeenReported) {
75
76
  return
76
77
  }