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.
- Sign In on the Azure Portal
- On the left bar click on Create Resource
- Search for Application Insights
- Click on Create
- Provide a name for the application
- Select ASP.NET web application on the Application Type
- Create a new Resource Group and provide a name
- Select your data center Location
- Once created click on overview tab
- 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:
- Download and Extract the solution from here
- Open your tenant app catalog
- Click on Apps for SharePoint
- Upload the solution to the catalog
- Check the option Make this solution available to all sites in the organization
- Go to Site Contents
- Open the list Tenant Wide Extensions
- Edit the ModernApplicationInsighs item
- Modify the Component Properties and replace the keyvalue by your Application Insights tracking ID.
- 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.
February 26, 2019
[…] Deploy Application Insights globally on modern SharePoint – João Ferreira (BindTuning) […]
February 26, 2019
Nice one! Does this have the navigation tracking fix/workaround implemented like the Google Analytics one? Thanks!
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.
February 27, 2019
Great work, thanks!
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
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! 🙂
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.
April 17, 2019
Can this solution be deployed at a Site collection level too?
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/
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?
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.
April 24, 2019
Hi Joao,
Will Normal Windows Powershell work?
April 24, 2019
No, you need to install SharePoint Online PowerShell cmdlets
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()
June 10, 2019
Hi Bryan,
Thanks for your feedback.
October 24, 2020
Hi,
This is pretty cool, can this be deployed at a Hub level?
Thank you for your insight.