- 确认已启用用户流程功能,具体可以参考以下代码示例:
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","Dependency"];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:"YOUR_INSTRUMENTATION_KEY"
});
appInsights.trackPageView();
appInsights.trackEvent("myCustomEvent", {customProperty: "custom property value"});
appInsights.trackException({exception: new Error("handled exceptions can be logged with this method")});
appInsights.trackMetric("myCustomMetric", 3.14);
var user = { name: "12345" };
appInsights.setAuthenticatedUserContext(user.name);
appInsights.clearAuthenticatedUserContext();
- 如果已启用用户流程功能,确保在应用程序中跟踪“pageview”事件。具体方法可以参考以下代码示例:
appInsights.trackPageView("pageName");
- 确认在应用程序代码中已向 Application Insights 发送关键信息 (For example: UserID, sessionID)。可以通过以下代码示例将 UserID 添加到“AuthenticatedUserContext”中:
var user = { name: "12345" };
appInsights.setAuthenticatedUserContext(user.name);