我有一个用 JavaScript 编写的单页应用程序。我当前正在使用 JavaScript API 将事件记录到 Azure Application Insights。我注意到 Application Insights 会自动将所有页面 View 写入 Application Insights。但是,我只对将自定义事件写入 Application Insights 感兴趣。
有没有办法禁用记录页面 View ?换句话说,我可以使用 Application Insights 仅记录自定义事件、自定义指标和异常吗?
我在 API 文档中没有看到任何内容。谢谢。
最佳答案
您可以通过检查类型并在Telemetry Initializer中返回true/false来限制您想要的遥测类型。创建客户端时如下。
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
const appInsights = new ApplicationInsights({ config: {
instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE'
} });
appInsights.addTelemetryInitializer(t => {
// Update criteria as per your need.
if (t.baseType == 'PageView') // or anything else
return false; // disable
return true; // enable everything else
});
关于Azure Application Insights - 禁用记录页面 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65007124/