How to add Google tag manager globally to SharePoint Online

A solution to add google tag manager has being requested a few times to me since I released the solutions to add Google Analytics to SharePoint.

In this article you will find a pre-built solution to add Google tag manager to modern SharePoint Online using an Application Customizer.

What is Google Tag Manager?

Google Tag Manager is a tag management system created by Google to manage JavaScript and HTML tags used for tracking and analytics on websites.

How to Setup Google Tag Manager

First things first, before we get into the SharePoint bits let’s set up google tag manager and get everything you need.

  1. Sign in to your Tag Manager account
  2. Create a Workspace for your SharePoint site
  3. From the top bar copy the Tracking ID as shown in the picture below

How to add Google Tag Manager to modern SharePoint

To get the solution provided in this article globally deployed follow the steps below:

  1. Download and Extract the solution from here
  2. Open your tenant app catalog
  3. Click on Apps for SharePoint
  4. Upload the solution to the catalog
  5. Check the option Make this solution available to all sites in the organization
  6. Go to Site Contents
  7. Open the list Tenant Wide Extensions
  8. Edit the Gtagmanager item
  9. Modify the Component Properties and replace the trackingID value by your Google Tag Manager tracking ID.
  10. Save the item and all your modern SharePoint sites on Office 365 will get Google Tag Manager. If this was the first solution globally deployed on your tenant, it may take up to 20 minutes get available.

As always the source code of this solution is available on GitHub

Download Google Tag Manager
Explore Solution on GitHub

Venda vetor criado por freepik – br.freepik.com


2 Responses to “How to add Google tag manager globally to SharePoint Online”

  1. Jon

    February 11, 2020

    This will record all sites? What about individual site only? For me I’m only looking for metrics on 1 site only

    Reply
    • João Ferreira

      February 12, 2020

      Hi Jon,

      You can install it in a single site collection or in a single sub site following these steps.
      Download it and deploy the solution to the global app catalog, when you reach steps number 5 Uncheck the option Make this solution available to all sites in the organization

      Open PowerShell and execute the following commands, PnP PowerShell needs to be installed in your machine

      1 – Connect to the site where you want to add the tag manager, change the URL to your own
      Connect-PnPOnline -UseWebLogin -Url https://contoso.sharepoint.com/

      2 – Apply the extension to the site

      Add-PnPCustomAction -ClientSideComponentId “8b00fe9b-cce0-4a46-b74b-0263532d8f94” -Name “GTAGManager” -Title “GTAGManager” -Location ClientSideExtension.ApplicationCustomizer -ClientSideComponentProperties: ‘{“trackingID”:”GTM-*******”}’ -Scope site

      Change the tracking id to your own value.

      If you want to apply it to a subsite only do the following:

      1 – Connect to the sub site using powershell
      2 – On the scope parameter use web instead of site

      To check if the extension was applied to the site you can use this command
      Get-PnPCustomAction -scope site

      Change the scope to the value you have used to install the app.

      Hope this helps, have a nice day 🙂

      Reply

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: