问题
When I go into the Azure Application Insights resource for my Dev web app, and go to view Usage, I see a link that says 'Learn how to collect page view data'.
The link gives me the code below.
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: "1x1111x1-1x1x-1x1x-xx11-xxxxxxxxxxxx"
});
window.appInsights = appInsights;
appInsights.trackPageView();
When I run/debug my page, I receive these messages in the browser console window:
POST http://dc.services.visualstudio.com/v2/track 400 (Invalid instrumentation key) - dc.services.visualstudio.com/v2/track:1
AI (Internal): NONUSRACT_OnError message:"Failed to send telemetry." props:"{message:{\itemsReceived:3,\itemsAccepted:0,\errors:[{\index:0,\statusCode:400,\message:\Invalid instrumentation key},{\index:1,\statusCode:400,\message:\Invalid instrumentation key},{\index:2,\statusCode:400,\message:\Invalid instrumentation key}]}}" - ai.0.js:1
In my actual code, I am using the key they provided me in the sample, which matches the key in properties. Why do I receive these errors?
More background data:
I have an AppInsights.js
file with the above code, and load it via my BundleConfig in the <head>
of my _Layout.cshtml
file like this:
@Scripts.RenderFormat("<script src='{0}' defer></script>", "~/bundles/scripts")
We do need the defer tag for some of the scripts we load.
来源:https://stackoverflow.com/questions/36633131/application-insights-page-view-code-gives-me-client-side-errors