How To Add Google Analytics To The Modern Sharepoint

How To Articles

Adding Google Analytics to the modern SharePoint site is a great way to track and analyze user activity on your site. As a web developer, I have found Google Analytics to be an invaluable tool for gaining insights into user behavior and making data-driven decisions to improve the user experience. In this article, I will guide you through the process of adding Google Analytics to your modern SharePoint site.

Step 1: Sign up for Google Analytics

The first step is to sign up for a Google Analytics account if you don’t have one already. Simply visit the Google Analytics website and follow the instructions to create a new account. Once you have created your account, you will be provided with a unique tracking ID.

Step 2: Access SharePoint Settings

Next, navigate to your SharePoint site and click on the gear icon in the top right corner to access the settings menu. From the dropdown menu, select “Site settings” to open the site settings page.

Step 3: Add Google Analytics Tracking Code

In the site settings page, scroll down to the “Web Designer Galleries” section and click on “Master pages and page layouts”. This will open the master pages and page layouts gallery. Locate the master page file that you want to edit (usually named “seattle.master”) and click on it to open the file.

Once the master page file is open, find the <head> section of the code. This is where we will add the Google Analytics tracking code. Insert the following code snippet just before the closing </head> tag:

<script async src=""></script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'YOUR_TRACKING_ID');

Make sure to replace “YOUR_TRACKING_ID” with the actual tracking ID you obtained from Google Analytics in Step 1.

Step 4: Save and Publish

After adding the tracking code, save the master page file and publish it. This will apply the changes to all pages on your SharePoint site. Keep in mind that modifying the master page file may require administrative privileges.

Step 5: Verify Tracking

To verify that Google Analytics is correctly tracking your SharePoint site, visit your site and navigate to a few different pages. Then, log in to your Google Analytics account and go to the “Real-Time” section. You should see live data showing the number of active users on your site.


By adding Google Analytics to your modern SharePoint site, you gain valuable insights into user behavior and can make data-driven decisions to improve the user experience. With the ability to track and analyze user activity, you can identify popular content, measure campaign effectiveness, and optimize your site for better engagement. Incorporating Google Analytics is a simple yet powerful way to enhance your SharePoint site.