How to add Application Insights to SharePoint without modifying the master page
Google analytics articles are among the most popular articles in this blog and inclusive they got featured on SharePoint Dev Weekly episodes.
On episode #27 Vesa and Waldek discussed the advantages and disadvantages of having internal and potentially confidential data sent from SharePoint to Google servers.
Google Analytics is not the only monitoring tool you can add to SharePoint, Microsoft has Application Insights that provides a similar functionality with the advantage of keeping your data in the same ecosystem.
In this article you will find a solution to add Application Insights to your classic SharePoint sites without modifying the master page, Microsoft also have instructions available here, but it requires the manual manipulation of the master page or the page source code.
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
Install Application Insights on SharePoint
To install the solution in your SharePoint and start tracking your sites follow the steps below:
- Download the solution from here
- On your site collection root site go to Settings -> Site Settings -> Solutions
- Upload and activate the solution
- Open your site with SharePoint designer
- Go to All Files -> Style Library -> Application Insights -> js
- Check out and edit the insights.js file in advanced mode
- Locate the words APPLICATION INSIGHTS and replace it by your own
Once you activate the solution, Application Insights script is immediately added to your site however it is not tracking your site yet, you still need to add your instrumentation key to the script
From this moment on all the sites in your site collection are being tracked by Application Insights and your data will live inside the Microsoft Ecosystem.
The project solution as always is available on GitHub and you can modify it according to your needs.