How to add Google Analytics in SharePoint Online

add google analytics to sharepoint online

In this SharePoint Online tutorial, we will discuss how to add Google Analytics in SharePoint Online. The same way also, we can add google analytics in SharePoint 2013/2016 sites.

We will also discuss what is google analytics and how we can generate the google analytics code which we can add in SharePoint sites.


What is Google Analytics:

Google Analytics is a web analytics service offered by Google that tracks and reports website traffic.

Google Analytics is a free service provided by Google. We can analytics our Internal or external site through this service. By using this service we can track the most viewed site and what sites do you need to improve.

Google analytics SharePoint
Google analytics SharePoint

In this article, I explain step by step how to build Google Analytics in SharePoint online.

How to setup Google Analytics

You need to have a Google Analytics account before setup this. For creating the free account you have to click on https://www.google.com/analytics/.

Step 1: Login to the Analytics site -> Click on Admin in left menu -> Create New Account

Google analytics SharePoint Online
Google analytics SharePoint Online

Step 2: Next It will appear a new account where you have to register your web site. Here you can select the Website or Mobile app according to your requirement.

Next enter your Account name, Website Name and Website URL. In the Website URL, you can use either http or https as per your application URL.

The Website URL should be same as your application URL.

add google analytics to sharepoint
add google analytics to sharepoint

Step 3: Next choose the Industry category and Reporting time zone. In Data Sharing Settings you can select all option as per below screenshot.

add google analytics to sharepoint online
add google analytics to sharepoint online

Step 4: Next click on Get Tracking Id to generate the ID which you have to configure in your application.

how to add google analytics to sharepoint online
how to add google analytics to sharepoint online

Step 5: Next click on all check box as per below screen shot and Click on I Accept to generate the code.

how to add google analytics to sharepoint
how to add google analytics to sharepoint

Step 6: Next it will generate a JavaScript code which you can simply copy and paste it in your SharePoint application.

how to add google analytics to sharepoint online
how to add google analytics to sharepoint online

Add google analytics to SharePoint Online

Step 7: The below is my code which has generated over here and we will add the below code in our SharePoint Online site.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-139800411-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-139800411-1');
</script>

Step 8: Next login to your SharePoint site and use the same code in your SharePoint page. Whether you can create a custom web part to use this code and activate this feature for your site collection or you can simply use this code inside your Master page.

Note: Here for testing purpose I have used this code in a page inside a Script Editor Web part. Once you paste your code inside a snipped, next click on Insert and save the page.

add google analytics to sharepoint
add google analytics to sharepoint

Step 9: Next refresh the page and wait for sometimes to see the report in Analytics report section. To see the report you have to go to the report section and click on Overview. It’s showing 1 as I am the only one user currently present in the site.

how to add google analytics to sharepoint online
how to add google analytics to sharepoint online

Step 10: If you click on Location then you can also see the exact location where the user has visited your SharePoint site.

google analytics sharepoint online
google analytics sharepoint online

Step 11: In the content section, we can also see the page where the user has visited. As I have posted this code in a single page so I can able to see the only one page. Suppose you have posted this code inside a master page so you can able to see all pages where the user has visited.

google analytics for sharepoint 2013 on premise
google analytics for sharepoint 2013 on premise

Step 12: In Audience section we can also see the page viewer and user details as well.

how to enable google analytics in sharepoint online
how to enable google analytics in sharepoint online

You may like following SharePoint tutorials:

This is all about on how to add and setup for Google Analytics in SharePoint Online or SharePoint 2013/2016 sites.

Check out Best Alternative to InfoPath -> Try Now

EnjoySharePoint YouTube Channel

About Rajkiran Swain

Rajkiran is currently working as a SharePoint Consultant in QATAR . Rajkiran having 6 + years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).

View all posts by Rajkiran Swain →