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.
Setup SharePoint Starter Kit from any platform
SharePoint Starter Kit allows you to test-drive modern SharePoint experiences on your own tenant, and now you can set it up from any platform.

That is totally 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 set up this solution for your Modern SharePoint sites? This subject has already been addressed in the post of Joao Ferreira.

What can I bring more to that?

  1. Upgrade his solution to use the latest version of SharePoint Framework
  2. Perform some enhancements
  3. Allow you to deploy the solution from any platform thanks to Office365-CLI. If you too, are a macOS user and working on several SharePoint solutions yourself, you want to have a way to provision Google Analytics, without having to use a VM or a Windows computer
  4. Create scripts to implement the solution easier

Google Analytics implementation

I wrote two scripts that will allow you to implement the solution easily.

Prerequisites

  1. Google Analytics Tracking ID: https://support.google.com/analytics/answer/1008080
  2. Tenant App Catalog or Site Collection App Catalog:
  3. If you choose to use PowerShell solution, you'll need to install the PnP PowerShell module
  4. If you choose to use any platform solution, you'll need Bash and Office365-CLI
[note]Note

The user account that will perform the following actions has to have sufficient permissions on the target sites collection and on the App Catalog.

PowerShell (Windows only)

  1. Download the PowerShell solution from the repository
  1. Unzip the package
  2. From your PowerShell terminal, connect to your target site collection with Connect-PnPOnline cmdlet
    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/target-site
    
  3. Launch the setup.ps1
    .\setup.ps1 -siteUrl https://contoso.sharepoint.com/sites/target-site -trackingID 'UA-000000000-1'
    
[note]Note

If you can't execute the PowerShell script, cause of security reason, before unzip the package, execute the Unblock-File cmdlet.
[note]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, Mac OS, Windows)

  1. Download any platform solution from the repository
  1. Unzip the package
  2. Allow setup.sh script execution
    chmod +x ./setup.sh
    
  3. From your Bash terminal, connect to your target site collection with spo login cmdlet
    spo login https://contoso.sharepoint.com/sites/target-site
    
  4. Launch the setup.sh
    ./setup.sh --siteUrl https://contoso.sharepoint.com/sites/target-site --    trackingID 'UA-000000000-1'
    
[note]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?


You will find below some additional information about the Google Analytics interface and its configuration (thank you Karen for your suggestion 😉)

Ultimate Beginner’s Guide to Google Analytics 4 (NEW 2020 Interface)
If you’ve ever taken a quick peek at Google Analytics, you were probably thinking to yourself, “What is going on here? Where do I even begin?”

Enjoy 💪🏻



Hoping this post will help you 😉

You may also be interested in