Google Analytics is a web analytics service offered by Google that tracks and reports website traffic. SharePoint provides some reports too, but these ones can be quickly insufficient if you need more KPI.
Previously, on the classic experience of SharePoint, it was possible to add Google Analytics script by:
- Creating a Master Page and including the script (it was not a Best Practice by the way 🤭)
- Creating a Custom Action 👍🏻
Fast forward to today, modern SharePoint experiences support the most common scenarios that organizations use SharePoint for. Many organizations have already switched to using modern experiences, and many more are evaluating how they would benefit of modernizing their intranets.
That is totaly true! How to visualize in real time or through a complete dashboard several native and custom KPI?
In addition, you can access several features for FREE 💸.
Google Analytics for Modern SharePoint - for everybody
So, now... How to setup this solution to your Modern SharePoint sites? This subject has already been addressed in the post of Joao Ferreira.
What can I bring more to that?
- Upgrade his solution to use the latest version of SharePoint Framework
- Allow you to deploy the solution from any platform thanks to Office365-CLI. Being a macOS user and working on several SharePoint solutions myself, I wanted to have a way to provision Google Analytics, without having to use a VM or a Windows computer.
- Create scripts to implement the solution easier
Google Analytics implementation
I wrote two scripts that will allow you to implement the solution easily.
- Google Analytics Tracking ID: https://support.google.com/analytics/answer/1008080
- Tenant App Catalog or Site Collection App Catalog:
- Configure your Tenant App Catalog: https://docs.microsoft.com/en-us/sharepoint/use-app-catalog
- Configure your Site Collection App Catalog: https://docs.microsoft.com/en-us/sharepoint/dev/general-development/site-collection-app-catalog
- If you choose to use PowerShell solution, you'll need to install the PnP PowerShell module
- If you choose to use the any platform solution, you'll need Bash and Office365-CLI
PowerShell (Windows only)
- Download the PowerShell solution from the repository
- Unzip the package
- From your PowerShell terminal, connect to your target site collection with
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/target-site
- Launch the
.\setup.ps1 -siteUrl https://contoso.sharepoint.com/sites/target-site -trackingID 'UA-000000000-1'
If you can't execute the PowerShell script, cause of security reason, before unzip the package, execute the
Note: in this example, the package is deploy to the Site Collection App Catalog. You have other options like illustrated into the README.md, that allow you to manage the deployment.
Any platform (Linux, MacOS, Windows)
- Download the any platform solution from the repository
- Unzip the package
chmod +x ./setup.sh
- From your Bash terminal, connect to your target site collection with
spo connect https://contoso.sharepoint.com/sites/target-site
- Launch the
./setup.sh --siteUrl https://contoso.sharepoint.com/sites/target-site --trackingID 'UA-000000000-1'
Note: in this example, the package is deploy to the Site Collection App Catalog. You have other options like illustrated into the README.md, that allow you to manage the deployment
Pretty simple, isn't it ?
Hoping this post will help you 😉