DOXFX使用Application Insights最终用户用户分析

时间:2017-06-10 08:38:42

标签: azure-application-insights docfx

如何将应用洞察最终用户用户分析添加到DocFx以跟踪每个文档页面的使用情况?

Application Insights文档声明您需要在结束标记之前插入下面列出的JavaScript代码段,但我不确定这是否可以在DocFx中实现,或者是最好的方法。

您需要后处理器,还是可以使用自定义模板?

<!-- 
To collect end-user usage analytics about your application, 
insert the following script into each page you want to track.
Place this code immediately before the closing </head> tag,
and before any other scripts. Your first data will appear 
automatically in just a few seconds.
-->
<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&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t
    }({
        instrumentationKey:"###-###-###-##"
    });

    window.appInsights=appInsights;
    appInsights.trackPageView();
</script>

1 个答案:

答案 0 :(得分:1)

不需要PostProcessor。您可以通过自定义模板来实现此目的。可以在official tutorialthis question中找到更多信息。您可以在partials/head.tmpl.partial中添加代码。它会影响所有生成的页面。