Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have added application insight into my Azure web app.

Currently, it shows this info:
User Id: MoRjc
Location: New York, United States
Device: Chrome 74.0, Windows 10

Already tried adding this code snippet from Microsoft:
<script type="text/javascript">
        var appInsights = window.appInsights || function (config) {
            function i(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } } var t = { config: config }, u = document, e = window, o = "script", s = "AuthenticatedUserContext", h = "start", c = "stop", l = "Track", a = l + "Event", v = l + "Page", y = u.createElement(o), r, f; y.src = config.url || "https://az416426.vo.msecnd.net/scripts/a/ai.0.js"; u.getElementsByTagName(o)[0].parentNode.appendChild(y); try { t.cookie = u.cookie } catch (p) { } for (t.queue = [], t.version = "1.0", r = ["Event", "Exception", "Metric", "PageView", "Trace", "Dependency"]; r.length;)i("track" + r.pop()); return i("set" + s), i("clear" + s), i(h + a), i(c + a), i(h + v), i(c + v), i("flush"), config.disableExceptionTracking || (r = "onerror", i("_" + r), f = e[r], e[r] = function (config, i, u, e, o) { var s = f & amp;& amp; f(config, i, u, e, o); return s !== !0 & amp;& amp; t["_" + r](config, i, u, e, o), s }), t
        }({
            //instrumentationKey: "11e145f2-a54e-414e-ad55-66d3bce9ca2e" //Prod
            instrumentationKey: "f566074f-b141-4ad1-8fa1-97a41ca8ee62"
        });

        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();
    </script>

    @if (User.Identity.IsAuthenticated)
    {
        <script>
            var appInsightsUserName = '@User.Identity.Name.Replace("\\", "\\\\")';
            appInsights.setAuthenticatedUserContext(appInsightsUserName.replace(/[,;=| ]+/g, "_"));
        </script>
}

Is there a missing code that I am not doing? Because I still can't get the authenticated user ID.

What I have tried:

User Id property is set incorrectly · Issue #571 · microsoft/ApplicationInsights-JS · GitHub[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900