Azure Application Insights - 禁用记录页面视图

Azure Application Insights - Disable Logging Page Views

我有一个用 JavaScript 编写的单页应用程序。我目前正在使用 JavaScript API 将事件记录到 Azure Application Insights。我注意到 Application Insights 会自动将所有页面视图写入 Application Insights。但是,我只对将自定义事件写入 Application Insights 感兴趣。

有没有办法禁用记录页面浏览量?换句话说,我能否仅使用 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
});