use Google Analytics in SharePoint Online, you need to add the Google Analytics tracking code to your SharePoint site. Here are the steps to do this:
-
Sign up for a Google Analytics account and create a new property for your SharePoint site.
-
Once you have created the property, you will be provided with a tracking ID. Copy the tracking ID as you will need it in the next step.
-
In SharePoint Online, go to Site Settings and select the option for “Design Manager”.
-
From the Design Manager, choose “Edit Master Pages”.
-
Select the master page you want to edit, and choose “Edit File” from the dropdown menu.
-
In the code editor, add the Google Analytics tracking code just before the closing </head> tag.
Here is an example of what the tracking code should look like:
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>