1
我試圖保存自定義指標 - 用戶在mu頁面上多長時間 - 使用Application Insights。我寫了下面的代碼(它是一個部分):保存活動之前卸載在JavaScript中的應用程序洞察
var start = new Date();
var recordMetrics = function() {
var end = new Date();
var timeSpentTotal = (end.getTime() - start.getTime())/1000;
if (window.appInsights) {
window.appInsights.trackMetric("timeSpentTotal", timeSpentTotal);
window.appInsights.flush();
console.log("Sent data with timeSpent");
}
}
window.addEventListener("beforeunload",
function (e) {
recordMetrics();
});
但是在刷新之後的每個請求都被取消。我幾乎肯定這是因爲App Insights創建異步AJAX請求。我可以以某種方式將其更改爲同步嗎?或者,也許我做了完全錯誤的事情?
沒有這條線,它不起作用。 –