/
Azure.ApplicationInsights.TrackingScript.cshtml
34 lines (30 loc) · 1.95 KB
/
Azure.ApplicationInsights.TrackingScript.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@using System.Web
<script type="text/javascript">
var appInsights = window.appInsights || function (config) {
function r(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 = u.createElement(o), i, f; for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop()); return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("_" + i), f = e[i], e[i] = function (config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t["_" + i](config, r, u, e, o), s }), t
}({
instrumentationKey: "@Model.InstrumentationKey"
});
window.appInsights = appInsights;
appInsights.trackPageView();
@{
// Setting the operation ID for the client-side request tracking too. This way the server-side request will
// be possible to correrlate to all subsequent client-side operations (if the page is cached it's OK because
// that means that the same server-side operation correlates to multiple client-side ones).
var requestId = WorkContext.HttpContext.GetOperationIdForRequest();
if (requestId != null)
{
<text>
appInsights.queue.push(function () {
appInsights.context.addTelemetryInitializer(function (envelope) {
envelope.tags["ai.operation.id"] = "@((string)requestId)";
});
});
</text>
}
}
@if (WorkContext.CurrentUser != null)
{
<text>appInsights.setAuthenticatedUserContext("@WorkContext.CurrentUser.Id.ToString()");</text>
}
</script>