@cloudcare/rum-uniapp 2.1.23 → 2.2.0
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/cjs/boot/buildEnv.js +1 -1
- package/cjs/core/configuration.js +3 -1
- package/cjs/helper/catchUserErrors.js +16 -0
- package/cjs/helper/enums.js +2 -1
- package/cjs/helper/utils.js +19 -2
- package/cjs/rumEventsCollection/action/trackActions.js +30 -73
- package/cjs/rumEventsCollection/page/index.js +37 -49
- package/cjs/rumEventsCollection/setDataCollection.js +25 -56
- package/cjs/rumEventsCollection/tracing/tracer.js +12 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/core/configuration.js +3 -1
- package/esm/helper/catchUserErrors.js +10 -0
- package/esm/helper/enums.js +2 -1
- package/esm/helper/utils.js +13 -0
- package/esm/rumEventsCollection/action/trackActions.js +30 -73
- package/esm/rumEventsCollection/page/index.js +37 -49
- package/esm/rumEventsCollection/setDataCollection.js +25 -56
- package/esm/rumEventsCollection/tracing/tracer.js +13 -2
- package/package.json +1 -1
package/cjs/boot/buildEnv.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.commonInit = commonInit;
|
|
|
8
8
|
exports.isIntakeRequest = isIntakeRequest;
|
|
9
9
|
var _utils = require("../helper/utils");
|
|
10
10
|
var _enums = require("../helper/enums");
|
|
11
|
+
var _catchUserErrors = require("../helper/catchUserErrors");
|
|
11
12
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
12
13
|
var DEFAULT_CONFIGURATION = exports.DEFAULT_CONFIGURATION = {
|
|
13
14
|
sampleRate: 100,
|
|
@@ -64,7 +65,8 @@ function commonInit(userConfiguration, buildEnv) {
|
|
|
64
65
|
sdkVersion: buildEnv.sdkVersion,
|
|
65
66
|
sdkName: buildEnv.sdkName,
|
|
66
67
|
datakitUrl: getDatakitEndPoint(userConfiguration),
|
|
67
|
-
tags: userConfiguration.tags || []
|
|
68
|
+
tags: userConfiguration.tags || [],
|
|
69
|
+
injectTraceHeader: userConfiguration.injectTraceHeader && (0, _catchUserErrors.catchUserErrors)(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:')
|
|
68
70
|
};
|
|
69
71
|
if ('trackInteractions' in userConfiguration) {
|
|
70
72
|
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.catchUserErrors = catchUserErrors;
|
|
7
|
+
function catchUserErrors(fn, errorMsg) {
|
|
8
|
+
return function () {
|
|
9
|
+
var args = [].slice.call(arguments);
|
|
10
|
+
try {
|
|
11
|
+
return fn.apply(this, args);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
console.error(errorMsg, err);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
package/cjs/helper/enums.js
CHANGED
package/cjs/helper/utils.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ONE_SECOND = exports.ONE_MINUTE = exports.ONE_HOUR = void 0;
|
|
7
7
|
exports.UUID = UUID;
|
|
8
|
-
exports.
|
|
8
|
+
exports.areInOrder = void 0;
|
|
9
|
+
exports.assign = assign;
|
|
10
|
+
exports.base64Encode = void 0;
|
|
9
11
|
exports.deepClone = deepClone;
|
|
10
12
|
exports.deepMixObject = void 0;
|
|
11
13
|
exports.deepSnakeCase = deepSnakeCase;
|
|
@@ -36,7 +38,9 @@ exports.now = void 0;
|
|
|
36
38
|
exports.performDraw = performDraw;
|
|
37
39
|
exports.replaceNumberCharByPath = replaceNumberCharByPath;
|
|
38
40
|
exports.round = round;
|
|
39
|
-
exports.
|
|
41
|
+
exports.safeJSONParse = void 0;
|
|
42
|
+
exports.shallowClone = shallowClone;
|
|
43
|
+
exports.toArray = exports.throttle = void 0;
|
|
40
44
|
exports.toServerDuration = toServerDuration;
|
|
41
45
|
exports.toSnakeCase = toSnakeCase;
|
|
42
46
|
exports.values = exports.utf8Encode = exports.urlParse = exports.trim = void 0;
|
|
@@ -740,4 +744,17 @@ function getGlobalObject() {
|
|
|
740
744
|
}
|
|
741
745
|
}
|
|
742
746
|
return globalObject;
|
|
747
|
+
}
|
|
748
|
+
function assign(target) {
|
|
749
|
+
each(slice.call(arguments, 1), function (source) {
|
|
750
|
+
for (var prop in source) {
|
|
751
|
+
if (Object.prototype.hasOwnProperty.call(source, prop)) {
|
|
752
|
+
target[prop] = source[prop];
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
return target;
|
|
757
|
+
}
|
|
758
|
+
function shallowClone(object) {
|
|
759
|
+
return assign({}, object);
|
|
743
760
|
}
|
|
@@ -9,8 +9,6 @@ var _lifeCycle = require("../../core/lifeCycle");
|
|
|
9
9
|
var _trackEventCounts = require("../trackEventCounts");
|
|
10
10
|
var _trackPageActiveites = require("../trackPageActiveites");
|
|
11
11
|
var _enums = require("../../helper/enums");
|
|
12
|
-
var _sdk = require("../../core/sdk");
|
|
13
|
-
var WHITE_METHOD = ['setup'];
|
|
14
12
|
function trackActions(lifeCycle, Vue) {
|
|
15
13
|
var action = startActionManagement(lifeCycle);
|
|
16
14
|
|
|
@@ -18,57 +16,34 @@ function trackActions(lifeCycle, Vue) {
|
|
|
18
16
|
lifeCycle.subscribe(_lifeCycle.LifeCycleEventType.VIEW_CREATED, function () {
|
|
19
17
|
action.discardCurrent();
|
|
20
18
|
});
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var originComponent = Component;
|
|
46
|
-
Component = function Component(component) {
|
|
47
|
-
var methods = (0, _utils.getMethods)(component.methods);
|
|
48
|
-
methods.forEach(function (methodName) {
|
|
49
|
-
clickProxy(component, methodName, function (_action) {
|
|
50
|
-
action.create(_action.type, _action.name);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
return originComponent(component);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!hasComponent) {
|
|
57
|
-
var originCreatePage = _sdk.tracker.createPage;
|
|
58
|
-
_sdk.tracker.createPage = function (page) {
|
|
59
|
-
// methods 方法
|
|
60
|
-
proxyInstance(page, action, lifeCycle);
|
|
61
|
-
return originCreatePage.call(this, page);
|
|
62
|
-
};
|
|
63
|
-
var originCreateComponent = _sdk.tracker.createComponent;
|
|
64
|
-
_sdk.tracker.createComponent = function (component) {
|
|
65
|
-
proxyInstance(component, action, lifeCycle);
|
|
66
|
-
return originCreateComponent.call(this, component);
|
|
19
|
+
var hookClick = function hookClick(instance) {
|
|
20
|
+
var methods = (0, _utils.getMethods)(instance);
|
|
21
|
+
methods.forEach(function (methodName) {
|
|
22
|
+
clickProxy(instance, methodName, function (_action) {
|
|
23
|
+
action.create(_action.type, _action.name);
|
|
24
|
+
}, lifeCycle);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var originPage = Page;
|
|
28
|
+
Page = function Page(page) {
|
|
29
|
+
try {
|
|
30
|
+
hookClick(page);
|
|
31
|
+
} catch (error) {}
|
|
32
|
+
return originPage(page);
|
|
33
|
+
};
|
|
34
|
+
var originComponent = Component;
|
|
35
|
+
Component = function Component(component) {
|
|
36
|
+
if (component.methods && component.methods.onLoad) {
|
|
37
|
+
var originOnLoad = component.methods.onLoad;
|
|
38
|
+
component.methods.onLoad = function () {
|
|
39
|
+
try {
|
|
40
|
+
hookClick(this);
|
|
41
|
+
} catch (error) {}
|
|
42
|
+
return originOnLoad.apply(this, arguments);
|
|
67
43
|
};
|
|
68
44
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
45
|
+
return originComponent(component);
|
|
46
|
+
};
|
|
72
47
|
return {
|
|
73
48
|
stop: function stop() {
|
|
74
49
|
action.discardCurrent();
|
|
@@ -77,28 +52,10 @@ function trackActions(lifeCycle, Vue) {
|
|
|
77
52
|
};
|
|
78
53
|
}
|
|
79
54
|
|
|
80
|
-
function proxyInstance(options, action, lifeCycle) {
|
|
81
|
-
// methods 方法
|
|
82
|
-
if (options.methods) {
|
|
83
|
-
var vueMethods = Object.keys(options.methods);
|
|
84
|
-
vueMethods.forEach(function (methodName) {
|
|
85
|
-
clickProxy(options.methods, methodName, function (_action) {
|
|
86
|
-
action.create(_action.type, _action.name);
|
|
87
|
-
}, lifeCycle);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
var originMethods = (0, _utils.getMethods)(options);
|
|
91
|
-
originMethods.forEach(function (methodName) {
|
|
92
|
-
clickProxy(options, methodName, function (_action) {
|
|
93
|
-
action.create(_action.type, _action.name);
|
|
94
|
-
}, lifeCycle);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
55
|
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
98
|
-
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
99
56
|
var originMethod = origin[methodName];
|
|
100
57
|
origin[methodName] = function () {
|
|
101
|
-
var result = originMethod.apply(this, arguments);
|
|
58
|
+
var result = originMethod.apply(this, arguments) || {};
|
|
102
59
|
var action = {};
|
|
103
60
|
if ((0, _utils.isObject)(arguments[0])) {
|
|
104
61
|
var currentTarget = arguments[0].currentTarget || {};
|
|
@@ -111,17 +68,17 @@ function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
|
111
68
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
112
69
|
} else if (methodName === 'onAddToFavorites') {
|
|
113
70
|
action.type = 'click';
|
|
114
|
-
action.name = '收藏 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
71
|
+
action.name = '收藏 ' + '标题: ' + result.title || '' + (result.query ? ' query: ' + result.query : '');
|
|
115
72
|
callback(action);
|
|
116
73
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
117
74
|
} else if (methodName === 'onShareAppMessage') {
|
|
118
75
|
action.type = 'click';
|
|
119
|
-
action.name = '转发 ' + '标题: ' + result.title + (result.path ? ' path: ' + result.path : '');
|
|
76
|
+
action.name = '转发 ' + '标题: ' + result.title || '' + (result.path ? ' path: ' + result.path : '');
|
|
120
77
|
callback(action);
|
|
121
78
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
122
79
|
} else if (methodName === 'onShareTimeline') {
|
|
123
80
|
action.type = 'click';
|
|
124
|
-
action.name = '分享到朋友圈 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
81
|
+
action.name = '分享到朋友圈 ' + '标题: ' + result.title || '' + (result.query ? ' query: ' + result.query : '');
|
|
125
82
|
callback(action);
|
|
126
83
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
127
84
|
} else if (methodName === 'onTabItemTap') {
|
|
@@ -10,58 +10,46 @@ var _trackEventCounts2 = require("../trackEventCounts");
|
|
|
10
10
|
var _lifeCycle = require("../../core/lifeCycle");
|
|
11
11
|
// 劫持原小程序App方法
|
|
12
12
|
var THROTTLE_VIEW_UPDATE_PERIOD = exports.THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var activePage = (0, _utils.getActivePage)();
|
|
28
|
-
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
13
|
+
function rewritePage(configuration, lifeCycle, Vue) {
|
|
14
|
+
var originPage = Page;
|
|
15
|
+
var originComponent = Component;
|
|
16
|
+
var hookPage = function hookPage(pageInstance) {
|
|
17
|
+
var currentView,
|
|
18
|
+
startTime = (0, _utils.now)();
|
|
19
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(function (methodName) {
|
|
20
|
+
var userDefinedMethod = pageInstance[methodName];
|
|
21
|
+
pageInstance[methodName] = function () {
|
|
22
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
23
|
+
if (typeof currentView === 'undefined') {
|
|
24
|
+
var activePage = (0, _utils.getActivePage)();
|
|
25
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
26
|
+
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
29
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
30
|
+
currentView.triggerUpdate();
|
|
31
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
32
|
+
currentView.end();
|
|
33
|
+
currentView = undefined;
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function rewritePage(configuration, lifeCycle, Vue) {
|
|
44
|
-
if (Vue && Vue.extend) {
|
|
45
|
-
var originVueExtend = Vue.extend;
|
|
46
|
-
Vue.extend = function (vueOptions) {
|
|
47
|
-
proxyPage(vueOptions, lifeCycle);
|
|
48
|
-
return originVueExtend.call(this, vueOptions);
|
|
49
|
-
};
|
|
50
|
-
} else {
|
|
51
|
-
if (Page) {
|
|
52
|
-
var originPage = Page;
|
|
53
|
-
Page = function Page(pageOptions) {
|
|
54
|
-
proxyPage(pageOptions, lifeCycle);
|
|
55
|
-
return originPage.call(this, pageOptions);
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
var originComponent = Component;
|
|
59
|
-
Component = function Component(pageOptions) {
|
|
60
|
-
proxyPage(pageOptions.methods, lifeCycle);
|
|
61
|
-
return originComponent.call(this, pageOptions);
|
|
36
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
62
37
|
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
Component = function Component(component) {
|
|
41
|
+
try {
|
|
42
|
+
hookPage(component.methods);
|
|
43
|
+
} catch (error) {}
|
|
44
|
+
return originComponent(component);
|
|
45
|
+
};
|
|
46
|
+
Page = function Page(page) {
|
|
47
|
+
// 合并方法,插入记录脚本
|
|
48
|
+
try {
|
|
49
|
+
hookPage(page);
|
|
50
|
+
} catch (error) {}
|
|
51
|
+
return originPage(page);
|
|
52
|
+
};
|
|
65
53
|
}
|
|
66
54
|
function newView(lifeCycle, route, startTime) {
|
|
67
55
|
if (typeof startTime === 'undefined' || Number(startTime) === 0) {
|
|
@@ -5,63 +5,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.startSetDataColloction = startSetDataColloction;
|
|
7
7
|
var _lifeCycle = require("../core/lifeCycle");
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
function startSetDataColloction(lifeCycle, Vue) {
|
|
9
|
+
var originComponent = Component;
|
|
10
|
+
Component = function Component(component) {
|
|
11
|
+
var originComponentAttached;
|
|
12
|
+
function handlerOrigin() {
|
|
13
|
+
this.setUpdatePerformanceListener && this.setUpdatePerformanceListener({
|
|
14
|
+
withDataPaths: true
|
|
15
|
+
}, function (res) {
|
|
16
|
+
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_SET_DATA_UPDATE, res);
|
|
17
|
+
});
|
|
18
|
+
return originComponentAttached && originComponentAttached.apply(this, arguments);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (typeof setData === 'function') {
|
|
29
|
-
try {
|
|
30
|
-
// 这里暂时这么处理 只读属性 会抛出错误
|
|
31
|
-
mpInstance.setData = function (data, callback) {
|
|
32
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
33
|
-
};
|
|
34
|
-
} catch (err) {
|
|
35
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
36
|
-
configurable: false,
|
|
37
|
-
enumerable: false,
|
|
38
|
-
value: function value(data, callback) {
|
|
39
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
20
|
+
try {
|
|
21
|
+
if (component.lifetimes && component.lifetimes['attached']) {
|
|
22
|
+
originComponentAttached = component.lifetimes['attached'];
|
|
23
|
+
component.lifetimes['attached'] = handlerOrigin;
|
|
24
|
+
} else if (component['attached']) {
|
|
25
|
+
// 兼容老版本
|
|
26
|
+
originComponentAttached = component['attached'];
|
|
27
|
+
component['attached'] = handlerOrigin;
|
|
42
28
|
}
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
if (component.onLoad) {
|
|
30
|
+
originComponentAttached = component.onLoad;
|
|
31
|
+
component.onLoad = handlerOrigin;
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {}
|
|
34
|
+
return originComponent(component);
|
|
45
35
|
};
|
|
46
|
-
}
|
|
47
|
-
function startSetDataColloction(lifeCycle, Vue) {
|
|
48
|
-
if (Vue && Vue.extend) {
|
|
49
|
-
var originVueExtend = Vue.extend;
|
|
50
|
-
Vue.extend = function (vueOptions) {
|
|
51
|
-
proxyPage(vueOptions, lifeCycle);
|
|
52
|
-
return originVueExtend.call(this, vueOptions);
|
|
53
|
-
};
|
|
54
|
-
} else {
|
|
55
|
-
if (!_sdk.tracker) return;
|
|
56
|
-
var originCreatePage = _sdk.tracker.createPage;
|
|
57
|
-
_sdk.tracker.createPage = function (pageOptions) {
|
|
58
|
-
proxyPage(pageOptions, lifeCycle);
|
|
59
|
-
return originCreatePage.call(this, pageOptions);
|
|
60
|
-
};
|
|
61
|
-
var originCreateComponent = _sdk.tracker.createComponent;
|
|
62
|
-
_sdk.tracker.createComponent = function (component) {
|
|
63
|
-
proxyPage(component, lifeCycle);
|
|
64
|
-
return originCreateComponent.call(this, component);
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
36
|
}
|
|
@@ -80,5 +80,16 @@ function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
|
80
80
|
}
|
|
81
81
|
context.traceId = tracer.getTraceId();
|
|
82
82
|
context.spanId = tracer.getSpanId();
|
|
83
|
-
|
|
83
|
+
var headers = tracer.makeTracingHeaders();
|
|
84
|
+
if (configuration.injectTraceHeader) {
|
|
85
|
+
var result = configuration.injectTraceHeader((0, _utils.shallowClone)(context));
|
|
86
|
+
if ((0, _utils.getType)(result) === 'object') {
|
|
87
|
+
(0, _utils.each)(result, function (value, key) {
|
|
88
|
+
if ((0, _utils.getType)(value) === 'string') {
|
|
89
|
+
headers[key] = value;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
inject(headers);
|
|
84
95
|
}
|
package/esm/boot/buildEnv.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { extend2Lev, urlParse, values, isFunction, isBoolean } from '../helper/utils';
|
|
2
2
|
import { ONE_KILO_BYTE, ONE_SECOND, TraceType } from '../helper/enums';
|
|
3
|
+
import { catchUserErrors } from '../helper/catchUserErrors';
|
|
3
4
|
var TRIM_REGIX = /^\s+|\s+$/g;
|
|
4
5
|
export var DEFAULT_CONFIGURATION = {
|
|
5
6
|
sampleRate: 100,
|
|
@@ -56,7 +57,8 @@ export function commonInit(userConfiguration, buildEnv) {
|
|
|
56
57
|
sdkVersion: buildEnv.sdkVersion,
|
|
57
58
|
sdkName: buildEnv.sdkName,
|
|
58
59
|
datakitUrl: getDatakitEndPoint(userConfiguration),
|
|
59
|
-
tags: userConfiguration.tags || []
|
|
60
|
+
tags: userConfiguration.tags || [],
|
|
61
|
+
injectTraceHeader: userConfiguration.injectTraceHeader && catchUserErrors(userConfiguration.injectTraceHeader, 'injectTraceHeader threw an error:')
|
|
60
62
|
};
|
|
61
63
|
if ('trackInteractions' in userConfiguration) {
|
|
62
64
|
transportConfiguration.trackInteractions = !!userConfiguration.trackInteractions;
|
package/esm/helper/enums.js
CHANGED
package/esm/helper/utils.js
CHANGED
|
@@ -694,4 +694,17 @@ export function getGlobalObject() {
|
|
|
694
694
|
}
|
|
695
695
|
}
|
|
696
696
|
return globalObject;
|
|
697
|
+
}
|
|
698
|
+
export function assign(target) {
|
|
699
|
+
each(slice.call(arguments, 1), function (source) {
|
|
700
|
+
for (var prop in source) {
|
|
701
|
+
if (Object.prototype.hasOwnProperty.call(source, prop)) {
|
|
702
|
+
target[prop] = source[prop];
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
return target;
|
|
707
|
+
}
|
|
708
|
+
export function shallowClone(object) {
|
|
709
|
+
return assign({}, object);
|
|
697
710
|
}
|
|
@@ -3,8 +3,6 @@ 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'];
|
|
8
6
|
export function trackActions(lifeCycle, Vue) {
|
|
9
7
|
var action = startActionManagement(lifeCycle);
|
|
10
8
|
|
|
@@ -12,57 +10,34 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
12
10
|
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
13
11
|
action.discardCurrent();
|
|
14
12
|
});
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var originComponent = Component;
|
|
40
|
-
Component = function Component(component) {
|
|
41
|
-
var methods = getMethods(component.methods);
|
|
42
|
-
methods.forEach(methodName => {
|
|
43
|
-
clickProxy(component, methodName, function (_action) {
|
|
44
|
-
action.create(_action.type, _action.name);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return originComponent(component);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (!hasComponent) {
|
|
51
|
-
var originCreatePage = tracker.createPage;
|
|
52
|
-
tracker.createPage = function (page) {
|
|
53
|
-
// methods 方法
|
|
54
|
-
proxyInstance(page, action, lifeCycle);
|
|
55
|
-
return originCreatePage.call(this, page);
|
|
56
|
-
};
|
|
57
|
-
var originCreateComponent = tracker.createComponent;
|
|
58
|
-
tracker.createComponent = function (component) {
|
|
59
|
-
proxyInstance(component, action, lifeCycle);
|
|
60
|
-
return originCreateComponent.call(this, component);
|
|
13
|
+
var hookClick = function hookClick(instance) {
|
|
14
|
+
var methods = getMethods(instance);
|
|
15
|
+
methods.forEach(methodName => {
|
|
16
|
+
clickProxy(instance, methodName, function (_action) {
|
|
17
|
+
action.create(_action.type, _action.name);
|
|
18
|
+
}, lifeCycle);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var originPage = Page;
|
|
22
|
+
Page = function Page(page) {
|
|
23
|
+
try {
|
|
24
|
+
hookClick(page);
|
|
25
|
+
} catch (error) {}
|
|
26
|
+
return originPage(page);
|
|
27
|
+
};
|
|
28
|
+
var originComponent = Component;
|
|
29
|
+
Component = function Component(component) {
|
|
30
|
+
if (component.methods && component.methods.onLoad) {
|
|
31
|
+
var originOnLoad = component.methods.onLoad;
|
|
32
|
+
component.methods.onLoad = function () {
|
|
33
|
+
try {
|
|
34
|
+
hookClick(this);
|
|
35
|
+
} catch (error) {}
|
|
36
|
+
return originOnLoad.apply(this, arguments);
|
|
61
37
|
};
|
|
62
38
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
return originComponent(component);
|
|
40
|
+
};
|
|
66
41
|
return {
|
|
67
42
|
stop: function stop() {
|
|
68
43
|
action.discardCurrent();
|
|
@@ -71,28 +46,10 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
71
46
|
};
|
|
72
47
|
}
|
|
73
48
|
|
|
74
|
-
function proxyInstance(options, action, lifeCycle) {
|
|
75
|
-
// methods 方法
|
|
76
|
-
if (options.methods) {
|
|
77
|
-
var vueMethods = Object.keys(options.methods);
|
|
78
|
-
vueMethods.forEach(methodName => {
|
|
79
|
-
clickProxy(options.methods, methodName, function (_action) {
|
|
80
|
-
action.create(_action.type, _action.name);
|
|
81
|
-
}, lifeCycle);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
var originMethods = getMethods(options);
|
|
85
|
-
originMethods.forEach(methodName => {
|
|
86
|
-
clickProxy(options, methodName, function (_action) {
|
|
87
|
-
action.create(_action.type, _action.name);
|
|
88
|
-
}, lifeCycle);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
49
|
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
92
|
-
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
93
50
|
var originMethod = origin[methodName];
|
|
94
51
|
origin[methodName] = function () {
|
|
95
|
-
var result = originMethod.apply(this, arguments);
|
|
52
|
+
var result = originMethod.apply(this, arguments) || {};
|
|
96
53
|
var action = {};
|
|
97
54
|
if (isObject(arguments[0])) {
|
|
98
55
|
var currentTarget = arguments[0].currentTarget || {};
|
|
@@ -105,17 +62,17 @@ function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
|
105
62
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
106
63
|
} else if (methodName === 'onAddToFavorites') {
|
|
107
64
|
action.type = 'click';
|
|
108
|
-
action.name = '收藏 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
65
|
+
action.name = '收藏 ' + '标题: ' + result.title || '' + (result.query ? ' query: ' + result.query : '');
|
|
109
66
|
callback(action);
|
|
110
67
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
111
68
|
} else if (methodName === 'onShareAppMessage') {
|
|
112
69
|
action.type = 'click';
|
|
113
|
-
action.name = '转发 ' + '标题: ' + result.title + (result.path ? ' path: ' + result.path : '');
|
|
70
|
+
action.name = '转发 ' + '标题: ' + result.title || '' + (result.path ? ' path: ' + result.path : '');
|
|
114
71
|
callback(action);
|
|
115
72
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
116
73
|
} else if (methodName === 'onShareTimeline') {
|
|
117
74
|
action.type = 'click';
|
|
118
|
-
action.name = '分享到朋友圈 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
75
|
+
action.name = '分享到朋友圈 ' + '标题: ' + result.title || '' + (result.query ? ' query: ' + result.query : '');
|
|
119
76
|
callback(action);
|
|
120
77
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
121
78
|
} else if (methodName === 'onTabItemTap') {
|
|
@@ -4,58 +4,46 @@ import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
|
4
4
|
|
|
5
5
|
// 劫持原小程序App方法
|
|
6
6
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var activePage = getActivePage();
|
|
22
|
-
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
7
|
+
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
8
|
+
var originPage = Page;
|
|
9
|
+
var originComponent = Component;
|
|
10
|
+
var hookPage = function hookPage(pageInstance) {
|
|
11
|
+
var currentView,
|
|
12
|
+
startTime = now();
|
|
13
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
|
|
14
|
+
var userDefinedMethod = pageInstance[methodName];
|
|
15
|
+
pageInstance[methodName] = function () {
|
|
16
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
17
|
+
if (typeof currentView === 'undefined') {
|
|
18
|
+
var activePage = getActivePage();
|
|
19
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
20
|
+
}
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
23
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
24
|
+
currentView.triggerUpdate();
|
|
25
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
26
|
+
currentView.end();
|
|
27
|
+
currentView = undefined;
|
|
28
|
+
}
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
38
|
-
if (Vue && Vue.extend) {
|
|
39
|
-
var originVueExtend = Vue.extend;
|
|
40
|
-
Vue.extend = function (vueOptions) {
|
|
41
|
-
proxyPage(vueOptions, lifeCycle);
|
|
42
|
-
return originVueExtend.call(this, vueOptions);
|
|
43
|
-
};
|
|
44
|
-
} else {
|
|
45
|
-
if (Page) {
|
|
46
|
-
var originPage = Page;
|
|
47
|
-
Page = function Page(pageOptions) {
|
|
48
|
-
proxyPage(pageOptions, lifeCycle);
|
|
49
|
-
return originPage.call(this, pageOptions);
|
|
50
|
-
};
|
|
51
|
-
} else {
|
|
52
|
-
var originComponent = Component;
|
|
53
|
-
Component = function Component(pageOptions) {
|
|
54
|
-
proxyPage(pageOptions.methods, lifeCycle);
|
|
55
|
-
return originComponent.call(this, pageOptions);
|
|
30
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
56
31
|
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Component = function Component(component) {
|
|
35
|
+
try {
|
|
36
|
+
hookPage(component.methods);
|
|
37
|
+
} catch (error) {}
|
|
38
|
+
return originComponent(component);
|
|
39
|
+
};
|
|
40
|
+
Page = function Page(page) {
|
|
41
|
+
// 合并方法,插入记录脚本
|
|
42
|
+
try {
|
|
43
|
+
hookPage(page);
|
|
44
|
+
} catch (error) {}
|
|
45
|
+
return originPage(page);
|
|
46
|
+
};
|
|
59
47
|
}
|
|
60
48
|
function newView(lifeCycle, route, startTime) {
|
|
61
49
|
if (typeof startTime === 'undefined' || Number(startTime) === 0) {
|
|
@@ -1,61 +1,30 @@
|
|
|
1
1
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
export function startSetDataColloction(lifeCycle, Vue) {
|
|
3
|
+
var originComponent = Component;
|
|
4
|
+
Component = function Component(component) {
|
|
5
|
+
var originComponentAttached;
|
|
6
|
+
function handlerOrigin() {
|
|
7
|
+
this.setUpdatePerformanceListener && this.setUpdatePerformanceListener({
|
|
8
|
+
withDataPaths: true
|
|
9
|
+
}, res => {
|
|
10
|
+
lifeCycle.notify(LifeCycleEventType.PAGE_SET_DATA_UPDATE, res);
|
|
11
|
+
});
|
|
12
|
+
return originComponentAttached && originComponentAttached.apply(this, arguments);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (typeof setData === 'function') {
|
|
23
|
-
try {
|
|
24
|
-
// 这里暂时这么处理 只读属性 会抛出错误
|
|
25
|
-
mpInstance.setData = function (data, callback) {
|
|
26
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
27
|
-
};
|
|
28
|
-
} catch (err) {
|
|
29
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
30
|
-
configurable: false,
|
|
31
|
-
enumerable: false,
|
|
32
|
-
value: function value(data, callback) {
|
|
33
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
14
|
+
try {
|
|
15
|
+
if (component.lifetimes && component.lifetimes['attached']) {
|
|
16
|
+
originComponentAttached = component.lifetimes['attached'];
|
|
17
|
+
component.lifetimes['attached'] = handlerOrigin;
|
|
18
|
+
} else if (component['attached']) {
|
|
19
|
+
// 兼容老版本
|
|
20
|
+
originComponentAttached = component['attached'];
|
|
21
|
+
component['attached'] = handlerOrigin;
|
|
36
22
|
}
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
if (component.onLoad) {
|
|
24
|
+
originComponentAttached = component.onLoad;
|
|
25
|
+
component.onLoad = handlerOrigin;
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {}
|
|
28
|
+
return originComponent(component);
|
|
39
29
|
};
|
|
40
|
-
}
|
|
41
|
-
export function startSetDataColloction(lifeCycle, Vue) {
|
|
42
|
-
if (Vue && Vue.extend) {
|
|
43
|
-
var originVueExtend = Vue.extend;
|
|
44
|
-
Vue.extend = function (vueOptions) {
|
|
45
|
-
proxyPage(vueOptions, lifeCycle);
|
|
46
|
-
return originVueExtend.call(this, vueOptions);
|
|
47
|
-
};
|
|
48
|
-
} else {
|
|
49
|
-
if (!tracker) return;
|
|
50
|
-
var originCreatePage = tracker.createPage;
|
|
51
|
-
tracker.createPage = function (pageOptions) {
|
|
52
|
-
proxyPage(pageOptions, lifeCycle);
|
|
53
|
-
return originCreatePage.call(this, pageOptions);
|
|
54
|
-
};
|
|
55
|
-
var originCreateComponent = tracker.createComponent;
|
|
56
|
-
tracker.createComponent = function (component) {
|
|
57
|
-
proxyPage(component, lifeCycle);
|
|
58
|
-
return originCreateComponent.call(this, component);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { each, extend, getOrigin } from '../../helper/utils';
|
|
1
|
+
import { each, extend, getOrigin, getType, shallowClone } from '../../helper/utils';
|
|
2
2
|
import { TraceType } from '../../helper/enums';
|
|
3
3
|
import { DDtraceTracer } from './ddtraceTracer';
|
|
4
4
|
import { SkyWalkingTracer } from './skywalkingTracer';
|
|
@@ -72,5 +72,16 @@ export function injectHeadersIfTracingAllowed(configuration, context, inject) {
|
|
|
72
72
|
}
|
|
73
73
|
context.traceId = tracer.getTraceId();
|
|
74
74
|
context.spanId = tracer.getSpanId();
|
|
75
|
-
|
|
75
|
+
var headers = tracer.makeTracingHeaders();
|
|
76
|
+
if (configuration.injectTraceHeader) {
|
|
77
|
+
var result = configuration.injectTraceHeader(shallowClone(context));
|
|
78
|
+
if (getType(result) === 'object') {
|
|
79
|
+
each(result, function (value, key) {
|
|
80
|
+
if (getType(value) === 'string') {
|
|
81
|
+
headers[key] = value;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
inject(headers);
|
|
76
87
|
}
|