Deploy Application Insights globally on modern SharePoint

On my last article I’ve provided a solution to deploy Application Insights to classic SharePoint without modifying the master page and on todays article I’m providing the same solution but for modern SharePoint using an Application Customizer and Tenant Wide Deployment.

Setup Application Insights

Before installing Application Insights on SharePoint, you first need to do the setup on your Azure account following the steps below.

  1. Sign In on the Azure Portal
  2. On the left bar click on Create Resource
  3. Search for Application Insights
  4. Click on Create
  5. Provide a name for the application
  6. Select ASP.NET web application on the Application Type
  7. Create a new Resource Group and provide a name
  8. Select your data center Location
  9. Once created click on overview tab
  10. Copy the Instrumentation Key and save it for later

How to use Application Insights on modern SharePoint

This solution can be installed and configured directly through the browser, to do it follow the steps below:

  1. Download and Extract the solution from here
  2. Open your tenant app catalog
  3. Click on Apps for SharePoint
  4. Upload the solution to the catalog
  5. Check the option Make this solution available to all sites in the organization
  6. Go to Site Contents
  7. Open the list Tenant Wide Extensions
  8. Edit the ModernApplicationInsighs item
  9. Modify the Component Properties and replace the keyvalue by your Application Insights tracking ID.
  10. Save the item and all your modern SharePoint site on Office 365 are ready to be monitored. If this was the first solution globally deployed on your tenant, it may take up to 20 minutes get available.

Conclusion

With the modern and classic version of the solution to add Application Insights to SharePoint you will be able to monitor the use of your Intranet without sending your data outside the Microsoft ecosystem.

As always, the source code for this solution is available on GitHub, feel free to use and modify it according to your needs.

Download Application Insights
Explore Solution on GitHub

Infographic vector created by freepik – www.freepik.com


16 Responses to “Deploy Application Insights globally on modern SharePoint”

  1. […] Deploy Application Insights globally on modern SharePoint – João Ferreira (BindTuning) […]

    Reply
  2. Tuomas Pakkanen

    February 26, 2019

    Nice one! Does this have the navigation tracking fix/workaround implemented like the Google Analytics one? Thanks!

    Reply
    • João Ferreira

      February 26, 2019

      Hi Tuomas, that is a great question and I completly forgot to implement it. Let me check if Microsoft already fixed it, if not I’ll update it with the same fix that was made on google analytics.

      Reply
      • Tuomas Pakkanen

        February 27, 2019

        Great work, thanks!

        Reply
  3. Tuomas Pakkanen

    March 2, 2019

    Hi again!

    Another thing I am currently struggling with is setting the authenticated user context and tracking the signed in user. Modifying the code like below breaks the page view tracking (dependencies still seem to be tracked, oddly enough):

    appInsights.setAuthenticatedUserContext(this.context.pageContext.user.email);
    window.appInsights=appInsights,appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView({User: this.context.pageContext.user.email});`);

    Have you come across problems with adding custom data and setting the auth user context? Used to do this kind of code with classic site tracking and it was working OK back then.

    Best regards
    Tuomas

    Reply
    • Tuomas Pakkanen

      March 2, 2019

      Looks like it started working like this:
      appInsights.setAuthenticatedUserContext(this.context.pageContext.user.email);
      window.appInsights=appInsights;
      appInsights.trackPageView({User: this.context.pageContext.user.email});`);

      Maybe the queue part somehow breaks the code. Not really a developer so it’s not super easy! 🙂

      Reply
      • João Ferreira

        March 7, 2019

        Hi Tuomas,

        Thanks for your valuable feedback, I’m thinking about building a new solution to send user data to Application Insights.

        Reply
  4. Gokul

    April 17, 2019

    Can this solution be deployed at a Site collection level too?

    Reply
    • João Ferreira

      April 23, 2019

      Hi Gokul,

      Yes it can be deployed at Site collection level if you create the app catalog in the site collection using PowerShell.
      You can find more information about it here. http://sharepoint-tricks.com/tenant-app-catalog-vs-site-collection-app-catalog/

      Reply
      • Gokul

        April 24, 2019

        Powershell you mean Sharepoint powershell or windows powershell ? Currently in our organization we are not allowed to use Powershell. Is there way for this to work without using powershell?

        Reply
        • João Ferreira

          April 24, 2019

          Hi Gokul,

          There is no other way to create the app catalog without using PowerShell Microsoft is not providing a GUI to enable this functionality.

          Reply
  5. Gokul

    April 24, 2019

    Hi Joao,

    Will Normal Windows Powershell work?

    Reply
    • João Ferreira

      April 24, 2019

      No, you need to install SharePoint Online PowerShell cmdlets

      Reply
  6. Bryan

    May 14, 2019

    The other way to do it at a site collection level is to do the following:

    1) Do all of the steps in “Setup Application Insights”
    2) Do the steps in “How to use Application Insights on modern SharePoint” with the following changes:
    a) Do NOT check the “Make this solution available to all sites in the organization” checkbox in step 5.
    b) Replace steps 6+ with :
    i) Add the app to the site and wait it to be available (a few seconds)
    ii) Run some SharePoint PnP powershell to set the instrumentation key:

    $url = “full site url”
    $key = “your Azure Instrumentation key”

    $name = “ModernAppInsights”
    $compId = “8c39d8f8-036c-4d2f-9796-c1cfdb966fcb”
    $props = “{“”key””:””” + $key + “””}”

    Connect-PnPOnline -UseWebLogin $url
    $clientContext = get-pnpcontext

    $action = Get-PnpCustomAction | Where-Object -Property “ClientSideComponentId” -eq $compId
    $action.ClientSideComponentProperties = $props
    $action.Update()

    Reply
  7. Ishan

    October 24, 2020

    Hi,

    This is pretty cool, can this be deployed at a Hub level?

    Thank you for your insight.

    Reply

Leave a Reply


Web developer focused on SharePoint branding, blogger, tech enthusiast. Travelling and sports are my addictions, knowledge and success are my daily motivations.