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.
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
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.
Step 3: Next choose the Industry category and Reporting time zone. In Data Sharing Settings you can select all option as per below screenshot.
Step 4: Next click on Get Tracking Id to generate the ID which you have to configure in your application.
Step 5: Next click on all check box as per below screen shot and Click on I Accept to generate the code.
Step 6: Next it will generate a JavaScript code which you can simply copy and paste it in your SharePoint application.
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.
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.
Step 10: If you click on Location then you can also see the exact location where the user has visited your SharePoint site.
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.
Step 12: In Audience section we can also see the page viewer and user details as well.
You may like following SharePoint tutorials:
- Display SharePoint list data in jQuery data table using Rest API
- How to disable/enable alert for a list or library in SharePoint 2019/2016/2013
- How to Set Permissions in SharePoint Online/2013/2016 Site
- Add heading in the default newForm.aspx in SharePoint list using JavaScript and CSS
- Create an organization chart from a list in SharePoint Online/2013/2016 using JavaScript
- Create Highcharts in SharePoint using Rest API
- Embed PowerPoint Slide in SharePoint Online/2013/2016/2019
- Embed Yammer group feed in SharePoint Online/2013/2016
- Create a Survey in SharePoint Online or SharePoint 2013/2016/2019
- HTTP Error 400 The size of the request headers is too long. SharePoint Online Office 365
- Retrieve and Display TASK status using REST API in SharePoint
This is all about on how to add and setup for Google Analytics in SharePoint Online or SharePoint 2013/2016 sites.
Rajkiran is currently working as a SharePoint Consultant in India . Rajkiran having 7+ 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).