Tyler
Tyler

Reputation: 1049

How can I change a custom property name in Application Insights data

Is there a way to change the name of a custom property for existing page view data in Application Insights?

Upvotes: 0

Views: 1820

Answers (1)

Dmitry Matveev
Dmitry Matveev

Reputation: 2679

You can change any properties on page view event before it left the browser with telemetry initializer:

Add this code immediately after the initialization snippet that you get from the portal.

...
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 of insertion

appInsights.trackPageView();

Also, you can rename columns at the query time in the Analytics query by aliasing them or copying them:

pageViews | summarize sum(itemCount) by NameB=tostring(customDimensions.NameA) | ...

pageViews | extend NameB = customDimensions.NameA | ...

Upvotes: 2

Related Questions