gpt4 book ai didi

azure - 如何为 Azure App Insights 中的页面 View 事件提供自定义名称?

转载 作者:行者123 更新时间:2023-12-03 16:24:14 24 4
gpt4 key购买 nike

默认情况下,App Insights 使用页面标题作为事件名称。拥有动态页面名称(例如“Order 32424”)会产生大量的事件类型。

Documentation关于此事说要使用 trackEvent 方法,但没有示例。

appInsights.trackEvent("Edit button clicked", { "Source URL": "http://www.contoso.com/index" })

最好的方法是什么?拥有某种映射/过滤器将是完美的,它允许将某些页面的事件名称修改为共享名称,例如“Order 23424”=>“Order”,同时保留大多数页面不变。

最佳答案

您应该能够利用 telemetry initializer将事件名称中的某些模式替换为该名称的更“常见”版本的方法。

以下是来自 Application Insights JS SDK GitHub 的示例,介绍如何在发送 pageView 数据之前对其进行修改。通过稍加修改,您可以使用它根据事件的外观更改事件名称:

window.appInsights = appInsights;
...
// Add telemetry initializer
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(function (envelope) {
var telemetryItem = envelope.data.baseData;

// To check the telemetry item’s type:
if (envelope.name === Microsoft.ApplicationInsights.Telemetry.PageView.envelopeType) {
// this statement removes url from all page view documents
telemetryItem.url = "URL CENSORED";
}

// To set custom properties:
telemetryItem.properties = telemetryItem.properties || {};
telemetryItem.properties["globalProperty"] = "boo";

// To set custom metrics:
telemetryItem.measurements = telemetryItem.measurements || {};
telemetryItem.measurements["globalMetric"] = 100;
});
});
// end

...
appInsights.trackPageView();
appInsights.trackEvent(...);

关于azure - 如何为 Azure App Insights 中的页面 View 事件提供自定义名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53778932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com