How to track SharePoint usage with Google Analytics
Google Analytics is the number one tracking tool in the internet and despite have not being designed to be used in intranets it works perfectly with SharePoint.
In this post you will learn how you can easily install Google Analytics on modern sites in SharePoint Online, this solution has support for the new Google Analytics 4.
How to add Google Analytics to SharePoint
The solution use here is available in the PnP GitHub repository however it needs to be compiled in order to get installed in your tenant. In this article I’m providing you the installation package ready to be used in your tenant, to do it please follow the instructions below:
- Start by download the installation file from here
- Open your global app catalog if you want to monitor all the modern site collections in your tenant or the local site collection app catalog if you just want to monitor an individual site collection. To learn more about the differences between the site collection app catalogs have a look here.
- Upload the solution to the app catalog
- In the deployment pop-up make sure you select the option Make this solution available to all sites in the organization, this option will deploy the solution automatically without the need to manually add the app
- The Google Analytics solution is provided with 3 custom properties that need to be configured to get start tracking your pages.
- If you are installing the solution in the global app catalog the Tenant Wide Extensions is available directly from the Site Contents.
- If you are installing it in a site collection, the Tenant Wide Extensions list is hidden and you need to use the following URL adjusted to your tenant and site collection URL https://contoso.sharepoint.com/sites/projectx/Lists/TenantWideExtensions/AllItems.aspx.
- Edit the item with the title Analytics
- Replace the Component Properties Value by the following code
- Replace the value in the trackingId property by your Google Analytics code
- If your organization does not primarily use modern browsers to access your SharePoint tenant, you can default to the non-asynchronous script loading method by changing the property disableAsync value from false to true
- Ig your tracking code starts with G- it means you are already using Google Analytics 4, in this case change the property googleAnalyticsV4 value from false to true
- Click Save
From this moment on your SharePoint environment is being tracked by Google Analytics as shown in the following image.
Other Google Analytics scenarios and solutions for SharePoint Online and SharePoint On-Prem
I’ve writing and building solutions to integrate Analytics in SharePoint for a few years now, if you are looking for a solution for a SharePoint version that is not covered by this article, please have a look to the following list: