---
title: "Set up Google Analytics with Google Tag Manager"
slug: "set-up-google-analytics-with-google-tag-manager"
abstract: "How to set up Google Analytics for use with Google Tag Manager and Content Hub."
---
# 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](https://support.google.com/analytics/answer/1008015?hl=en). You need one Google Analytics account per Content Hub instance.
2. [Set up and install Google Tag Manager](https://support.google.com/tagmanager/answer/6103696).
3. In Content Hub, set up and [activate the Google Tag Manager](https://doc.sitecore.com/ch/en/users/content-hub/google-tag-manager.html "Google Tag Manager").
4. In the Google Tag Manager, in the upper-left corner, click the account name (for example, mycompany.com) and then click the Google Analytics tab.

    ![account name](https://doc.sitecore.com/api/markdown-image/ch/en/users/content-hub/images/account_name.png)

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

    ![google analysis page](https://doc.sitecore.com/api/markdown-image/ch/en/users/content-hub/images/google_analysis_page.png)

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](https://support.google.com/analytics/answer/9304153#stream&zippy=%2Cweb).
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.

> [!tip]
> 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.

## Example

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

```javascript
const EVENT_NAME = "ENTITY_SAVED";
export default function createExternal (container) {
    let eventHandler = null;

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

    return {
        render: context => {
            removeListener();

            eventHandler = event => {
                window.dataLayer.push({
                    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: () => {
            removeListener();
        }
    };
};

```

> [!note]
> See the [data layer](https://developers.google.com/tag-platform/tag-manager/web/datalayer) for information about using **window.dataLayer.push()**.