@beisen/analysis-pms
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -54,20 +54,17 @@ /******/ (function(modules) { // webpackBootstrap | ||
var perfAnalysis = __webpack_require__(2); | ||
'use strict'; | ||
((function(){ | ||
if(window.iTalentPMS) { | ||
window.iTalentPMS && window.iTalentPMS.clearAll && window.iTalentPMS.clearAll(); | ||
return; | ||
} | ||
var _perfAnalysis = __webpack_require__(2); | ||
window.iTalentPMS = new perfAnalysis(); | ||
//收集移动端行为数据 | ||
window.collectMobileAction = function(type, event) { | ||
// actionAnaly.commonEvent(type, event, true); | ||
}; | ||
var _perfAnalysis2 = _interopRequireDefault(_perfAnalysis); | ||
})()) | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
(function () { | ||
window.iTalentPMS = new _perfAnalysis2.default(); | ||
//收集移动端行为数据 | ||
window.collectMobileAction = function (type, event) {}; | ||
})(); | ||
/***/ }, | ||
@@ -77,7 +74,14 @@ /* 2 */ | ||
var defineData = __webpack_require__(3); | ||
var utils = __webpack_require__(4); | ||
'use strict'; | ||
var _opsUrl = __webpack_require__(3); | ||
var _opsUrl2 = _interopRequireDefault(_opsUrl); | ||
var _utils = __webpack_require__(4); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function perfAnalysis() { | ||
this._fetchItem = []; | ||
this._fetchItem = []; | ||
} | ||
@@ -88,42 +92,21 @@ | ||
// 获取频道名称 | ||
perfAnalysis.prototype._getCurrentPage = function() { | ||
perfAnalysis.prototype._getCurrentPage = function () { | ||
var pages = location.hash && decodeURIComponent(location.hash) || ''; | ||
if (pages.indexOf('?') == -1) { | ||
return pages.split('#')[1] | ||
return pages.split('#')[1]; | ||
} | ||
pages = pages.substring(pages.indexOf('#') + 1, pages.indexOf('?')); | ||
pages = pages.slice(0,1) === '/' ? pages.split('/')[1] : pages; | ||
pages = pages.slice(0, 1) === '/' ? pages.split('/')[1] : pages; | ||
return pages; | ||
}; | ||
// 获取BSGlobal中参数,如用户id、租户id等 | ||
perfAnalysis.prototype._getCurrentUserinfo = function() { | ||
if (window.BSGlobal) { | ||
var obj = {}; | ||
obj.uid = BSGlobal.loginUserInfo && BSGlobal.loginUserInfo.Id ? BSGlobal.loginUserInfo.Id : 0; | ||
obj.tid = BSGlobal.tenantInfo && BSGlobal.tenantInfo.Id ? BSGlobal.tenantInfo.Id : 0; | ||
obj.appCode = BSGlobal.application ? BSGlobal.application : ""; | ||
obj.sessionId = BSGlobal.start && BSGlobal.start.getTime ? obj.uid + BSGlobal.start.getTime() : 0; | ||
obj.appVersion = BSGlobal.appVersion ? BSGlobal.appVersion : ''; | ||
return obj; | ||
} | ||
}; | ||
// 通用参数 | ||
perfAnalysis.prototype._getCommonParams = function() { | ||
var info = this._getCurrentUserinfo(); | ||
var commonParams = "&appCode=" + info.appCode + "&appName=" + location.host | ||
+ "&uid=" + info.uid + "&tid=" + info.tid + "&sessionId=" + info.sessionId; | ||
return commonParams | ||
} | ||
//处理ajax走performance接口 | ||
perfAnalysis.prototype.addAjax = function(name, state, url, method, traceId, analysisData) { | ||
perfAnalysis.prototype.addAjax = function (name, state, url, method, traceId, analysisData) { | ||
var temp = { | ||
name: name, | ||
time: new Date().getTime(), | ||
url: url, | ||
method: method | ||
name: name, | ||
time: new Date().getTime(), | ||
url: url, | ||
method: method | ||
}; | ||
if (state === 'start') { | ||
@@ -133,9 +116,9 @@ this._fetchItem.push(temp); | ||
//匹配一对ajax,取到开始和结束时间 | ||
for (var i = this._fetchItem.length -1; i >= 0; i--) { | ||
for (var i = this._fetchItem.length - 1; i >= 0; i--) { | ||
if (this._fetchItem[i].name === name && this._fetchItem[i].url === url) { | ||
var url = this._fetchItem[i].url, | ||
method = this._fetchItem[i].method, | ||
var _url = this._fetchItem[i].url, | ||
_method = this._fetchItem[i].method, | ||
time = this._fetchItem[i].time; | ||
this._getAjaxTiming(url, method, time, new Date().getTime(), traceId, analysisData); | ||
this._getAjaxTiming(_url, _method, time, new Date().getTime(), traceId, analysisData); | ||
this._fetchItem.splice(i, 1); //移除已匹配成功的ajax | ||
@@ -148,31 +131,46 @@ } | ||
//获取ajax请求的时间数据 | ||
perfAnalysis.prototype._getAjaxTiming = function(url, method, start, end, traceId, analysisData) { | ||
var sourceActionName = analysisData && analysisData['sourceActionName'] || '' //来源动作名称 | ||
var sourceActionCode = analysisData && analysisData['sourceActionCode'] || '' //来源动作名称 | ||
var pageCode = analysisData && analysisData['pageCode'] || '' //来源页面编码 | ||
var dataKey = analysisData && analysisData['dataKey'] || '' //数据id | ||
var page = analysisData && analysisData['pages'] || '' //数据来源页面 | ||
perfAnalysis.prototype._getAjaxTiming = function (url, method, start, end, traceId, analysisData) { | ||
/* | ||
* sourceActionName: 来源动作名称 | ||
* sourceActionCode:来源动作编码 | ||
* pageCode:来源页面编码 | ||
* dataKey:数据id | ||
* pages: 数据来源页面 | ||
*/ | ||
var _analysisData$sourceA = analysisData.sourceActionName, | ||
sourceActionName = _analysisData$sourceA === undefined ? '' : _analysisData$sourceA, | ||
_analysisData$sourceA2 = analysisData.sourceActionCode, | ||
sourceActionCode = _analysisData$sourceA2 === undefined ? '' : _analysisData$sourceA2, | ||
_analysisData$pageCod = analysisData.pageCode, | ||
pageCode = _analysisData$pageCod === undefined ? '' : _analysisData$pageCod, | ||
_analysisData$dataKey = analysisData.dataKey, | ||
dataKey = _analysisData$dataKey === undefined ? '' : _analysisData$dataKey, | ||
_analysisData$pages = analysisData.pages, | ||
pages = _analysisData$pages === undefined ? '' : _analysisData$pages; | ||
var labelName = '[ajax][' + method + ']' + url; | ||
var time = end - start; | ||
var info = this._getCurrentUserinfo(); | ||
pages = page ? page : this._getCurrentPage() | ||
var logData = Object.assign({}, (0, _utils.getCurrentUserinfo)(), { | ||
start: start, | ||
end: end, | ||
traceId: traceId, | ||
pageCode: pageCode, | ||
cid: 2, | ||
label: encodeURIComponent((0, _utils.handleEncode)('[ajax][' + method + ']' + url)), | ||
pages: pages ? pages : this._getCurrentPage(), | ||
time: end - start, | ||
modelInfo: JSON.stringify(dataKey), | ||
actionName: encodeURIComponent((0, _utils.handleEncode)(sourceActionName)), | ||
actionCode: sourceActionCode, | ||
terminalType: (0, _utils.getTerminalType)(), | ||
ts: new Date().getTime() | ||
}); | ||
labelName = utils.handleEncode(labelName) | ||
sourceActionName = utils.handleEncode(sourceActionName) | ||
var commonParams = this._getCommonParams(); | ||
var params = "?cid=" + 2 + "&label=" + encodeURIComponent(labelName) | ||
+ "&start=" + start + "&end=" + end + '&time=' + time + '&ts=' + new Date().getTime() | ||
+ "&pages=" + pages + "&traceId=" + traceId + "&actionName=" + encodeURIComponent(sourceActionName) + "&actionCode=" + sourceActionCode | ||
+ "&pageCode=" + pageCode + "&modelInfo=" + JSON.stringify(dataKey) + "&version=" + info.appVersion + commonParams | ||
// var isPC = utils.getTerminalType() === 'pc' ? true : false | ||
// var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > 0 ? true : false | ||
// var params | ||
// let isPC = getTerminalType() === 'pc' ? true : false | ||
// let isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > 0 ? true : false | ||
// let params | ||
// pc端 非ie调performance | ||
// if ('performance' in window && window.performance.getEntries && isPC && isChrome) { | ||
// var ajaxPerf = window.performance.getEntries(); | ||
// ajaxPerf = utils.uniqueArr(ajaxPerf); | ||
// for (var i = 0; i < ajaxPerf.length; i++) { | ||
// var name; | ||
// let ajaxPerf = window.performance.getEntries(); | ||
// ajaxPerf = uniqueArr(ajaxPerf); | ||
// for (let i = 0; i < ajaxPerf.length; i++) { | ||
// let name; | ||
// if (typeof(ajaxPerf[i].name) === 'string' && ajaxPerf[i].name.indexOf("%22") && ajaxPerf[i].name.indexOf("TableList")!==-1) { | ||
@@ -184,3 +182,3 @@ // name = ajaxPerf[i].name.replace(/\%22/g,"\"") | ||
// if (ajaxPerf[i].entryType === "resource" && ajaxPerf[i].initiatorType === '' && name.indexOf(url) > -1) { | ||
// var t = this._getCommonPerf(ajaxPerf[i]); | ||
// let t = this._getCommonPerf(ajaxPerf[i]); | ||
// params = commonParam + "&traceId=" + traceId + "&actionName=" + sourceActionName + "&actionCode=" + sourceActionCode | ||
@@ -193,46 +191,10 @@ // + "&pageCode=" + pageCode + "&modelInfo=" + JSON.stringify(dataKey) + "&version=" + info.appVersion; | ||
// } else { | ||
// params = commonParam | ||
this._sendDataToOps(params); | ||
// params = commonParam | ||
this._sendDataToOps(logData); | ||
// } | ||
}; | ||
//获取performance数据的公共方法 | ||
perfAnalysis.prototype._getCommonPerf = function(t, sign) { | ||
var newPerf = {}; | ||
if (t) { | ||
//兼容IE10,10无下边这些属性 | ||
newPerf.redirect = t.redirectEnd && t.redirectStart ? Math.ceil(t.redirectEnd - t.redirectStart) : 0; | ||
newPerf.dns = t.domainLookupEnd && t.domainLookupStart ? Math.ceil(t.domainLookupEnd - t.domainLookupStart) : 0; | ||
newPerf.connect = t.connectEnd && t.connectStart ? Math.ceil(t.connectEnd - t.connectStart) : 0; | ||
newPerf.request = t.responseStart && t.requestStart ? Math.ceil(t.responseStart - t.requestStart) : 0; | ||
newPerf.response = t.responseEnd && t.responseStart ? Math.ceil(t.responseEnd - t.responseStart) : 0; | ||
//performance.timing(sign为true)和performance.getEntries为不同的sign | ||
if (sign) { | ||
newPerf.domReady = t.domContentLoadedEventStart - t.responseEnd; | ||
newPerf.pageLoaded = t.loadEventStart - t.responseEnd; | ||
newPerf.pageTotal = t.loadEventEnd - t.navigationStart; | ||
} else { | ||
newPerf.totalTime = Math.ceil(t.duration); | ||
} | ||
} | ||
return newPerf; | ||
}; | ||
//page浏览器数据收集 | ||
perfAnalysis.prototype._pagePerformance = function() { | ||
if ('performance' in window && 'timing' in window.performance) { | ||
var t = window.performance.timing; | ||
var ns = t.navigationStart; //开始获取网页的时间 | ||
var newPerf = this._getCommonPerf(t, true); | ||
return "&pagetimestamp=" + ns + "&redirecttime=" + newPerf.redirect + "&dnstime=" | ||
+ newPerf.dns + "&contime=" + newPerf.connect + "&reqtime=" + newPerf.request + "&resptime=" | ||
+ newPerf.response + "&dreadytime=" + newPerf.domReady + "&loadtime=" + newPerf.pageLoaded | ||
+ "&totaltime=" + newPerf.pageTotal; | ||
} | ||
}; | ||
//将splash/ajax/all数据发至运维接口 | ||
perfAnalysis.prototype._sendDataToOps = function(params) { | ||
//启用性能打点开关 | ||
perfAnalysis.prototype._sendDataToOps = function (params) { | ||
//启用性能打点开关 | ||
// if (!BSGlobal.IsUseUxPMS) { | ||
@@ -243,17 +205,7 @@ // return; | ||
if (BSGlobal && BSGlobal.env) { | ||
var terminalType = utils.getTerminalType(); | ||
var lowEnv = BSGlobal.env.toLocaleLowerCase(); | ||
var img = new Image; | ||
var paramStr = params + "&terminalType=" + terminalType; | ||
if (lowEnv && lowEnv.indexOf('production') == 0) { | ||
img.src = location.protocol + defineData.prodOpsUrl + paramStr; | ||
} else if (lowEnv == 'testing') { | ||
img.src = location.protocol + defineData.testOpsUrl + paramStr; | ||
} else if (lowEnv == 'development') { | ||
img.src = location.protocol + defineData.devOpsUrl + paramStr; | ||
} else if (lowEnv == 'labs') { | ||
img.src = location.protocol + defineData.labsOpsUrl + paramStr; | ||
} else if (lowEnv == 'sandbox') { | ||
img.src = location.protocol + defineData.sandOpsUrl + paramStr; | ||
} | ||
var restParams = (0, _utils.objToLink)(params); | ||
restParams = restParams.substring(0, restParams.length - 1); //去掉结尾多余的& | ||
var url = _opsUrl2.default[BSGlobal.env.toLocaleLowerCase()] + '?' + restParams; | ||
var img = new Image(); | ||
img.src = url; | ||
} | ||
@@ -263,3 +215,3 @@ }; | ||
//公共性能打点方法 | ||
perfAnalysis.prototype._up = function(label, time, pages, step) { | ||
perfAnalysis.prototype._up = function (label, time, pages, step) { | ||
//启用性能打点开关 | ||
@@ -269,16 +221,17 @@ // if (!BSGlobal.IsUseUxPMS) { | ||
// } | ||
var logData = Object.assign({}, (0, _utils.getCurrentUserinfo)(), { | ||
pages: pages, | ||
time: time, | ||
label: encodeURIComponent((0, _utils.handleEncode)(label)), | ||
terminalType: (0, _utils.getTerminalType)(), | ||
ts: new Date().getTime() | ||
}); | ||
label = utils.handleEncode(label) | ||
var commonParams = this._getCommonParams(); | ||
var upParams = "?label=" + encodeURIComponent(label)+ '&time=' + time | ||
+ '&ts=' + new Date().getTime() + "&pages=" + pages + commonParams; | ||
var params | ||
var params = void 0; | ||
if (label && label.indexOf('ajax') > 0) { | ||
params = upParams + "&cid=" + 2 | ||
params = Object.assign({}, logData, { cid: 2 }); | ||
} else { | ||
params = upParams + "&cid=" + 5 | ||
params = Object.assign({}, logData, { cid: 5 }); | ||
} | ||
this._sendDataToOps(params); | ||
@@ -288,42 +241,42 @@ }; | ||
// 公共首屏计算 | ||
perfAnalysis.prototype._splash = function(pageId) { | ||
var labelName = '[splash]' + location.protocol + '//' + location.host + location.hash; | ||
label = utils.handleEncode(labelName) | ||
perfAnalysis.prototype._splash = function (pageId) { | ||
if (!window.performance || !window.performance.timing) { | ||
return; | ||
} | ||
// 首屏时间:调用_splash时间 - performance.timing.navigatorStart | ||
try { | ||
var splashTime = performance.now(); | ||
var splashTime = void 0; | ||
if (performance.now) { | ||
splashTime = performance.now(); | ||
splashTime = splashTime.toString().split('.')[0]; | ||
} catch(e) { | ||
console.info('not support performance now'); | ||
return; | ||
} else { | ||
var t = window.performance.timing; | ||
splashTime = new Date().getTime() - t.navigationStart; | ||
} | ||
var pages = this._getCurrentPage() | ||
var firstContentPaint = 0; | ||
try { | ||
var paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime | ||
} catch(e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint' ) | ||
firstContentPaint = paintData[0].startTime; | ||
} catch (e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint'); | ||
} | ||
var commonParams = this._getCommonParams(); | ||
var pageParams = this._pagePerformance(); //page performance参数 | ||
var logData = Object.assign({}, (0, _utils.getCurrentUserinfo)(), (0, _utils.getPagePerformance)(), { | ||
pageId: pageId, | ||
firstContentPaint: firstContentPaint, | ||
cid: 1, | ||
label: encodeURIComponent((0, _utils.handleEncode)('[splash]' + location.protocol + '//' + location.host + location.hash)), | ||
pages: this._getCurrentPage(), | ||
time: splashTime, | ||
terminalType: (0, _utils.getTerminalType)(), | ||
ts: new Date().getTime() | ||
}); | ||
var params = "?cid=" + 1 + "&pages=" + pages + "&label=" + encodeURIComponent(label) | ||
+ '&time=' + splashTime + '&ts=' + new Date().getTime() + "&pageId=" + pageId | ||
+ '&firstContentPaint=' + firstContentPaint + commonParams + pageParams; | ||
this._sendDataToOps(logData); | ||
}; | ||
this._sendDataToOps(params); | ||
} | ||
//公共行为打点方法 | ||
perfAnalysis.prototype._upAction = function(modelInfo, cmp_id, page, step) { | ||
}; | ||
perfAnalysis.prototype._upAction = function (modelInfo, cmp_id, page, step) {}; | ||
/***/ }, | ||
@@ -333,19 +286,18 @@ /* 3 */ | ||
module.exports = { | ||
devOpsUrl: "//dev.opsapi.beisencorp.com/opsapi/AddPerformnanceLog", | ||
testOpsUrl: "//opsapi.italent.link/opsapi/AddPerformnanceLog", | ||
prodOpsUrl: "//opsapi.beisen.com/opsapi/AddPerformnanceLog", | ||
labsOpsUrl: "//labs.opsapi.beisencorp.com/opsapi/AddPerformnanceLog", | ||
sandOpsUrl: "//opsapi.upaas.in/opsapi/AddPerformnanceLog", | ||
type: 1, | ||
step: 0, | ||
sw: screen.width || 0, | ||
sh: screen.height || 0, | ||
ww: window.innerHeight || 0, | ||
wh: window.innerWidth || 0 | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var url = { | ||
development: "//dev.opsapi.beisencorp.com/opsapi/AddPerformnanceLog", | ||
testing: "//opsapi.italent.link/opsapi/AddPerformnanceLog", | ||
production: "//opsapi.beisen.com/opsapi/AddPerformnanceLog", | ||
labs: "//labs.opsapi.beisencorp.com/opsapi/AddPerformnanceLog", | ||
sandbox: "//opsapi.upaas.in/opsapi/AddPerformnanceLog" | ||
}; | ||
exports.default = url; | ||
/***/ }, | ||
@@ -355,65 +307,154 @@ /* 4 */ | ||
'use strict'; | ||
module.exports = { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getCurrentUserinfo = getCurrentUserinfo; | ||
exports.getCommonPerf = getCommonPerf; | ||
exports.getPagePerformance = getPagePerformance; | ||
exports.objToLink = objToLink; | ||
exports.getTerminalType = getTerminalType; | ||
exports.handleEncode = handleEncode; | ||
// 获取BSGlobal中参数,如用户id、租户id等 | ||
function getCurrentUserinfo() { | ||
if (window.BSGlobal) { | ||
var _BSGlobal = BSGlobal, | ||
_BSGlobal$loginUserIn = _BSGlobal.loginUserInfo, | ||
loginUserInfo = _BSGlobal$loginUserIn === undefined ? { Id: 0 } : _BSGlobal$loginUserIn, | ||
_BSGlobal$tenantInfo = _BSGlobal.tenantInfo, | ||
tenantInfo = _BSGlobal$tenantInfo === undefined ? { Id: 0 } : _BSGlobal$tenantInfo, | ||
application = _BSGlobal.application, | ||
_BSGlobal$start = _BSGlobal.start, | ||
start = _BSGlobal$start === undefined ? {} : _BSGlobal$start, | ||
_BSGlobal$appVersion = _BSGlobal.appVersion, | ||
appVersion = _BSGlobal$appVersion === undefined ? '' : _BSGlobal$appVersion; | ||
isArray: function(arr) { | ||
return Object.prototype.toString.call(arr) === '[object Array]'; | ||
}, | ||
//去除performance请求中的重复数据 | ||
uniqueArr: function(array) { | ||
var a = JSON.parse(JSON.stringify(array)); | ||
var r = []; | ||
for(var i = 0, l = a.length; i < l; i++) { | ||
for(var j = i + 1; j < l; j++) | ||
if (a[i].name == a[j].name) j = ++i; | ||
r.push(a[i]); | ||
return { | ||
uid: loginUserInfo.Id, | ||
tid: tenantInfo.Id, | ||
appCode: application, | ||
sessionId: start.getTime ? '' + loginUserInfo.Id + BSGlobal.start.getTime() : 0, | ||
appName: location.host, | ||
version: appVersion, | ||
scrWidth: screen.width || 0, | ||
scrHeight: screen.height || 0, | ||
winheight: window.innerHeight || 0, | ||
winwidth: window.innerWidth || 0 | ||
}; | ||
} | ||
}; | ||
function getCommonPerf(t, sign) { | ||
var newPerf = {}; | ||
if (t) { | ||
//兼容IE10,10无下边这些属性 | ||
newPerf.redirect = t.redirectEnd && t.redirectStart ? Math.ceil(t.redirectEnd - t.redirectStart) : 0; | ||
newPerf.dns = t.domainLookupEnd && t.domainLookupStart ? Math.ceil(t.domainLookupEnd - t.domainLookupStart) : 0; | ||
newPerf.connect = t.connectEnd && t.connectStart ? Math.ceil(t.connectEnd - t.connectStart) : 0; | ||
newPerf.request = t.responseStart && t.requestStart ? Math.ceil(t.responseStart - t.requestStart) : 0; | ||
newPerf.response = t.responseEnd && t.responseStart ? Math.ceil(t.responseEnd - t.responseStart) : 0; | ||
//performance.timing(sign为true)和performance.getEntries为不同的sign | ||
if (sign) { | ||
newPerf.domReady = t.domContentLoadedEventStart - t.responseEnd; | ||
newPerf.pageLoaded = t.loadEventStart - t.responseEnd; | ||
newPerf.pageTotal = t.loadEventEnd - t.navigationStart; | ||
} else { | ||
newPerf.totalTime = Math.ceil(t.duration); | ||
} | ||
return r; | ||
}, | ||
} | ||
return newPerf; | ||
}; | ||
//page浏览器数据收集 | ||
function getPagePerformance() { | ||
if ('performance' in window && 'timing' in window.performance) { | ||
var t = window.performance.timing; | ||
var ns = t.navigationStart; //开始获取网页的时间 | ||
var newPerf = getCommonPerf(t, true); | ||
var redirect = newPerf.redirect, | ||
dns = newPerf.dns, | ||
connect = newPerf.connect, | ||
request = newPerf.request, | ||
response = newPerf.response, | ||
domReady = newPerf.domReady, | ||
pageLoaded = newPerf.pageLoaded, | ||
pageTotal = newPerf.pageTotal; | ||
//生成guid | ||
getGuid: function() { | ||
var s = []; | ||
var hexDigits = "0123456789abcdef"; | ||
for (var i = 0; i < 36; i++) { | ||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
} | ||
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 | ||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 | ||
s[8] = s[13] = s[18] = s[23] = "-"; | ||
return { | ||
pagetimestamp: ns, | ||
redirecttime: redirect, | ||
dnstime: dns, | ||
contime: connect, | ||
reqtime: request, | ||
resptime: response, | ||
dreadytime: domReady, | ||
loadtime: pageLoaded, | ||
totaltime: pageTotal | ||
}; | ||
} | ||
}; | ||
var uuid = s.join(""); | ||
return uuid; | ||
}, | ||
function objToLink(obj) { | ||
var link = ''; | ||
for (var i in obj) { | ||
link += i + '=' + obj[i] + '&'; | ||
} | ||
return link; | ||
} | ||
//判断pc/mobile | ||
getTerminalType: function() { | ||
var ua = navigator.userAgent; | ||
var isMobile = ua.indexOf('Mobile') > 0; | ||
var isWeixin = !!ua.match(/MicroMessenger/i);//判断是否微信平台 | ||
var isWeibo = !!ua.match(/Weibo/i); //判断是否微博平台 | ||
var isBeisenApp = !!ua.match(/BeisenApp/i) && !ua.match(/Apicloud/i); | ||
var isApiCloud = ua.toLowerCase().match(/apicloud/i); | ||
var isUpaasApp = ua.toLowerCase().match(/upaasapp/i); | ||
var isDingTalk = !!ua.match(/DingTalk/i); | ||
if (isMobile || isWeixin || isWeibo || isBeisenApp || isApiCloud || isUpaasApp || isDingTalk) { | ||
return 'mobile'; | ||
}else { | ||
return 'pc'; | ||
// export function isArray(arr) { | ||
// return Object.prototype.toString.call(arr) === '[object Array]'; | ||
// } | ||
// export function uniqueArr(array) { | ||
// let a = JSON.parse(JSON.stringify(array)); | ||
// let r = []; | ||
// for(let i = 0, l = a.length; i < l; i++) { | ||
// for(let j = i + 1; j < l; j++) | ||
// if (a[i].name == a[j].name) j = ++i; | ||
// r.push(a[i]); | ||
// } | ||
// return r; | ||
// } | ||
// export function getGuid() { | ||
// let s = []; | ||
// let hexDigits = "0123456789abcdef"; | ||
// for (let i = 0; i < 36; i++) { | ||
// s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
// } | ||
// s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 | ||
// s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 | ||
// s[8] = s[13] = s[18] = s[23] = "-"; | ||
// let uuid = s.join(""); | ||
// return uuid; | ||
// } | ||
function getTerminalType() { | ||
var ua = navigator.userAgent; | ||
var isMobile = ua.indexOf('Mobile') > 0; | ||
var isWeixin = !!ua.match(/MicroMessenger/i); //判断是否微信平台 | ||
var isWeibo = !!ua.match(/Weibo/i); //判断是否微博平台 | ||
var isBeisenApp = !!ua.match(/BeisenApp/i) && !ua.match(/Apicloud/i); | ||
var isApiCloud = ua.toLowerCase().match(/apicloud/i); | ||
var isUpaasApp = ua.toLowerCase().match(/upaasapp/i); | ||
var isDingTalk = !!ua.match(/DingTalk/i); | ||
if (isMobile || isWeixin || isWeibo || isBeisenApp || isApiCloud || isUpaasApp || isDingTalk) { | ||
return 'mobile'; | ||
} else { | ||
return 'pc'; | ||
} | ||
} | ||
// decodeURIComponent有%时会报错 | ||
function handleEncode(value) { | ||
try { | ||
return decodeURIComponent(escape(value)); | ||
} catch (e) { | ||
value = value && value.indexOf('%') !== -1 ? value.replace(/%/g, '百分') : value; | ||
try { | ||
return decodeURIComponent(value); | ||
} catch (e) { | ||
return 'has error'; | ||
} | ||
}, | ||
// decodeURIComponent有%时会报错 | ||
handleEncode: function(value) { | ||
try { | ||
return decodeURIComponent(escape(value)) | ||
} catch(e) { | ||
value = value && value.indexOf('%') !== -1 ? value.replace(/%/g, '百分') : value | ||
try { | ||
return decodeURIComponent(value) | ||
} catch(e) { | ||
return 'has error' | ||
} | ||
} | ||
} | ||
@@ -420,0 +461,0 @@ } |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.objToLink = objToLink; | ||
exports.performance = performance; | ||
var defineData = require("../../src/common/defineData.js"); | ||
var envMapping = { | ||
'production': defineData.prodOpsUrl, | ||
'testing': defineData.testOpsUrl, | ||
'development': defineData.devOpsUrl | ||
}; | ||
var _opsUrl = require('../../src/common/opsUrl'); | ||
function objToLink(obj) { | ||
var link = ''; | ||
for (var i in obj) { | ||
link += i + '=' + obj[i] + '&'; | ||
} | ||
return link; | ||
} | ||
var _opsUrl2 = _interopRequireDefault(_opsUrl); | ||
var _utils = require('../../src/common/utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function performance() { | ||
var pageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var pageId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
if (!window.performance || !window.performance.timing) { | ||
return; | ||
} | ||
var t = window.performance.timing; | ||
var page = location.hash.slice(1) || ''; | ||
page = page.indexOf('?') > -1 ? page.split('?')[0] : page; | ||
if (!window.performance || !window.performance.timing) { | ||
return; | ||
} | ||
var t = window.performance.timing; | ||
var page = location.hash.slice(1) || ''; | ||
page = page.indexOf('?') > -1 ? page.split('?')[0] : page; | ||
if (!BSGlobal) { | ||
return; | ||
} | ||
var firstContentPaint = 0; | ||
try { | ||
var paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime; | ||
} catch (e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint'); | ||
} | ||
var now = new Date(); | ||
var logData = { | ||
appCode: BSGlobal.appInfo.appCode, //应用编码 | ||
appName: location.host, | ||
cid: 1, //首屏标识 | ||
label: encodeURIComponent('[splash]' + location.protocol + '//' + location.host + location.hash), | ||
uid: BSGlobal.loginUserInfo.Id || 0, | ||
tid: BSGlobal.tenantInfo.Id || 0, | ||
sessonId: BSGlobal.start && BSGlobal.start.getTime ? BSGlobal.loginUserInfo.Id + BSGlobal.start.getTime() : 0, | ||
ts: now.getTime(), | ||
scrWidth: screen.width || 0, | ||
scrHeight: screen.height || 0, | ||
winheight: window.innerHeight || 0, | ||
winwidth: window.innerWidth || 0, | ||
pages: page, | ||
pagetimestamp: t.navigationStart, | ||
redirecttime: t.redirectEnd - t.redirectStart, | ||
dnstime: t.domainLookupEnd - t.domainLookupStart, | ||
contime: t.connectEnd - t.connectStart, | ||
reqtime: t.responseStart - t.requestStart, | ||
resptime: t.responseEnd - t.responseStart, | ||
dreadytime: t.domContentLoadedEventStart - t.responseEnd, | ||
loadtime: t.loadEventStart - t.responseEnd, | ||
totaltime: t.loadEventEnd - t.navigationStart, | ||
time: now.getTime() - t.navigationStart, | ||
firstContentPaint: firstContentPaint, | ||
pageId: pageId // 页面唯一标识,若无则发路由名称 | ||
}; | ||
if (!BSGlobal) return; | ||
var restLink = objToLink(logData); | ||
if (BSGlobal.env) { | ||
var url = envMapping[BSGlobal.env.toLocaleLowerCase()] + '?' + restLink; | ||
var img = new Image(); | ||
img.src = url; | ||
} | ||
var firstContentPaint = 0; | ||
try { | ||
var paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime; | ||
} catch (e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint'); | ||
} | ||
var logData = Object.assign({}, (0, _utils.getCurrentUserinfo)(), (0, _utils.getPagePerformance)(), { | ||
cid: 1, //首屏标识 | ||
label: encodeURIComponent('[splash]' + location.protocol + '//' + location.host + location.hash), | ||
pages: page, | ||
time: new Date().getTime() - t.navigationStart, | ||
terminalType: (0, _utils.getTerminalType)(), | ||
firstContentPaint: firstContentPaint, | ||
pageId: pageId // 页面唯一标识,若无则发路由名称 | ||
}); | ||
if (BSGlobal.env) { | ||
var restLink = (0, _utils.objToLink)(logData); | ||
var url = _opsUrl2.default[BSGlobal.env.toLocaleLowerCase()] + '?' + restLink; | ||
var img = new Image(); | ||
img.src = url; | ||
} | ||
} |
{ | ||
"name": "@beisen\/analysis-pms", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib\/component\/index.js", |
@@ -47,2 +47,4 @@ # iTalentPMS | ||
### 0.3.4 使用es6重构代码 | ||
### 0.3.3 新增npm引用方式 | ||
### 0.3.1 大版本 | ||
@@ -49,0 +51,0 @@ * 新增首屏收集方法 |
var parseObj = require("./common/parseObj.js"); | ||
var defineData = require("./common/defineData.js"); | ||
var defineData = require("./common/opsUrl.js"); | ||
var perfAnalysis = require("./perfAnalysis.js"); | ||
@@ -4,0 +4,0 @@ |
@@ -0,65 +1,125 @@ | ||
// 获取BSGlobal中参数,如用户id、租户id等 | ||
export function getCurrentUserinfo() { | ||
if (window.BSGlobal) { | ||
const { loginUserInfo = {Id: 0}, tenantInfo = {Id: 0}, application, start = {}, appVersion = '' } = BSGlobal | ||
return { | ||
uid: loginUserInfo.Id, | ||
tid: tenantInfo.Id, | ||
appCode: application, | ||
sessionId: start.getTime ? `${loginUserInfo.Id}${BSGlobal.start.getTime()}` : 0, | ||
appName: location.host, | ||
version: appVersion, | ||
scrWidth: screen.width || 0, | ||
scrHeight: screen.height || 0, | ||
winheight: window.innerHeight || 0, | ||
winwidth: window.innerWidth || 0 | ||
} | ||
} | ||
}; | ||
export function getCommonPerf(t, sign) { | ||
let newPerf = {}; | ||
if (t) { | ||
//兼容IE10,10无下边这些属性 | ||
newPerf.redirect = t.redirectEnd && t.redirectStart ? Math.ceil(t.redirectEnd - t.redirectStart) : 0; | ||
newPerf.dns = t.domainLookupEnd && t.domainLookupStart ? Math.ceil(t.domainLookupEnd - t.domainLookupStart) : 0; | ||
newPerf.connect = t.connectEnd && t.connectStart ? Math.ceil(t.connectEnd - t.connectStart) : 0; | ||
newPerf.request = t.responseStart && t.requestStart ? Math.ceil(t.responseStart - t.requestStart) : 0; | ||
newPerf.response = t.responseEnd && t.responseStart ? Math.ceil(t.responseEnd - t.responseStart) : 0; | ||
//performance.timing(sign为true)和performance.getEntries为不同的sign | ||
if (sign) { | ||
newPerf.domReady = t.domContentLoadedEventStart - t.responseEnd; | ||
newPerf.pageLoaded = t.loadEventStart - t.responseEnd; | ||
newPerf.pageTotal = t.loadEventEnd - t.navigationStart; | ||
} else { | ||
newPerf.totalTime = Math.ceil(t.duration); | ||
} | ||
} | ||
return newPerf; | ||
}; | ||
//page浏览器数据收集 | ||
export function getPagePerformance() { | ||
if ('performance' in window && 'timing' in window.performance) { | ||
let t = window.performance.timing; | ||
let ns = t.navigationStart; //开始获取网页的时间 | ||
let newPerf = getCommonPerf(t, true); | ||
const {redirect, dns, connect, request, response, domReady, pageLoaded, pageTotal } = newPerf | ||
return { | ||
pagetimestamp: ns, | ||
redirecttime: redirect, | ||
dnstime: dns, | ||
contime: connect, | ||
reqtime: request, | ||
resptime: response, | ||
dreadytime: domReady, | ||
loadtime: pageLoaded, | ||
totaltime: pageTotal | ||
} | ||
} | ||
}; | ||
export function objToLink(obj) { | ||
let link = ''; | ||
for(let i in obj) { | ||
link += `${i}=${obj[i]}&` ; | ||
} | ||
return link | ||
} | ||
module.exports = { | ||
// export function isArray(arr) { | ||
// return Object.prototype.toString.call(arr) === '[object Array]'; | ||
// } | ||
isArray: function(arr) { | ||
return Object.prototype.toString.call(arr) === '[object Array]'; | ||
}, | ||
// export function uniqueArr(array) { | ||
// let a = JSON.parse(JSON.stringify(array)); | ||
// let r = []; | ||
// for(let i = 0, l = a.length; i < l; i++) { | ||
// for(let j = i + 1; j < l; j++) | ||
// if (a[i].name == a[j].name) j = ++i; | ||
// r.push(a[i]); | ||
// } | ||
// return r; | ||
// } | ||
//去除performance请求中的重复数据 | ||
uniqueArr: function(array) { | ||
var a = JSON.parse(JSON.stringify(array)); | ||
var r = []; | ||
for(var i = 0, l = a.length; i < l; i++) { | ||
for(var j = i + 1; j < l; j++) | ||
if (a[i].name == a[j].name) j = ++i; | ||
r.push(a[i]); | ||
} | ||
return r; | ||
}, | ||
// export function getGuid() { | ||
// let s = []; | ||
// let hexDigits = "0123456789abcdef"; | ||
// for (let i = 0; i < 36; i++) { | ||
// s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
// } | ||
// s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 | ||
// s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 | ||
// s[8] = s[13] = s[18] = s[23] = "-"; | ||
//生成guid | ||
getGuid: function() { | ||
var s = []; | ||
var hexDigits = "0123456789abcdef"; | ||
for (var i = 0; i < 36; i++) { | ||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); | ||
} | ||
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 | ||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 | ||
s[8] = s[13] = s[18] = s[23] = "-"; | ||
// let uuid = s.join(""); | ||
// return uuid; | ||
// } | ||
var uuid = s.join(""); | ||
return uuid; | ||
}, | ||
export function getTerminalType() { | ||
let ua = navigator.userAgent; | ||
let isMobile = ua.indexOf('Mobile') > 0; | ||
let isWeixin = !!ua.match(/MicroMessenger/i);//判断是否微信平台 | ||
let isWeibo = !!ua.match(/Weibo/i); //判断是否微博平台 | ||
let isBeisenApp = !!ua.match(/BeisenApp/i) && !ua.match(/Apicloud/i); | ||
let isApiCloud = ua.toLowerCase().match(/apicloud/i); | ||
let isUpaasApp = ua.toLowerCase().match(/upaasapp/i); | ||
let isDingTalk = !!ua.match(/DingTalk/i); | ||
if (isMobile || isWeixin || isWeibo || isBeisenApp || isApiCloud || isUpaasApp || isDingTalk) { | ||
return 'mobile'; | ||
} else { | ||
return 'pc'; | ||
} | ||
} | ||
//判断pc/mobile | ||
getTerminalType: function() { | ||
var ua = navigator.userAgent; | ||
var isMobile = ua.indexOf('Mobile') > 0; | ||
var isWeixin = !!ua.match(/MicroMessenger/i);//判断是否微信平台 | ||
var isWeibo = !!ua.match(/Weibo/i); //判断是否微博平台 | ||
var isBeisenApp = !!ua.match(/BeisenApp/i) && !ua.match(/Apicloud/i); | ||
var isApiCloud = ua.toLowerCase().match(/apicloud/i); | ||
var isUpaasApp = ua.toLowerCase().match(/upaasapp/i); | ||
var isDingTalk = !!ua.match(/DingTalk/i); | ||
if (isMobile || isWeixin || isWeibo || isBeisenApp || isApiCloud || isUpaasApp || isDingTalk) { | ||
return 'mobile'; | ||
}else { | ||
return 'pc'; | ||
} | ||
}, | ||
// decodeURIComponent有%时会报错 | ||
handleEncode: function(value) { | ||
// decodeURIComponent有%时会报错 | ||
export function handleEncode(value) { | ||
try { | ||
return decodeURIComponent(escape(value)) | ||
} catch(e) { | ||
value = value && value.indexOf('%') !== -1 ? value.replace(/%/g, '百分') : value | ||
try { | ||
return decodeURIComponent(escape(value)) | ||
return decodeURIComponent(value) | ||
} catch(e) { | ||
value = value && value.indexOf('%') !== -1 ? value.replace(/%/g, '百分') : value | ||
try { | ||
return decodeURIComponent(value) | ||
} catch(e) { | ||
return 'has error' | ||
} | ||
} | ||
} | ||
} | ||
return 'has error' | ||
} | ||
} | ||
} |
@@ -1,72 +0,38 @@ | ||
const defineData = require("../../src/common/defineData.js"); | ||
import opsUrl from '../../src/common/opsUrl' | ||
import { objToLink, getCurrentUserinfo, getPagePerformance, getTerminalType } from '../../src/common/utils' | ||
const envMapping = { | ||
'production': defineData.prodOpsUrl, | ||
'testing': defineData.testOpsUrl, | ||
'development': defineData.devOpsUrl | ||
} | ||
export function performance(pageId = '') { | ||
if(!window.performance || !window.performance.timing) { | ||
return | ||
} | ||
let t = window.performance.timing | ||
let page = location.hash.slice(1) || ''; | ||
page = page.indexOf('?') > -1 ? page.split('?')[0] : page | ||
export function objToLink(obj) { | ||
let link = ''; | ||
for(let i in obj) { | ||
link += `${i}=${obj[i]}&` ; | ||
} | ||
return link | ||
} | ||
if(!BSGlobal) return | ||
let firstContentPaint = 0; | ||
try { | ||
let paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime | ||
} catch(e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint' ) | ||
} | ||
export function performance(pageId = '') { | ||
if(!window.performance || !window.performance.timing) { | ||
return | ||
} | ||
let t = window.performance.timing | ||
let page = location.hash.slice(1) || ''; | ||
page = page.indexOf('?') > -1 ? page.split('?')[0] : page | ||
if( !BSGlobal){ | ||
return; | ||
} | ||
let firstContentPaint = 0; | ||
try { | ||
let paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime | ||
} catch(e) { | ||
console.info('not support performance getEntriesByName, can not get firstContentPaint' ) | ||
} | ||
let now = new Date(); | ||
let logData = { | ||
appCode: BSGlobal.appInfo.appCode,//应用编码 | ||
appName: location.host, | ||
cid: 1,//首屏标识 | ||
label: encodeURIComponent('[splash]' + location.protocol + '//' + location.host + location.hash), | ||
uid: BSGlobal.loginUserInfo.Id || 0, | ||
tid: BSGlobal.tenantInfo.Id || 0, | ||
sessonId: BSGlobal.start && BSGlobal.start.getTime ? BSGlobal.loginUserInfo.Id + BSGlobal.start.getTime() : 0, | ||
ts: now.getTime(), | ||
scrWidth: screen.width || 0, | ||
scrHeight: screen.height || 0, | ||
winheight: window.innerHeight || 0, | ||
winwidth: window.innerWidth || 0, | ||
pages: page, | ||
pagetimestamp: t.navigationStart, | ||
redirecttime: t.redirectEnd - t.redirectStart, | ||
dnstime: t.domainLookupEnd - t.domainLookupStart, | ||
contime: t.connectEnd - t.connectStart, | ||
reqtime: t.responseStart - t.requestStart, | ||
resptime: t.responseEnd - t.responseStart, | ||
dreadytime: t.domContentLoadedEventStart - t.responseEnd, | ||
loadtime: t.loadEventStart - t.responseEnd, | ||
totaltime: t.loadEventEnd - t.navigationStart, | ||
time: now.getTime() - t.navigationStart, | ||
firstContentPaint, | ||
pageId // 页面唯一标识,若无则发路由名称 | ||
} | ||
let logData = Object.assign({}, getCurrentUserinfo(), getPagePerformance(), { | ||
cid: 1,//首屏标识 | ||
label: encodeURIComponent('[splash]' + location.protocol + '//' + location.host + location.hash), | ||
pages: page, | ||
time: new Date().getTime() - t.navigationStart, | ||
terminalType: getTerminalType(), | ||
firstContentPaint, | ||
pageId // 页面唯一标识,若无则发路由名称 | ||
}) | ||
if (BSGlobal.env) { | ||
let restLink = objToLink(logData); | ||
if (BSGlobal.env) { | ||
const url = `${envMapping[BSGlobal.env.toLocaleLowerCase()]}?${restLink}`; | ||
let img = new Image(); | ||
img.src = url; | ||
} | ||
const url = `${opsUrl[BSGlobal.env.toLocaleLowerCase()]}?${restLink}`; | ||
let img = new Image(); | ||
img.src = url; | ||
} | ||
} |
@@ -1,16 +0,10 @@ | ||
var perfAnalysis = require('../src/perfAnalysis.js'); | ||
import perfAnalysis from '../src/perfAnalysis' | ||
((function(){ | ||
if(window.iTalentPMS) { | ||
window.iTalentPMS && window.iTalentPMS.clearAll && window.iTalentPMS.clearAll(); | ||
return; | ||
} | ||
window.iTalentPMS = new perfAnalysis(); | ||
//收集移动端行为数据 | ||
window.collectMobileAction = function(type, event) { | ||
// actionAnaly.commonEvent(type, event, true); | ||
}; | ||
})()) |
@@ -1,3 +0,3 @@ | ||
var defineData = require("./common/defineData.js"); | ||
var utils = require("./common/utils.js"); | ||
import opsUrl from './common/opsUrl' | ||
import { handleEncode, getTerminalType, getCurrentUserinfo, objToLink, getPagePerformance } from './common/utils' | ||
@@ -12,3 +12,3 @@ function perfAnalysis() { | ||
perfAnalysis.prototype._getCurrentPage = function() { | ||
var pages = location.hash && decodeURIComponent(location.hash) || ''; | ||
let pages = location.hash && decodeURIComponent(location.hash) || ''; | ||
if (pages.indexOf('?') == -1) { | ||
@@ -22,26 +22,5 @@ return pages.split('#')[1] | ||
// 获取BSGlobal中参数,如用户id、租户id等 | ||
perfAnalysis.prototype._getCurrentUserinfo = function() { | ||
if (window.BSGlobal) { | ||
var obj = {}; | ||
obj.uid = BSGlobal.loginUserInfo && BSGlobal.loginUserInfo.Id ? BSGlobal.loginUserInfo.Id : 0; | ||
obj.tid = BSGlobal.tenantInfo && BSGlobal.tenantInfo.Id ? BSGlobal.tenantInfo.Id : 0; | ||
obj.appCode = BSGlobal.application ? BSGlobal.application : ""; | ||
obj.sessionId = BSGlobal.start && BSGlobal.start.getTime ? obj.uid + BSGlobal.start.getTime() : 0; | ||
obj.appVersion = BSGlobal.appVersion ? BSGlobal.appVersion : ''; | ||
return obj; | ||
} | ||
}; | ||
// 通用参数 | ||
perfAnalysis.prototype._getCommonParams = function() { | ||
var info = this._getCurrentUserinfo(); | ||
var commonParams = "&appCode=" + info.appCode + "&appName=" + location.host | ||
+ "&uid=" + info.uid + "&tid=" + info.tid + "&sessionId=" + info.sessionId; | ||
return commonParams | ||
} | ||
//处理ajax走performance接口 | ||
perfAnalysis.prototype.addAjax = function(name, state, url, method, traceId, analysisData) { | ||
var temp = { | ||
let temp = { | ||
name: name, | ||
@@ -57,5 +36,5 @@ time: new Date().getTime(), | ||
//匹配一对ajax,取到开始和结束时间 | ||
for (var i = this._fetchItem.length -1; i >= 0; i--) { | ||
for (let i = this._fetchItem.length -1; i >= 0; i--) { | ||
if (this._fetchItem[i].name === name && this._fetchItem[i].url === url) { | ||
var url = this._fetchItem[i].url, | ||
let url = this._fetchItem[i].url, | ||
method = this._fetchItem[i].method, | ||
@@ -73,30 +52,36 @@ time = this._fetchItem[i].time; | ||
perfAnalysis.prototype._getAjaxTiming = function(url, method, start, end, traceId, analysisData) { | ||
var sourceActionName = analysisData && analysisData['sourceActionName'] || '' //来源动作名称 | ||
var sourceActionCode = analysisData && analysisData['sourceActionCode'] || '' //来源动作名称 | ||
var pageCode = analysisData && analysisData['pageCode'] || '' //来源页面编码 | ||
var dataKey = analysisData && analysisData['dataKey'] || '' //数据id | ||
var page = analysisData && analysisData['pages'] || '' //数据来源页面 | ||
/* | ||
* sourceActionName: 来源动作名称 | ||
* sourceActionCode:来源动作编码 | ||
* pageCode:来源页面编码 | ||
* dataKey:数据id | ||
* pages: 数据来源页面 | ||
*/ | ||
let {sourceActionName = '', sourceActionCode = '', pageCode = '', dataKey = '', pages = ''} = analysisData | ||
let logData = Object.assign({}, getCurrentUserinfo(), { | ||
start, | ||
end, | ||
traceId, | ||
pageCode, | ||
cid: 2, | ||
label: encodeURIComponent(handleEncode(`[ajax][${method}]${url}`)), | ||
pages: pages ? pages : this._getCurrentPage(), | ||
time: end - start, | ||
modelInfo: JSON.stringify(dataKey), | ||
actionName: encodeURIComponent(handleEncode(sourceActionName)), | ||
actionCode: sourceActionCode, | ||
terminalType: getTerminalType(), | ||
ts: new Date().getTime() | ||
}) | ||
var labelName = '[ajax][' + method + ']' + url; | ||
var time = end - start; | ||
var info = this._getCurrentUserinfo(); | ||
pages = page ? page : this._getCurrentPage() | ||
labelName = utils.handleEncode(labelName) | ||
sourceActionName = utils.handleEncode(sourceActionName) | ||
var commonParams = this._getCommonParams(); | ||
var params = "?cid=" + 2 + "&label=" + encodeURIComponent(labelName) | ||
+ "&start=" + start + "&end=" + end + '&time=' + time + '&ts=' + new Date().getTime() | ||
+ "&pages=" + pages + "&traceId=" + traceId + "&actionName=" + encodeURIComponent(sourceActionName) + "&actionCode=" + sourceActionCode | ||
+ "&pageCode=" + pageCode + "&modelInfo=" + JSON.stringify(dataKey) + "&version=" + info.appVersion + commonParams | ||
// var isPC = utils.getTerminalType() === 'pc' ? true : false | ||
// var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > 0 ? true : false | ||
// var params | ||
// let isPC = getTerminalType() === 'pc' ? true : false | ||
// let isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > 0 ? true : false | ||
// let params | ||
// pc端 非ie调performance | ||
// if ('performance' in window && window.performance.getEntries && isPC && isChrome) { | ||
// var ajaxPerf = window.performance.getEntries(); | ||
// ajaxPerf = utils.uniqueArr(ajaxPerf); | ||
// for (var i = 0; i < ajaxPerf.length; i++) { | ||
// var name; | ||
// let ajaxPerf = window.performance.getEntries(); | ||
// ajaxPerf = uniqueArr(ajaxPerf); | ||
// for (let i = 0; i < ajaxPerf.length; i++) { | ||
// let name; | ||
// if (typeof(ajaxPerf[i].name) === 'string' && ajaxPerf[i].name.indexOf("%22") && ajaxPerf[i].name.indexOf("TableList")!==-1) { | ||
@@ -108,3 +93,3 @@ // name = ajaxPerf[i].name.replace(/\%22/g,"\"") | ||
// if (ajaxPerf[i].entryType === "resource" && ajaxPerf[i].initiatorType === '' && name.indexOf(url) > -1) { | ||
// var t = this._getCommonPerf(ajaxPerf[i]); | ||
// let t = this._getCommonPerf(ajaxPerf[i]); | ||
// params = commonParam + "&traceId=" + traceId + "&actionName=" + sourceActionName + "&actionCode=" + sourceActionCode | ||
@@ -118,42 +103,6 @@ // + "&pageCode=" + pageCode + "&modelInfo=" + JSON.stringify(dataKey) + "&version=" + info.appVersion; | ||
// params = commonParam | ||
this._sendDataToOps(params); | ||
this._sendDataToOps(logData); | ||
// } | ||
}; | ||
//获取performance数据的公共方法 | ||
perfAnalysis.prototype._getCommonPerf = function(t, sign) { | ||
var newPerf = {}; | ||
if (t) { | ||
//兼容IE10,10无下边这些属性 | ||
newPerf.redirect = t.redirectEnd && t.redirectStart ? Math.ceil(t.redirectEnd - t.redirectStart) : 0; | ||
newPerf.dns = t.domainLookupEnd && t.domainLookupStart ? Math.ceil(t.domainLookupEnd - t.domainLookupStart) : 0; | ||
newPerf.connect = t.connectEnd && t.connectStart ? Math.ceil(t.connectEnd - t.connectStart) : 0; | ||
newPerf.request = t.responseStart && t.requestStart ? Math.ceil(t.responseStart - t.requestStart) : 0; | ||
newPerf.response = t.responseEnd && t.responseStart ? Math.ceil(t.responseEnd - t.responseStart) : 0; | ||
//performance.timing(sign为true)和performance.getEntries为不同的sign | ||
if (sign) { | ||
newPerf.domReady = t.domContentLoadedEventStart - t.responseEnd; | ||
newPerf.pageLoaded = t.loadEventStart - t.responseEnd; | ||
newPerf.pageTotal = t.loadEventEnd - t.navigationStart; | ||
} else { | ||
newPerf.totalTime = Math.ceil(t.duration); | ||
} | ||
} | ||
return newPerf; | ||
}; | ||
//page浏览器数据收集 | ||
perfAnalysis.prototype._pagePerformance = function() { | ||
if ('performance' in window && 'timing' in window.performance) { | ||
var t = window.performance.timing; | ||
var ns = t.navigationStart; //开始获取网页的时间 | ||
var newPerf = this._getCommonPerf(t, true); | ||
return "&pagetimestamp=" + ns + "&redirecttime=" + newPerf.redirect + "&dnstime=" | ||
+ newPerf.dns + "&contime=" + newPerf.connect + "&reqtime=" + newPerf.request + "&resptime=" | ||
+ newPerf.response + "&dreadytime=" + newPerf.domReady + "&loadtime=" + newPerf.pageLoaded | ||
+ "&totaltime=" + newPerf.pageTotal; | ||
} | ||
}; | ||
//将splash/ajax/all数据发至运维接口 | ||
@@ -167,17 +116,7 @@ perfAnalysis.prototype._sendDataToOps = function(params) { | ||
if (BSGlobal && BSGlobal.env) { | ||
var terminalType = utils.getTerminalType(); | ||
var lowEnv = BSGlobal.env.toLocaleLowerCase(); | ||
var img = new Image; | ||
var paramStr = params + "&terminalType=" + terminalType; | ||
if (lowEnv && lowEnv.indexOf('production') == 0) { | ||
img.src = location.protocol + defineData.prodOpsUrl + paramStr; | ||
} else if (lowEnv == 'testing') { | ||
img.src = location.protocol + defineData.testOpsUrl + paramStr; | ||
} else if (lowEnv == 'development') { | ||
img.src = location.protocol + defineData.devOpsUrl + paramStr; | ||
} else if (lowEnv == 'labs') { | ||
img.src = location.protocol + defineData.labsOpsUrl + paramStr; | ||
} else if (lowEnv == 'sandbox') { | ||
img.src = location.protocol + defineData.sandOpsUrl + paramStr; | ||
} | ||
let restParams = objToLink(params); | ||
restParams = restParams.substring(0, restParams.length -1) //去掉结尾多余的& | ||
const url = `${opsUrl[BSGlobal.env.toLocaleLowerCase()]}?${restParams}`; | ||
let img = new Image(); | ||
img.src = url; | ||
} | ||
@@ -192,14 +131,15 @@ }; | ||
// } | ||
let logData = Object.assign({}, getCurrentUserinfo(), { | ||
pages, | ||
time, | ||
label: encodeURIComponent(handleEncode(label)), | ||
terminalType: getTerminalType(), | ||
ts: new Date().getTime() | ||
}) | ||
label = utils.handleEncode(label) | ||
var commonParams = this._getCommonParams(); | ||
var upParams = "?label=" + encodeURIComponent(label)+ '&time=' + time | ||
+ '&ts=' + new Date().getTime() + "&pages=" + pages + commonParams; | ||
var params | ||
let params | ||
if (label && label.indexOf('ajax') > 0) { | ||
params = upParams + "&cid=" + 2 | ||
params = Object.assign({}, logData, {cid: 2}) | ||
} else { | ||
params = upParams + "&cid=" + 5 | ||
params = Object.assign({}, logData, {cid: 5}) | ||
} | ||
@@ -212,19 +152,19 @@ | ||
perfAnalysis.prototype._splash = function(pageId) { | ||
var labelName = '[splash]' + location.protocol + '//' + location.host + location.hash; | ||
label = utils.handleEncode(labelName) | ||
if (!window.performance || !window.performance.timing) { | ||
return | ||
} | ||
// 首屏时间:调用_splash时间 - performance.timing.navigatorStart | ||
try { | ||
var splashTime = performance.now(); | ||
let splashTime | ||
if (performance.now) { | ||
splashTime = performance.now() | ||
splashTime = splashTime.toString().split('.')[0]; | ||
} catch(e) { | ||
console.info('not support performance now'); | ||
return; | ||
} else { | ||
let t = window.performance.timing | ||
splashTime = new Date().getTime() - t.navigationStart | ||
} | ||
var pages = this._getCurrentPage() | ||
var firstContentPaint = 0; | ||
let firstContentPaint = 0; | ||
try { | ||
var paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
let paintData = performance.getEntriesByName("first-contentful-paint", "paint"); | ||
firstContentPaint = paintData[0].startTime | ||
@@ -235,11 +175,15 @@ } catch(e) { | ||
var commonParams = this._getCommonParams(); | ||
var pageParams = this._pagePerformance(); //page performance参数 | ||
let logData = Object.assign({}, getCurrentUserinfo(), getPagePerformance(), { | ||
pageId, | ||
firstContentPaint, | ||
cid: 1, | ||
label: encodeURIComponent(handleEncode('[splash]' + location.protocol + '//' + location.host + location.hash)), | ||
pages: this._getCurrentPage(), | ||
time: splashTime, | ||
terminalType: getTerminalType(), | ||
ts: new Date().getTime() | ||
}) | ||
this._sendDataToOps(logData); | ||
var params = "?cid=" + 1 + "&pages=" + pages + "&label=" + encodeURIComponent(label) | ||
+ '&time=' + splashTime + '&ts=' + new Date().getTime() + "&pageId=" + pageId | ||
+ '&firstContentPaint=' + firstContentPaint + commonParams + pageParams; | ||
this._sendDataToOps(params); | ||
} | ||
@@ -246,0 +190,0 @@ |
@@ -9,2 +9,11 @@ var webpack = require('webpack'); | ||
}, | ||
module : { | ||
loaders : [ | ||
{ | ||
loader : 'babel-loader', | ||
test : /\.js$/, | ||
exclude : /node_modules/ | ||
} | ||
] | ||
}, | ||
output: { | ||
@@ -14,2 +23,5 @@ path: path.join( __dirname, '/dist' ), | ||
}, | ||
resolve: { | ||
extensions: ['', '.js'] | ||
}, | ||
plugins: [ | ||
@@ -16,0 +28,0 @@ new webpack.DefinePlugin({ |
@@ -8,2 +8,14 @@ var webpack = require('webpack'); | ||
}, | ||
module : { | ||
loaders : [ | ||
{ | ||
loader : 'babel-loader', | ||
test : /\.js$/, | ||
exclude : /node_modules/ | ||
} | ||
] | ||
}, | ||
resolve: { | ||
extensions: ['', '.js'] | ||
}, | ||
output: { | ||
@@ -10,0 +22,0 @@ path: path.join( __dirname, '/dist' ), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6400
166
240061