Set up Google Analytics with Google Tag Manager

You can use Google Tag Manager and Google Analytics to enable traffic or page view analysis of Sitecore Content Hub data.

To set up Google Analytics with Google Tag Manager:

  1. Create an account for Google Analytics. You need one Google Analytics account per Content Hub instance.

  2. Set up and install Google Tag Manager.

  3. In Content Hub, set up and activate the Google Tag Manager.

  4. In the Google Tag Manager, in the upper-left corner, click the account name (for example, and then click the Google Analytics tab.

    account name
  5. On the Google Analytics page, click Get started and follow the prompts.

    google analysis page
  6. In each Google Analytics account, enable GA4 to get a measurement ID.

  7. To use the measurement ID and receive traffic into Google Analytics, configure Google Tag Manager by adding a new tag to its settings and use the GA4 configuration option.

  8. Copy the measurement ID from step 6 to the new tag. This tag should be triggered on all page views to get the traffic.

  9. Set Google Tag Manager to a version and publish.


To test your connection, look at the network tab in your browser where Content Hub is open. If you see traffic with collect.js, this means your traffic is being pushed to Google Analytics.


To send information about custom actions and events to Google Tag Manager, use window.dataLayer.push:


export default function createExternal (container) {
    let eventHandler = null;

    const removeListener = () => {
        if (eventHandler) {
            window.removeEventListener(EVENT_NAME, eventHandler);
            eventHandler = null;

    return {
        render: context => {

            eventHandler = event => {
                    event: "demoGTM",
                    entityId: context.options.entityId,
                    definitionName: event.detail.definitionName,
                    description: 'This is sample code using window.dataLayer.push'

            window.addEventListener(EVENT_NAME, eventHandler);
        unmount: () => {

See the data layer for information about using window.dataLayer.push().

Do you have some feedback for us?

If you have suggestions for improving this article,