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: "f566074f-b141-4ad1-8fa1-97a41ca8ee62"
});
window.appInsights = appInsights;
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(function (envelope) {
var telemetryItem = envelope.data.baseData;
if (envelope.name === Microsoft.ApplicationInsights.Telemetry.PageView.envelopeType) {
telemetryItem.url = "URL CENSORED";
}
telemetryItem.properties = telemetryItem.properties || {};
telemetryItem.properties["globalProperty"] = "boo";
telemetryItem.measurements = telemetryItem.measurements || {};
telemetryItem.measurements["globalMetric"] = 100;
});
});
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[
^]