Getting started - Google Tag Manager configuration

How to configure and use the Site Analytics app for SharePoint Online by Accelerator 365

The Site Analytics app from Accelerator 365 integrates your SharePoint sites with Google Analytics to provide real-time insights for engagement across your intranet.

Site Analytics supports configuration for both Google Analytics 4 and Google Tag Manager.

Note: This guide is for the configuration of Google Tag Manager. For Google Analytics 4 instructions, visit Getting started - Google Analytics 4 configuration.

Jump to


Google Tag Manager configuration

Note: Creating a Google GA4 property and a Tag Manager account is a prerequisite to the following steps.

Variables

Create custom data layer variables to pass data collected by the Site Analytics extension to your Google Analytics 4 property.

  1. Log into your Google Tag Manager account and go to the Variables section on the left pane.
  2. Click the New button on the top-right corner of the User-Defined Variables to create a variable.
  3. To make future work with variables more convenient, it is recommended to rename the variable on the top left of the panel to Site Name.
  4. Click on the Variable Configuration block in the middle and select Data Layer Variable found underneath the Page Variables section.
  5. The Data Layer Variable Name should be site_name.
  6. The rest of the configuration options can be left unchanged.  Press Save to apply changes.

  7. Create the following User-Defined Variables:

    Title Type Data Layer Variable Name
    Site Name Data Layer Variable site_name
    Site URL Data Layer Variable site_url
    Hub Site Name Data Layer Variable hub_site_name
    Hub Site URL Data Layer Variable hub_site_url
    User ID Data Layer Variable user_id

Triggers

  1. Navigate to the Triggers section on the left pane and click the New button on the top-right corner.
  2. Change the trigger name in the top left to User Properties Loaded. Click on the Trigger Configuration panel in the middle and pick the trigger’s type - Custom Event.
  3. Type acc_set_user_props in the Event name field. This is the name of the custom event this tag will trigger. Press Save to apply changes.

  4. Add another trigger titled Page Meta Loaded with acc_set_page_meta as the event name. This custom event will be triggered when the Site Analytics application customizer re-loads information about the page after navigation. Press Save to apply changes.

Tags

  1. Navigate to the Tags section on the left pane and click the New button on the top-right corner to add a tag that will send data to Site Analytics.
  2. Give this tag a name, e.g., GA Configuration - <your GTM property name>. Click on the Tag Configuration section and choose Google Analytics: GA4 Event type.
  3. You will then be prompted to create a Google Tag. Press the Create tag button and click Save to apply changes.

    GTM - GA Configuration
  4. Next, configure this tag to pass custom variables to the GA4 property. Expand the User Properties section and click Add Row to register a new parameter.


    A Property Name is the name of the custom dimension in the Google Analytics 4 property (user_id is the default value). Values will be taken from the data layer variables created earlier.

    To select a variable click the button on the right of the
    Value field and pick User ID.

    Note: If you wish to track custom user profile properties from SharePoint or Entra ID, they should also be added here.

  5. Click inside the Triggering section to pick a trigger. Select the User Properties Loaded custom event. Press Save to apply all changes.

    GTM - GA Configuration 2
  6. Add another tag titled GA - Custom Page View. The Tag Type should be Google Analytics: GA4 Event. This tag will send information about the page a user has navigated to.
  7. Again, set the same Configuration Tag as previously created.
  8. Set the Event Name as page_view.
  9. Expand the Event Parameters section and create the following parameters:
    Parameter Name Value
    site_name {{Site Name}}
    site_url {{Site URL}}
    hub_site_name {{Hub Site Name}}
    hub_site_url {{Hub Site URL}}
  10. Click inside the Triggering section to pick a trigger. Select Page Meta Loaded and press Save to apply all changes.

  11. It is recommended to test the changes before in Preview mode.

    First, follow the instructions to connect Site Analytics to a GTM container, then click Preview in GTM.
  12. Once you have previewed your container and events are being registered in GA4, you can proceed to publishing your container.

    Click on the Submit button on the top right to publish the container.

SharePoint configuration

Note: only a user with the SharePoint Administrator role can set up this type of alert due to properties that need to be set in SharePoint.

  1. Navigate to a site where the Site Analytics app has been added.
  2. Click the Settings icon on the SharePoint suite bar and navigate to Site contents.
  3. In Site contents, a configuration panel for the Site Analytics extension will appear at the foot of the page. Click on Configure button
  4. A property pane will appear, allowing you to connect the Site Analytics app to your GTM property.

    You will need to insert a JSON string in the pre-defined format below, replacing the bold item with the GTM container.

    JSON format
    [
      {
        "provider": "google",
        "type": "GTM",
        "configuration": {
          "default": {
            "trackingId": "[insert Google Tag Manager Container ID]"
          }
        }
      }
    ]
  5. Your JSON will be validated to ensure it is correctly formatted. Click on the Save button to apply the SharePoint properties for Site Analytics.

Other SharePoint configuration options

Note: the following configurations are optional. 


Using the Overrides feature for multiple GTM containers

Replace the bold items in the JSON below for different GTM containers to be configured for different SharePoint sites using the overrides feature.


JSON format

[
{
  "provider": "google",
  "type": "GTM",
  "configuration": {
    "default": {
      "trackingId": "[insert Google Tag Manager Container ID]"
    },
    "overrides": [
      {
        "sites": ["/sites/sitename1", "/sites/sitename2"],
        "trackingId": "[insert Google Tag Manager Container ID]"
      }
    ]
  }
}
] 


Disabling the User-ID feature

Google Tag Manager allows you to associate a persistent ID for a single user across multiple sessions or devices meaning a more accurate recording in Tag Manager of unique users.  

Note: the actual user identity is deliberately encoded so it is not possible to track individually named users within Google Tag Manager.

If you do not wish to use the User-ID feature it is necessary to update both the GTM container and configuration in the Site Analytics app.

  1. Log into your Google Tag Manager account and go to Triggers section on the left pane.
  2. Select the User Properties Loaded trigger and delete.
  3.  Replace the bold items in the JSON below to connect the Site Analytics app to a Google Tag Manager container. Data will be sent to this property from wherever the Site Analytics app is enabled, however, the User-ID data will not be sent.

JSON format

[
    {
        "provider": "google",
        "type": "GTM",
        "configuration": {
            "default": {
                "trackingId": "[insert Google Tag Manager Container ID]",
                "enable_user_id": false
            }
        }
    }
]