How to add Google Analytics to the Modern SharePoint

Having an analytics tool monitoring your intranet is essential to understand the engagement of the users and how they are interacting with the content that is published. Google Analytics is widely used in the internet, it provides a concise analysis with reports of everything that happens in your site as well as real time reports, mostly targeted for public sites it also works on SharePoint intranets. Earlier this year I wrote an article that explains step by step how to add Google Analytics to SharePoint without modifying the master page, while that solution is still valid for classic SharePoint it doesn’t work on the modern sites and libraries. In this article, I explain step by step how to build and deploy an Application Customizer using the SharePoint Framework Extensions, I am also providing the installation files and the instructions to use it if you don’t want to build it yourself. How to setup Google Analytics First things first, before we get into the SharePoint bits let’s set up google analytics and get everything you need. Sign in to your Analytics account Select the Admin tab Select an account from the menu in the ACCOUNT column, or CREATE NEW ACCOUNT if you don’t have one already Select a property from the menu in the PROPERTY column Under PROPERTY, click Tracking Info Tracking Code Save the Tracking Id More information about google analytics setup can be found here. Create the Application Customizer Extension project The Application Customizer is one of the available extension types provided by the SharePoint Framework and allows you to add custom JavaScript to every page in a site or web. To achieve the steps below you need to have installed the SPFx v1.4 or higher, you can get the latest version from here. Create a folder with the name of the project e.g. analytics Open the console window in the new directory Type the command yo @microsoft/sharepoint When prompted: Accept the default app-extension as your solution name, and press Enter. Choose SharePoint Online only (latest), and press Enter. Choose Use the current folder, and press Enter. Choose Y … Continue reading How to add Google Analytics to the Modern SharePoint