none
Show User name

    Question

  • Hi,

    I have recently created an insights application, so fetch data from my on-prem SharePoint enviroment.
    So far so good, I am getting alot of data, but one annoying thing, is that even tough I have successfully configured my SharePoint applications to feed usage data to app insights, I still can't see the actual user name, only a useless userID looking something like this: njQBs

    Obviously this is not very usefull, but does anyone know how to get the actual username to show? 

    I tried alot of different stuff already, and I see many articles talking about including some kind of c# code to the global.asax file, but they don't really explain in detail how this is done.

    This is the article that comes the closest to explaining how to achieve this, but details are missing, for someone like me, that has no idea how to add this kind of stuff:

    http://eriksteinebach.com/2016/12/26/Follow-a-specific-user-with-Application-Insights-by-setting-AuthenticatedUserId/

    I also tried this out, but that didint do anything either:

    https://docs.microsoft.com/en-us/azure/application-insights/app-insights-sharepoint

    Hope someone in here has some ideas as to how I can make this work.



    mic



    • Edited by MichaelIT02 Monday, November 19, 2018 12:32 PM
    Monday, November 19, 2018 9:59 AM

All replies

  • Hello Michael,

    SetAuthenticatedUserContext() is the right way to achieve this. You will, most likely, need to add it to the SharePoint master page into AI script right before tracking page view and set this method to drop a user cookie as well via the third parameter of that method (if your site is OK with dropping non-essential cookies and already notifies user about it):

    setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string, storeInCookie = false)

    That should do the trick.


    Dmitry Matveev

    Tuesday, November 20, 2018 2:12 AM
    Owner
  • Hi Dmitry,

    Thank you for the reply.

    So if I understand you correctly, the script should just look like this:

    <script type="text/javascript">
    var appInsights=window.appInsights||function(a){
      function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
      }({
          instrumentationKey:"xxx"
      });
    setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string, storeInCookie = false)
    window.appInsights=appInsights,appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView();
    </script>



    mic



    • Edited by MichaelIT02 Monday, November 26, 2018 7:48 AM Clean up script
    Tuesday, November 20, 2018 8:58 AM
  • Hello Michael,

    I would expect that you'd add your actual values to the setAuthenticatedUserContext() call, for instance:

    setAuthenticatedUserContext("User1", "Account1", true)

    Or, better, with variables:

    setAuthenticatedUserContext(currentUserId, currentAccount, true)
    Apart from that, the script you posted looks like the default one, so should work just fine.

    Dmitry Matveev

    Thursday, November 29, 2018 10:57 PM
    Owner