@cloudcare/rum-uniapp 2.1.4 → 2.1.7

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildEnv = void 0;
7
7
  var buildEnv = {
8
- sdkVersion: '2.1.4',
8
+ sdkVersion: '2.1.7',
9
9
  sdkName: 'df_uniapp_rum_sdk'
10
10
  };
11
11
  exports.buildEnv = buildEnv;
@@ -45,6 +45,11 @@ var makeRum = function makeRum(startRumImpl) {
45
45
  addActionStrategy = _startRumImpl.addAction;
46
46
  isAlreadyInitialized = true;
47
47
  },
48
+ initVue3: function initVue3(userConfiguration) {
49
+ this.init({}, (0, _utils.extend)({
50
+ isVue2: false
51
+ }, userConfiguration));
52
+ },
48
53
  getInternalContext: function getInternalContext(startTime) {
49
54
  return _getInternalContext(startTime);
50
55
  },
@@ -37,8 +37,9 @@ var DEFAULT_CONFIGURATION = {
37
37
  trackInteractions: false,
38
38
  traceType: _enums.TraceType.DDTRACE,
39
39
  traceId128Bit: false,
40
- allowedTracingOrigins: [] // 新增
41
-
40
+ allowedTracingOrigins: [],
41
+ // 新增
42
+ isVue2: true
42
43
  };
43
44
  exports.DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION;
44
45
 
@@ -82,6 +83,10 @@ function commonInit(userConfiguration, buildEnv) {
82
83
  transportConfiguration.sampleRate = userConfiguration.sampleRate;
83
84
  }
84
85
 
86
+ if ('isVue2' in userConfiguration) {
87
+ transportConfiguration.isVue2 = userConfiguration.isVue2;
88
+ }
89
+
85
90
  return (0, _utils.extend2Lev)(DEFAULT_CONFIGURATION, transportConfiguration);
86
91
  }
87
92
 
@@ -12,14 +12,16 @@ var _utils = require("../helper/utils");
12
12
 
13
13
  var _enums = require("../helper/enums");
14
14
 
15
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
16
+
15
17
  var downloadProxySingleton;
16
18
  var beforeSendCallbacks = [];
17
19
  var onRequestCompleteCallbacks = [];
18
20
  var originalDownloadRequest;
19
21
 
20
- function startDownloadProxy() {
22
+ function startDownloadProxy(userConfiguration) {
21
23
  if (!downloadProxySingleton) {
22
- proxyDownload();
24
+ proxyDownload(userConfiguration);
23
25
  downloadProxySingleton = {
24
26
  beforeSend: function beforeSend(callback) {
25
27
  beforeSendCallbacks.push(callback);
@@ -42,7 +44,7 @@ function resetDownloadProxy() {
42
44
  }
43
45
  }
44
46
 
45
- function proxyDownload() {
47
+ function proxyDownload(userConfiguration) {
46
48
  originalDownloadRequest = _sdk.sdk.downloadFile;
47
49
 
48
50
  _sdk.sdk.downloadFile = function () {
@@ -58,23 +60,27 @@ function proxyDownload() {
58
60
  dataflux_xhr.startTime = (0, _utils.now)();
59
61
  var originalSuccess = arguments[0].success;
60
62
 
61
- arguments[0].success = function () {
62
- reportXhr(arguments[0]);
63
+ if (typeof originalSuccess === 'function') {
64
+ arguments[0].success = function () {
65
+ reportXhr(arguments[0]);
63
66
 
64
- if (originalSuccess) {
65
- originalSuccess.apply(_this, arguments);
66
- }
67
- };
67
+ if (originalSuccess) {
68
+ originalSuccess.apply(_this, arguments);
69
+ }
70
+ };
71
+ }
68
72
 
69
73
  var originalFail = arguments[0].fail;
70
74
 
71
- arguments[0].fail = function () {
72
- reportXhr(arguments[0]);
75
+ if (typeof originalFail === 'function') {
76
+ arguments[0].fail = function () {
77
+ reportXhr(arguments[0]);
73
78
 
74
- if (originalFail) {
75
- originalFail.apply(_this, arguments);
76
- }
77
- };
79
+ if (originalFail) {
80
+ originalFail.apply(_this, arguments);
81
+ }
82
+ };
83
+ }
78
84
 
79
85
  var hasBeenReported = false;
80
86
 
@@ -100,6 +106,35 @@ function proxyDownload() {
100
106
  beforeSendCallbacks.forEach(function (callback) {
101
107
  callback(dataflux_xhr);
102
108
  });
103
- return originalDownloadRequest.apply(this, arguments);
109
+ var result = originalDownloadRequest.apply(this, arguments); // 判断结果是否为promise
110
+
111
+ var isPromise = function isPromise(obj) {
112
+ return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
113
+ };
114
+
115
+ if (isPromise(result) && userConfiguration.isVue2) {
116
+ // vue2 版本,success, fail 都在then返回
117
+ return result.then(function (res) {
118
+ if (res[0]) {
119
+ reportXhr(res[0]);
120
+ } else {
121
+ reportXhr(res[1]);
122
+ }
123
+
124
+ return res;
125
+ });
126
+ } else if (isPromise(result) && !userConfiguration.isVue2) {
127
+ return new Promise(function (resolve, reject) {
128
+ result.then(function (res) {
129
+ reportXhr(res);
130
+ resolve(res);
131
+ })["catch"](function (err) {
132
+ reportXhr(err);
133
+ reject(err);
134
+ });
135
+ });
136
+ } else {
137
+ return result;
138
+ }
104
139
  };
105
140
  }
@@ -120,10 +120,10 @@ function startAutomaticErrorCollection(configuration) {
120
120
  }
121
121
 
122
122
  function trackNetworkError(configuration, errorObservable) {
123
- (0, _xhrProxy.startXhrProxy)().onRequestComplete(function (context) {
123
+ (0, _xhrProxy.startXhrProxy)(configuration).onRequestComplete(function (context) {
124
124
  return handleCompleteRequest(context.type, context);
125
125
  });
126
- (0, _downloadProxy.startDownloadProxy)().onRequestComplete(function (context) {
126
+ (0, _downloadProxy.startDownloadProxy)(configuration).onRequestComplete(function (context) {
127
127
  return handleCompleteRequest(context.type, context);
128
128
  });
129
129
 
@@ -12,14 +12,16 @@ var _utils = require("../helper/utils");
12
12
 
13
13
  var _enums = require("../helper/enums");
14
14
 
15
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
16
+
15
17
  var xhrProxySingleton;
16
18
  var beforeSendCallbacks = [];
17
19
  var onRequestCompleteCallbacks = [];
18
20
  var originalXhrRequest;
19
21
 
20
- function startXhrProxy() {
22
+ function startXhrProxy(userConfiguration) {
21
23
  if (!xhrProxySingleton) {
22
- proxyXhr();
24
+ proxyXhr(userConfiguration);
23
25
  xhrProxySingleton = {
24
26
  beforeSend: function beforeSend(callback) {
25
27
  beforeSendCallbacks.push(callback);
@@ -42,7 +44,7 @@ function resetXhrProxy() {
42
44
  }
43
45
  }
44
46
 
45
- function proxyXhr() {
47
+ function proxyXhr(userConfiguration) {
46
48
  originalXhrRequest = _sdk.sdk.request;
47
49
 
48
50
  _sdk.sdk.request = function () {
@@ -59,23 +61,27 @@ function proxyXhr() {
59
61
  dataflux_xhr.startTime = (0, _utils.now)();
60
62
  var originalSuccess = arguments[0].success;
61
63
 
62
- arguments[0].success = function () {
63
- reportXhr(arguments[0]);
64
+ if (typeof originalSuccess === 'function') {
65
+ arguments[0].success = function () {
66
+ reportXhr(arguments[0]);
64
67
 
65
- if (originalSuccess) {
66
- originalSuccess.apply(_this, arguments);
67
- }
68
- };
68
+ if (originalSuccess) {
69
+ originalSuccess.apply(_this, arguments);
70
+ }
71
+ };
72
+ }
69
73
 
70
74
  var originalFail = arguments[0].fail;
71
75
 
72
- arguments[0].fail = function () {
73
- reportXhr(arguments[0]);
76
+ if (typeof originalFail === 'function') {
77
+ arguments[0].fail = function () {
78
+ reportXhr(arguments[0]);
74
79
 
75
- if (originalFail) {
76
- originalFail.apply(_this, arguments);
77
- }
78
- };
80
+ if (originalFail) {
81
+ originalFail.apply(_this, arguments);
82
+ }
83
+ };
84
+ }
79
85
 
80
86
  var hasBeenReported = false;
81
87
 
@@ -98,6 +104,35 @@ function proxyXhr() {
98
104
  beforeSendCallbacks.forEach(function (callback) {
99
105
  callback(dataflux_xhr);
100
106
  });
101
- return originalXhrRequest.call(this, dataflux_xhr.option);
107
+ var result = originalXhrRequest.call(this, dataflux_xhr.option); // 判断结果是否为promise
108
+
109
+ var isPromise = function isPromise(obj) {
110
+ return !!obj && (_typeof(obj) === "object" || typeof obj === "function") && typeof obj.then === "function";
111
+ };
112
+
113
+ if (isPromise(result) && userConfiguration.isVue2) {
114
+ // vue2 版本,success, fail 都在then返回
115
+ return result.then(function (res) {
116
+ if (res[0]) {
117
+ reportXhr(res[0]);
118
+ } else {
119
+ reportXhr(res[1]);
120
+ }
121
+
122
+ return res;
123
+ });
124
+ } else if (isPromise(result) && !userConfiguration.isVue2) {
125
+ return new Promise(function (resolve, reject) {
126
+ result.then(function (res) {
127
+ reportXhr(res);
128
+ resolve(res);
129
+ })["catch"](function (err) {
130
+ reportXhr(err);
131
+ reject(err);
132
+ });
133
+ });
134
+ } else {
135
+ return result;
136
+ }
102
137
  };
103
138
  }
@@ -15,57 +15,41 @@ var _trackPageActiveites = require("../trackPageActiveites");
15
15
 
16
16
  var _enums = require("../../helper/enums");
17
17
 
18
+ var _sdk = require("../../core/sdk");
19
+
20
+ var WHITE_METHOD = ['setup'];
21
+
18
22
  function trackActions(lifeCycle, Vue) {
19
23
  var action = startActionManagement(lifeCycle); // New views trigger the discard of the current pending Action
20
24
 
21
25
  lifeCycle.subscribe(_lifeCycle.LifeCycleEventType.VIEW_CREATED, function () {
22
26
  action.discardCurrent();
23
27
  });
24
- var originVueExtend = Vue.extend;
25
-
26
- Vue.extend = function (vueOptions) {
27
- // methods 方法
28
- if (vueOptions.methods) {
29
- var vueMethods = Object.keys(vueOptions.methods);
30
- vueMethods.forEach(function (methodName) {
31
- clickProxy(vueOptions.methods, methodName, function (_action) {
32
- action.create(_action.type, _action.name);
33
- }, lifeCycle);
34
- });
35
- }
36
28
 
37
- var originMethods = (0, _utils.getMethods)(vueOptions);
38
- originMethods.forEach(function (methodName) {
39
- clickProxy(vueOptions, methodName, function (_action) {
40
- action.create(_action.type, _action.name);
41
- }, lifeCycle);
42
- });
43
- return originVueExtend.call(this, vueOptions);
44
- }; // var originPage = Page
45
- // Page = function (page) {
46
- // const methods = getMethods(page)
47
- // methods.forEach((methodName) => {
48
- // clickProxy(
49
- // page,
50
- // methodName,
51
- // function (_action) {
52
- // action.create(_action.type, _action.name)
53
- // },
54
- // lifeCycle,
55
- // )
56
- // })
57
- // return originPage(page)
58
- // }
59
- // var originComponent = Component
60
- // Component = function (component) {
61
- // const methods = getMethods(component)
62
- // methods.forEach((methodName) => {
63
- // clickProxy(component, methodName, function (_action) {
64
- // action.create(_action.type, _action.name)
65
- // })
66
- // })
67
- // return originComponent(component)
68
- // }
29
+ if (Vue && Vue.extend) {
30
+ var originVueExtend = Vue.extend;
31
+
32
+ Vue.extend = function (vueOptions) {
33
+ proxyInstance(vueOptions, action, lifeCycle);
34
+ return originVueExtend.call(this, vueOptions);
35
+ };
36
+ } else {
37
+ if (!_sdk.tracker) return;
38
+ var originCreatePage = _sdk.tracker.createPage;
39
+
40
+ _sdk.tracker.createPage = function (page) {
41
+ // methods 方法
42
+ proxyInstance(page, action, lifeCycle);
43
+ return originCreatePage.call(this, page);
44
+ };
45
+
46
+ var originCreateComponent = _sdk.tracker.createComponent;
47
+
48
+ _sdk.tracker.createComponent = function (component) {
49
+ proxyInstance(component, action, lifeCycle);
50
+ return originCreateComponent.call(this, component);
51
+ };
52
+ } // var originVueExtend = Vue.extend
69
53
 
70
54
 
71
55
  return {
@@ -75,11 +59,31 @@ function trackActions(lifeCycle, Vue) {
75
59
  };
76
60
  }
77
61
 
78
- function clickProxy(page, methodName, callback, lifeCycle) {
79
- var oirginMethod = page[methodName];
62
+ function proxyInstance(options, action, lifeCycle) {
63
+ // methods 方法
64
+ if (options.methods) {
65
+ var vueMethods = Object.keys(options.methods);
66
+ vueMethods.forEach(function (methodName) {
67
+ clickProxy(options.methods, methodName, function (_action) {
68
+ action.create(_action.type, _action.name);
69
+ }, lifeCycle);
70
+ });
71
+ }
72
+
73
+ var originMethods = (0, _utils.getMethods)(options);
74
+ originMethods.forEach(function (methodName) {
75
+ clickProxy(options, methodName, function (_action) {
76
+ action.create(_action.type, _action.name);
77
+ }, lifeCycle);
78
+ });
79
+ }
80
+
81
+ function clickProxy(origin, methodName, callback, lifeCycle) {
82
+ if (WHITE_METHOD.indexOf(methodName) > -1) return;
83
+ var originMethod = origin[methodName];
80
84
 
81
- page[methodName] = function () {
82
- var result = oirginMethod.apply(this, arguments);
85
+ origin[methodName] = function () {
86
+ var result = originMethod.apply(this, arguments);
83
87
  var action = {};
84
88
 
85
89
  if ((0, _utils.isObject)(arguments[0])) {
@@ -12,51 +12,64 @@ var _trackEventCounts2 = require("../trackEventCounts");
12
12
 
13
13
  var _lifeCycle = require("../../core/lifeCycle");
14
14
 
15
- var _sdk = require("../../core/sdk");
16
-
17
15
  // 劫持原小程序App方法
18
16
  var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
19
17
  exports.THROTTLE_VIEW_UPDATE_PERIOD = THROTTLE_VIEW_UPDATE_PERIOD;
20
18
 
21
- function rewritePage(configuration, lifeCycle, Vue) {
22
- var originVueExtend = Vue.extend;
23
-
24
- Vue.extend = function (vueOptions) {
25
- // 合并方法,插入记录脚本
26
- var currentView,
27
- startTime = (0, _utils.now)();
28
- ['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(function (methodName) {
29
- var userDefinedMethod = vueOptions[methodName];
30
-
31
- vueOptions[methodName] = function () {
32
- if (this.mpType !== 'page') {
33
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
34
- } // 只处理page类型
35
-
36
-
37
- if (methodName === 'onShow' || methodName === 'onLoad') {
38
- if (typeof currentView === 'undefined') {
39
- var activePage = (0, _utils.getActivePage)();
40
- currentView = newView(lifeCycle, activePage && activePage.route, startTime);
41
- }
19
+ function proxyPage(pageOptions, lifeCycle) {
20
+ // 合并方法,插入记录脚本
21
+ var currentView,
22
+ startTime = (0, _utils.now)();
23
+ ['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(function (methodName) {
24
+ var userDefinedMethod = pageOptions[methodName];
25
+
26
+ pageOptions[methodName] = function () {
27
+ var mpType = this.mpType || this.$vm.mpType;
28
+
29
+ if (mpType !== 'page') {
30
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
31
+ } // 只处理page类型
32
+
33
+
34
+ if (methodName === 'onShow' || methodName === 'onLoad') {
35
+ if (typeof currentView === 'undefined') {
36
+ var activePage = (0, _utils.getActivePage)();
37
+ currentView = newView(lifeCycle, activePage && activePage.route, startTime);
42
38
  }
39
+ }
43
40
 
44
- currentView && currentView.setLoadEventEnd(methodName);
41
+ currentView && currentView.setLoadEventEnd(methodName);
45
42
 
46
- if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
47
- currentView.triggerUpdate();
43
+ if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
44
+ currentView.triggerUpdate();
48
45
 
49
- if (methodName === 'onUnload' || methodName === 'onHide') {
50
- currentView.end();
51
- currentView = undefined;
52
- }
46
+ if (methodName === 'onUnload' || methodName === 'onHide') {
47
+ currentView.end();
48
+ currentView = undefined;
53
49
  }
50
+ }
54
51
 
55
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
56
- };
57
- });
58
- return originVueExtend.call(this, vueOptions);
59
- };
52
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
53
+ };
54
+ });
55
+ }
56
+
57
+ function rewritePage(configuration, lifeCycle, Vue) {
58
+ if (Vue && Vue.extend) {
59
+ var originVueExtend = Vue.extend;
60
+
61
+ Vue.extend = function (vueOptions) {
62
+ proxyPage(vueOptions, lifeCycle);
63
+ return originVueExtend.call(this, vueOptions);
64
+ };
65
+ } else {
66
+ var originComponent = Component;
67
+
68
+ Component = function Component(pageOptions) {
69
+ proxyPage(pageOptions.methods, lifeCycle);
70
+ return originComponent.call(this, pageOptions);
71
+ };
72
+ }
60
73
  }
61
74
 
62
75
  function newView(lifeCycle, route, startTime) {
@@ -47,7 +47,7 @@ function getHeaderString(header) {
47
47
  }
48
48
 
49
49
  function trackXhr(lifeCycle, configuration, tracer) {
50
- var xhrProxy = (0, _xhrProxy.startXhrProxy)();
50
+ var xhrProxy = (0, _xhrProxy.startXhrProxy)(configuration);
51
51
  xhrProxy.beforeSend(function (context) {
52
52
  if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
53
53
  tracer.traceXhr(context);
@@ -79,7 +79,7 @@ function trackXhr(lifeCycle, configuration, tracer) {
79
79
  }
80
80
 
81
81
  function trackDownload(lifeCycle, configuration) {
82
- var dwonloadProxy = (0, _downloadProxy.startDownloadProxy)();
82
+ var dwonloadProxy = (0, _downloadProxy.startDownloadProxy)(configuration);
83
83
  dwonloadProxy.beforeSend(function (context) {
84
84
  if ((0, _resourceUtils.isAllowedRequestUrl)(configuration, context.url)) {
85
85
  context.requestIndex = getNextRequestIndex();
@@ -9,6 +9,8 @@ var _lifeCycle = require("../core/lifeCycle");
9
9
 
10
10
  var _utils = require("../helper/utils");
11
11
 
12
+ var _sdk = require("../core/sdk");
13
+
12
14
  function resetSetData(data, callback, lifeCycle, mpInstance) {
13
15
  var pendingStartTimestamp = (0, _utils.now)();
14
16
 
@@ -26,36 +28,56 @@ function resetSetData(data, callback, lifeCycle, mpInstance) {
26
28
  return _callback;
27
29
  }
28
30
 
29
- function startSetDataColloction(lifeCycle, Vue) {
30
- var originVueExtend = Vue.extend;
31
-
32
- Vue.extend = function (vueOptions) {
33
- var userDefinedMethod = vueOptions['onLoad'];
31
+ function proxyPage(pageOptions, lifeCycle) {
32
+ var userDefinedMethod = pageOptions['onLoad'];
34
33
 
35
- vueOptions['onLoad'] = function () {
36
- var mpInstance = this.$scope;
37
- var setData = mpInstance.setData; // 重写setData
34
+ pageOptions['onLoad'] = function () {
35
+ var mpInstance = this.$scope;
36
+ var setData = mpInstance.setData;
38
37
 
39
- if (typeof setData === 'function') {
40
- try {
41
- // 这里暂时这么处理 只读属性 会抛出错误
42
- mpInstance.setData = function (data, callback) {
38
+ if (typeof setData === 'function') {
39
+ try {
40
+ // 这里暂时这么处理 只读属性 会抛出错误
41
+ mpInstance.setData = function (data, callback) {
42
+ return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
43
+ };
44
+ } catch (err) {
45
+ Object.defineProperty(mpInstance.__proto__, 'setData', {
46
+ configurable: false,
47
+ enumerable: false,
48
+ value: function value(data, callback) {
43
49
  return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
44
- };
45
- } catch (err) {
46
- Object.defineProperty(mpInstance.__proto__, 'setData', {
47
- configurable: false,
48
- enumerable: false,
49
- value: function value(data, callback) {
50
- return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
51
- }
52
- });
53
- }
50
+ }
51
+ });
54
52
  }
53
+ }
54
+
55
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
56
+ };
57
+ }
55
58
 
56
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
59
+ function startSetDataColloction(lifeCycle, Vue) {
60
+ if (Vue && Vue.extend) {
61
+ var originVueExtend = Vue.extend;
62
+
63
+ Vue.extend = function (vueOptions) {
64
+ proxyPage(vueOptions, lifeCycle);
65
+ return originVueExtend.call(this, vueOptions);
57
66
  };
67
+ } else {
68
+ if (!_sdk.tracker) return;
69
+ var originCreatePage = _sdk.tracker.createPage;
58
70
 
59
- return originVueExtend.call(this, vueOptions);
60
- };
71
+ _sdk.tracker.createPage = function (pageOptions) {
72
+ proxyPage(pageOptions, lifeCycle);
73
+ return originCreatePage.call(this, pageOptions);
74
+ };
75
+
76
+ var originCreateComponent = _sdk.tracker.createComponent;
77
+
78
+ _sdk.tracker.createComponent = function (component) {
79
+ proxyPage(component, lifeCycle);
80
+ return originCreateComponent.call(this, component);
81
+ };
82
+ }
61
83
  }
@@ -1,4 +1,4 @@
1
1
  export var buildEnv = {
2
- sdkVersion: '2.1.4',
2
+ sdkVersion: '2.1.7',
3
3
  sdkName: 'df_uniapp_rum_sdk'
4
4
  };
@@ -1,4 +1,4 @@
1
- import { isPercentage, extend2Lev, now, createContextManager, defineGlobal, getGlobalObject, isString, isObject } from '../helper/utils';
1
+ import { isPercentage, extend2Lev, extend, now, createContextManager, defineGlobal, getGlobalObject, isString, isObject } from '../helper/utils';
2
2
  import { startRum } from './rum';
3
3
  import { ActionType } from '../helper/enums';
4
4
  export var makeRum = function makeRum(startRumImpl) {
@@ -33,6 +33,11 @@ export var makeRum = function makeRum(startRumImpl) {
33
33
  addActionStrategy = _startRumImpl.addAction;
34
34
  isAlreadyInitialized = true;
35
35
  },
36
+ initVue3: function initVue3(userConfiguration) {
37
+ this.init({}, extend({
38
+ isVue2: false
39
+ }, userConfiguration));
40
+ },
36
41
  getInternalContext: function getInternalContext(startTime) {
37
42
  return _getInternalContext(startTime);
38
43
  },
@@ -26,8 +26,9 @@ export var DEFAULT_CONFIGURATION = {
26
26
  trackInteractions: false,
27
27
  traceType: TraceType.DDTRACE,
28
28
  traceId128Bit: false,
29
- allowedTracingOrigins: [] // 新增
30
-
29
+ allowedTracingOrigins: [],
30
+ // 新增
31
+ isVue2: true
31
32
  };
32
33
 
33
34
  function trim(str) {
@@ -70,6 +71,10 @@ export function commonInit(userConfiguration, buildEnv) {
70
71
  transportConfiguration.sampleRate = userConfiguration.sampleRate;
71
72
  }
72
73
 
74
+ if ('isVue2' in userConfiguration) {
75
+ transportConfiguration.isVue2 = userConfiguration.isVue2;
76
+ }
77
+
73
78
  return extend2Lev(DEFAULT_CONFIGURATION, transportConfiguration);
74
79
  }
75
80
 
@@ -5,9 +5,9 @@ var downloadProxySingleton;
5
5
  var beforeSendCallbacks = [];
6
6
  var onRequestCompleteCallbacks = [];
7
7
  var originalDownloadRequest;
8
- export function startDownloadProxy() {
8
+ export function startDownloadProxy(userConfiguration) {
9
9
  if (!downloadProxySingleton) {
10
- proxyDownload();
10
+ proxyDownload(userConfiguration);
11
11
  downloadProxySingleton = {
12
12
  beforeSend: function beforeSend(callback) {
13
13
  beforeSendCallbacks.push(callback);
@@ -29,7 +29,7 @@ export function resetDownloadProxy() {
29
29
  }
30
30
  }
31
31
 
32
- function proxyDownload() {
32
+ function proxyDownload(userConfiguration) {
33
33
  originalDownloadRequest = sdk.downloadFile;
34
34
 
35
35
  sdk.downloadFile = function () {
@@ -45,23 +45,27 @@ function proxyDownload() {
45
45
  dataflux_xhr.startTime = now();
46
46
  var originalSuccess = arguments[0].success;
47
47
 
48
- arguments[0].success = function () {
49
- reportXhr(arguments[0]);
48
+ if (typeof originalSuccess === 'function') {
49
+ arguments[0].success = function () {
50
+ reportXhr(arguments[0]);
50
51
 
51
- if (originalSuccess) {
52
- originalSuccess.apply(_this, arguments);
53
- }
54
- };
52
+ if (originalSuccess) {
53
+ originalSuccess.apply(_this, arguments);
54
+ }
55
+ };
56
+ }
55
57
 
56
58
  var originalFail = arguments[0].fail;
57
59
 
58
- arguments[0].fail = function () {
59
- reportXhr(arguments[0]);
60
+ if (typeof originalFail === 'function') {
61
+ arguments[0].fail = function () {
62
+ reportXhr(arguments[0]);
60
63
 
61
- if (originalFail) {
62
- originalFail.apply(_this, arguments);
63
- }
64
- };
64
+ if (originalFail) {
65
+ originalFail.apply(_this, arguments);
66
+ }
67
+ };
68
+ }
65
69
 
66
70
  var hasBeenReported = false;
67
71
 
@@ -87,6 +91,35 @@ function proxyDownload() {
87
91
  beforeSendCallbacks.forEach(function (callback) {
88
92
  callback(dataflux_xhr);
89
93
  });
90
- return originalDownloadRequest.apply(this, arguments);
94
+ var result = originalDownloadRequest.apply(this, arguments); // 判断结果是否为promise
95
+
96
+ var isPromise = function isPromise(obj) {
97
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
98
+ };
99
+
100
+ if (isPromise(result) && userConfiguration.isVue2) {
101
+ // vue2 版本,success, fail 都在then返回
102
+ return result.then(function (res) {
103
+ if (res[0]) {
104
+ reportXhr(res[0]);
105
+ } else {
106
+ reportXhr(res[1]);
107
+ }
108
+
109
+ return res;
110
+ });
111
+ } else if (isPromise(result) && !userConfiguration.isVue2) {
112
+ return new Promise(function (resolve, reject) {
113
+ result.then(function (res) {
114
+ reportXhr(res);
115
+ resolve(res);
116
+ }).catch(function (err) {
117
+ reportXhr(err);
118
+ reject(err);
119
+ });
120
+ });
121
+ } else {
122
+ return result;
123
+ }
91
124
  };
92
125
  }
@@ -91,10 +91,10 @@ export function startAutomaticErrorCollection(configuration) {
91
91
  return errorObservable;
92
92
  }
93
93
  export function trackNetworkError(configuration, errorObservable) {
94
- startXhrProxy().onRequestComplete(function (context) {
94
+ startXhrProxy(configuration).onRequestComplete(function (context) {
95
95
  return handleCompleteRequest(context.type, context);
96
96
  });
97
- startDownloadProxy().onRequestComplete(function (context) {
97
+ startDownloadProxy(configuration).onRequestComplete(function (context) {
98
98
  return handleCompleteRequest(context.type, context);
99
99
  });
100
100
 
@@ -5,9 +5,9 @@ var xhrProxySingleton;
5
5
  var beforeSendCallbacks = [];
6
6
  var onRequestCompleteCallbacks = [];
7
7
  var originalXhrRequest;
8
- export function startXhrProxy() {
8
+ export function startXhrProxy(userConfiguration) {
9
9
  if (!xhrProxySingleton) {
10
- proxyXhr();
10
+ proxyXhr(userConfiguration);
11
11
  xhrProxySingleton = {
12
12
  beforeSend: function beforeSend(callback) {
13
13
  beforeSendCallbacks.push(callback);
@@ -29,7 +29,7 @@ export function resetXhrProxy() {
29
29
  }
30
30
  }
31
31
 
32
- function proxyXhr() {
32
+ function proxyXhr(userConfiguration) {
33
33
  originalXhrRequest = sdk.request;
34
34
 
35
35
  sdk.request = function () {
@@ -46,23 +46,27 @@ function proxyXhr() {
46
46
  dataflux_xhr.startTime = now();
47
47
  var originalSuccess = arguments[0].success;
48
48
 
49
- arguments[0].success = function () {
50
- reportXhr(arguments[0]);
49
+ if (typeof originalSuccess === 'function') {
50
+ arguments[0].success = function () {
51
+ reportXhr(arguments[0]);
51
52
 
52
- if (originalSuccess) {
53
- originalSuccess.apply(_this, arguments);
54
- }
55
- };
53
+ if (originalSuccess) {
54
+ originalSuccess.apply(_this, arguments);
55
+ }
56
+ };
57
+ }
56
58
 
57
59
  var originalFail = arguments[0].fail;
58
60
 
59
- arguments[0].fail = function () {
60
- reportXhr(arguments[0]);
61
+ if (typeof originalFail === 'function') {
62
+ arguments[0].fail = function () {
63
+ reportXhr(arguments[0]);
61
64
 
62
- if (originalFail) {
63
- originalFail.apply(_this, arguments);
64
- }
65
- };
65
+ if (originalFail) {
66
+ originalFail.apply(_this, arguments);
67
+ }
68
+ };
69
+ }
66
70
 
67
71
  var hasBeenReported = false;
68
72
 
@@ -85,6 +89,35 @@ function proxyXhr() {
85
89
  beforeSendCallbacks.forEach(function (callback) {
86
90
  callback(dataflux_xhr);
87
91
  });
88
- return originalXhrRequest.call(this, dataflux_xhr.option);
92
+ var result = originalXhrRequest.call(this, dataflux_xhr.option); // 判断结果是否为promise
93
+
94
+ var isPromise = function isPromise(obj) {
95
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
96
+ };
97
+
98
+ if (isPromise(result) && userConfiguration.isVue2) {
99
+ // vue2 版本,success, fail 都在then返回
100
+ return result.then(function (res) {
101
+ if (res[0]) {
102
+ reportXhr(res[0]);
103
+ } else {
104
+ reportXhr(res[1]);
105
+ }
106
+
107
+ return res;
108
+ });
109
+ } else if (isPromise(result) && !userConfiguration.isVue2) {
110
+ return new Promise(function (resolve, reject) {
111
+ result.then(function (res) {
112
+ reportXhr(res);
113
+ resolve(res);
114
+ }).catch(function (err) {
115
+ reportXhr(err);
116
+ reject(err);
117
+ });
118
+ });
119
+ } else {
120
+ return result;
121
+ }
89
122
  };
90
123
  }
@@ -3,57 +3,39 @@ import { LifeCycleEventType } from '../../core/lifeCycle';
3
3
  import { trackEventCounts } from '../trackEventCounts';
4
4
  import { waitIdlePageActivity } from '../trackPageActiveites';
5
5
  import { ActionType } from '../../helper/enums';
6
+ import { tracker } from '../../core/sdk';
7
+ var WHITE_METHOD = ['setup'];
6
8
  export function trackActions(lifeCycle, Vue) {
7
9
  var action = startActionManagement(lifeCycle); // New views trigger the discard of the current pending Action
8
10
 
9
11
  lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
10
12
  action.discardCurrent();
11
13
  });
12
- var originVueExtend = Vue.extend;
13
-
14
- Vue.extend = function (vueOptions) {
15
- // methods 方法
16
- if (vueOptions.methods) {
17
- var vueMethods = Object.keys(vueOptions.methods);
18
- vueMethods.forEach(methodName => {
19
- clickProxy(vueOptions.methods, methodName, function (_action) {
20
- action.create(_action.type, _action.name);
21
- }, lifeCycle);
22
- });
23
- }
24
14
 
25
- var originMethods = getMethods(vueOptions);
26
- originMethods.forEach(methodName => {
27
- clickProxy(vueOptions, methodName, function (_action) {
28
- action.create(_action.type, _action.name);
29
- }, lifeCycle);
30
- });
31
- return originVueExtend.call(this, vueOptions);
32
- }; // var originPage = Page
33
- // Page = function (page) {
34
- // const methods = getMethods(page)
35
- // methods.forEach((methodName) => {
36
- // clickProxy(
37
- // page,
38
- // methodName,
39
- // function (_action) {
40
- // action.create(_action.type, _action.name)
41
- // },
42
- // lifeCycle,
43
- // )
44
- // })
45
- // return originPage(page)
46
- // }
47
- // var originComponent = Component
48
- // Component = function (component) {
49
- // const methods = getMethods(component)
50
- // methods.forEach((methodName) => {
51
- // clickProxy(component, methodName, function (_action) {
52
- // action.create(_action.type, _action.name)
53
- // })
54
- // })
55
- // return originComponent(component)
56
- // }
15
+ if (Vue && Vue.extend) {
16
+ var originVueExtend = Vue.extend;
17
+
18
+ Vue.extend = function (vueOptions) {
19
+ proxyInstance(vueOptions, action, lifeCycle);
20
+ return originVueExtend.call(this, vueOptions);
21
+ };
22
+ } else {
23
+ if (!tracker) return;
24
+ var originCreatePage = tracker.createPage;
25
+
26
+ tracker.createPage = function (page) {
27
+ // methods 方法
28
+ proxyInstance(page, action, lifeCycle);
29
+ return originCreatePage.call(this, page);
30
+ };
31
+
32
+ var originCreateComponent = tracker.createComponent;
33
+
34
+ tracker.createComponent = function (component) {
35
+ proxyInstance(component, action, lifeCycle);
36
+ return originCreateComponent.call(this, component);
37
+ };
38
+ } // var originVueExtend = Vue.extend
57
39
 
58
40
 
59
41
  return {
@@ -63,11 +45,31 @@ export function trackActions(lifeCycle, Vue) {
63
45
  };
64
46
  }
65
47
 
66
- function clickProxy(page, methodName, callback, lifeCycle) {
67
- var oirginMethod = page[methodName];
48
+ function proxyInstance(options, action, lifeCycle) {
49
+ // methods 方法
50
+ if (options.methods) {
51
+ var vueMethods = Object.keys(options.methods);
52
+ vueMethods.forEach(methodName => {
53
+ clickProxy(options.methods, methodName, function (_action) {
54
+ action.create(_action.type, _action.name);
55
+ }, lifeCycle);
56
+ });
57
+ }
58
+
59
+ var originMethods = getMethods(options);
60
+ originMethods.forEach(methodName => {
61
+ clickProxy(options, methodName, function (_action) {
62
+ action.create(_action.type, _action.name);
63
+ }, lifeCycle);
64
+ });
65
+ }
66
+
67
+ function clickProxy(origin, methodName, callback, lifeCycle) {
68
+ if (WHITE_METHOD.indexOf(methodName) > -1) return;
69
+ var originMethod = origin[methodName];
68
70
 
69
- page[methodName] = function () {
70
- var result = oirginMethod.apply(this, arguments);
71
+ origin[methodName] = function () {
72
+ var result = originMethod.apply(this, arguments);
71
73
  var action = {};
72
74
 
73
75
  if (isObject(arguments[0])) {
@@ -1,48 +1,63 @@
1
- import { extend, now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
1
+ import { type, now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
2
2
  import { trackEventCounts } from '../trackEventCounts';
3
- import { LifeCycleEventType } from '../../core/lifeCycle';
4
- import { sdk } from '../../core/sdk'; // 劫持原小程序App方法
3
+ import { LifeCycleEventType } from '../../core/lifeCycle'; // 劫持原小程序App方法
5
4
 
6
5
  export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
7
- export function rewritePage(configuration, lifeCycle, Vue) {
8
- var originVueExtend = Vue.extend;
9
-
10
- Vue.extend = function (vueOptions) {
11
- // 合并方法,插入记录脚本
12
- var currentView,
13
- startTime = now();
14
- ['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
15
- var userDefinedMethod = vueOptions[methodName];
16
-
17
- vueOptions[methodName] = function () {
18
- if (this.mpType !== 'page') {
19
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
20
- } // 只处理page类型
21
-
22
-
23
- if (methodName === 'onShow' || methodName === 'onLoad') {
24
- if (typeof currentView === 'undefined') {
25
- var activePage = getActivePage();
26
- currentView = newView(lifeCycle, activePage && activePage.route, startTime);
27
- }
6
+
7
+ function proxyPage(pageOptions, lifeCycle) {
8
+ // 合并方法,插入记录脚本
9
+ var currentView,
10
+ startTime = now();
11
+ ['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
12
+ var userDefinedMethod = pageOptions[methodName];
13
+
14
+ pageOptions[methodName] = function () {
15
+ var mpType = this.mpType || this.$vm.mpType;
16
+
17
+ if (mpType !== 'page') {
18
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
19
+ } // 只处理page类型
20
+
21
+
22
+ if (methodName === 'onShow' || methodName === 'onLoad') {
23
+ if (typeof currentView === 'undefined') {
24
+ var activePage = getActivePage();
25
+ currentView = newView(lifeCycle, activePage && activePage.route, startTime);
28
26
  }
27
+ }
29
28
 
30
- currentView && currentView.setLoadEventEnd(methodName);
29
+ currentView && currentView.setLoadEventEnd(methodName);
31
30
 
32
- if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
33
- currentView.triggerUpdate();
31
+ if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
32
+ currentView.triggerUpdate();
34
33
 
35
- if (methodName === 'onUnload' || methodName === 'onHide') {
36
- currentView.end();
37
- currentView = undefined;
38
- }
34
+ if (methodName === 'onUnload' || methodName === 'onHide') {
35
+ currentView.end();
36
+ currentView = undefined;
39
37
  }
38
+ }
40
39
 
41
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
42
- };
43
- });
44
- return originVueExtend.call(this, vueOptions);
45
- };
40
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
41
+ };
42
+ });
43
+ }
44
+
45
+ export function rewritePage(configuration, lifeCycle, Vue) {
46
+ if (Vue && Vue.extend) {
47
+ var originVueExtend = Vue.extend;
48
+
49
+ Vue.extend = function (vueOptions) {
50
+ proxyPage(vueOptions, lifeCycle);
51
+ return originVueExtend.call(this, vueOptions);
52
+ };
53
+ } else {
54
+ var originComponent = Component;
55
+
56
+ Component = function Component(pageOptions) {
57
+ proxyPage(pageOptions.methods, lifeCycle);
58
+ return originComponent.call(this, pageOptions);
59
+ };
60
+ }
46
61
  }
47
62
 
48
63
  function newView(lifeCycle, route, startTime) {
@@ -31,7 +31,7 @@ function getHeaderString(header) {
31
31
  }
32
32
 
33
33
  export function trackXhr(lifeCycle, configuration, tracer) {
34
- var xhrProxy = startXhrProxy();
34
+ var xhrProxy = startXhrProxy(configuration);
35
35
  xhrProxy.beforeSend(function (context) {
36
36
  if (isAllowedRequestUrl(configuration, context.url)) {
37
37
  tracer.traceXhr(context);
@@ -62,7 +62,7 @@ export function trackXhr(lifeCycle, configuration, tracer) {
62
62
  return xhrProxy;
63
63
  }
64
64
  export function trackDownload(lifeCycle, configuration) {
65
- var dwonloadProxy = startDownloadProxy();
65
+ var dwonloadProxy = startDownloadProxy(configuration);
66
66
  dwonloadProxy.beforeSend(function (context) {
67
67
  if (isAllowedRequestUrl(configuration, context.url)) {
68
68
  context.requestIndex = getNextRequestIndex();
@@ -1,5 +1,6 @@
1
1
  import { LifeCycleEventType } from '../core/lifeCycle';
2
2
  import { now } from '../helper/utils';
3
+ import { tracker } from '../core/sdk';
3
4
 
4
5
  function resetSetData(data, callback, lifeCycle, mpInstance) {
5
6
  var pendingStartTimestamp = now();
@@ -18,36 +19,56 @@ function resetSetData(data, callback, lifeCycle, mpInstance) {
18
19
  return _callback;
19
20
  }
20
21
 
21
- export function startSetDataColloction(lifeCycle, Vue) {
22
- var originVueExtend = Vue.extend;
23
-
24
- Vue.extend = function (vueOptions) {
25
- var userDefinedMethod = vueOptions['onLoad'];
22
+ function proxyPage(pageOptions, lifeCycle) {
23
+ var userDefinedMethod = pageOptions['onLoad'];
26
24
 
27
- vueOptions['onLoad'] = function () {
28
- var mpInstance = this.$scope;
29
- var setData = mpInstance.setData; // 重写setData
25
+ pageOptions['onLoad'] = function () {
26
+ var mpInstance = this.$scope;
27
+ var setData = mpInstance.setData;
30
28
 
31
- if (typeof setData === 'function') {
32
- try {
33
- // 这里暂时这么处理 只读属性 会抛出错误
34
- mpInstance.setData = function (data, callback) {
29
+ if (typeof setData === 'function') {
30
+ try {
31
+ // 这里暂时这么处理 只读属性 会抛出错误
32
+ mpInstance.setData = function (data, callback) {
33
+ return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
34
+ };
35
+ } catch (err) {
36
+ Object.defineProperty(mpInstance.__proto__, 'setData', {
37
+ configurable: false,
38
+ enumerable: false,
39
+ value: function value(data, callback) {
35
40
  return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
36
- };
37
- } catch (err) {
38
- Object.defineProperty(mpInstance.__proto__, 'setData', {
39
- configurable: false,
40
- enumerable: false,
41
- value: function value(data, callback) {
42
- return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
43
- }
44
- });
45
- }
41
+ }
42
+ });
46
43
  }
44
+ }
47
45
 
48
- return userDefinedMethod && userDefinedMethod.apply(this, arguments);
46
+ return userDefinedMethod && userDefinedMethod.apply(this, arguments);
47
+ };
48
+ }
49
+
50
+ export function startSetDataColloction(lifeCycle, Vue) {
51
+ if (Vue && Vue.extend) {
52
+ var originVueExtend = Vue.extend;
53
+
54
+ Vue.extend = function (vueOptions) {
55
+ proxyPage(vueOptions, lifeCycle);
56
+ return originVueExtend.call(this, vueOptions);
49
57
  };
58
+ } else {
59
+ if (!tracker) return;
60
+ var originCreatePage = tracker.createPage;
50
61
 
51
- return originVueExtend.call(this, vueOptions);
52
- };
62
+ tracker.createPage = function (pageOptions) {
63
+ proxyPage(pageOptions, lifeCycle);
64
+ return originCreatePage.call(this, pageOptions);
65
+ };
66
+
67
+ var originCreateComponent = tracker.createComponent;
68
+
69
+ tracker.createComponent = function (component) {
70
+ proxyPage(component, lifeCycle);
71
+ return originCreateComponent.call(this, component);
72
+ };
73
+ }
53
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/rum-uniapp",
3
- "version": "2.1.4",
3
+ "version": "2.1.7",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "miniprogram": "cjs",