---
schema_version: "1"
id: 9e874bca20becae7b26e8e0bda4e2e59b95112702f48d12952cc42ad29ca8ce7
title: Configuring User Analytics
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/api-experience-hub/configuring-user-analytics.md
canonical_url: https://docs.mulesoft.com/api-experience-hub/configuring-user-analytics
source_site: docs.mulesoft.com
content_type: documentation
content_hash: b1498076039c16a2fddca2728b6288d78d337f52769bb8d72c8e04bc9fc52073
description: MuleSoft Documentation Site
latest: true
---
---
product: API Experience Hub
---

# Configuring User Analytics

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Use Google Analytics to gain valuable insights into how consumers are using your services and
portal, identify areas for improvement, make data-driven decisions to optimize the user experience,
and drive business success.

Google Analytics tracks the following data:

- API usage metrics:

  - API instance access requests

  - API specification downloads

  - Most viewed API

  - Total number of calls made to an API

- User engagement metrics:

  - Active users

  - Login events

- API Console usage:

  - API requests

    Measure the overall API usage and identify patterns in API consumption. Captures each time an
    API request is made through the API Console and the total number of API requests made.

  - API usage by endpoint

    Identifies popular endpoints and monitors usage trends to optimize API design and resource
    allocation. Captures each time an API request is made to a specific endpoint through the API
    console and the number of requests made to each API endpoint.

## Configure Google Analytics

To configure Google Analytics to send events from the portal:

1.  Set up a Google Analytics property using the instructions in the
    [Set up the Analytics Google tag](https://support.google.com/analytics/answer/1008080?hl=en&visit_id=638531259961972871-3450454930&rd=1#zippy=%2Cin-this-article)
    topic in the Google documentation.

2.  Navigate to the Builder.

3.  Click **Settings** > **Security & Privacy**.

4.  In the **Content Security Policy (CSP)** section, click **Relaxed CSP: Permit Access to Inline
    Scripts and Allowed Hosts**.

5.  From **Settings**, click **Advanced**.

6.  In the **Advanced** page, enter your Google Analytics Tracking ID.

7.  Click **Let Google Analytics access your Salesforce data for deeper insights into search
    activity**.

8.  Click **Edit Head Markup**.

9.  Add the following code and replace all instances of `G-TRACK_ID` with your Google Analytics
    Tracking ID:

    <script async src="https://www.googletagmanager.com/gtag/js?id=G-TRACK\_ID"></script>
    <script>
      window.dataLayer = window.dataLayer || \[\];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'G-TRACK\_ID');
      document.addEventListener('analyticsCustomEvent', function(e) {
          let detail = JSON.parse(JSON.stringify(e.detail));
          gtag('event', detail.eventName, detail.dimensions);
      });
    </script>

10. From **Setup**, click **Security & Privacy**.

11. Confirm that the following URLs show in the **Trusted Sites for Scripts** section:

    - `https://www.google-analytics.com`

    - `https://www.googletagmanager.com`

12. If the URLs are missing, add them by clicking **Add Trusted Site**.

13. From **Setup**, click **Security** > **Trusted URLs**.

14. Confirm that the same two URLs are in the list of the **Trusted URLs** section.

    API Experience Hub can now start sending Google Analytics from the portal.
