How to provide custom names for page view events in Azure App Insights?

前端 未结 3 654
说谎
说谎 2021-01-19 14:31

By default App Insights use page title as event name. Having dynamic page names, like \"Order 32424\", creates insane amount of event types.

Documentation on the mat

3条回答
  •  萌比男神i
    2021-01-19 15:21

    You should be able to leverage telemetry initializer approach to replace certain pattern in the event name with the more "common" version of that name.

    Here is the example from Application Insights JS SDK GitHub on how to modify pageView's data before it's sent out. With the slight modification you may use it to change event names based on their appearance:

    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(...);
    

提交回复
热议问题