You're viewing **Apigee Edge** documentation.  
[Go to the
**Apigee X** documentation](http://cloud.google.com/apigee/docs/api-platform/publish/portal/api-portal-analytics). info

> [!NOTE]
> **Note:** The integrated portal is available as an Apigee-managed solution for Apigee Edge for Public Cloud customers only. If you are an Apigee Edge for Private Cloud customer, refer to the customer-managed [Drupal portal solution](https://docs.apigee.com/api-platform/publish/drupal/open-source-drupal).

<br />

You can configure Google analytics or your own custom analytics tracking, as described in the following sections.

## Configure Google Analytics

Before you can configure Google Analytics, you'll need a Google Analytics account and access to the tracking code that will be added to your portal pages and used to track activity on your site. For more information, see
[Google Analytics help](https://support.google.com/analytics).

To configure Google Analytics:

1. Select **Publish \> Portals** and select your portal.
2. Select **Settings** in the drop-down menu in the top navigation bar.  
   Alternatively, you can click **Settings** on the portal landing page.
3. Click the **Custom Scripts** tab.
4. Under **Google Analytics**, enter your Google Analytics tracking ID.
5. Click **Save**.

## Configure custom analytics tracking

Configure your own custom analytics tracking solution by passing event details to your own custom function. Your custom function must be defined as part of the `portal.onAnalyticsEvent` in the global namespace (declared on the `window` variable).

For example, you might want to send the event details to an analytics service other than Google Analytics:

    <script>
    window.portal = {};
    window.portal.onAnalyticsEvent = (event) => {
      // log event to console
      console.log(event);
      // TODO: publish event to custom analytics service
    }
    </script>

Add your custom script to each page in your portal on the **Custom Scripts** tab of the Settings page. For more information, see [Add custom scripts](https://docs.apigee.com/api-platform/publish/portal/custom-scripts).

The portal generates the following types of events in the same format used by Google Analytics:

| Event type | Example format | More information |
|---|---|---|
| Page visits | { hitType: 'pageview', page: '/apis' }; | [Page tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/pages) |
| Clicks on **Execute** on the Try it panel in the API reference doc | { hitType: 'event', eventCategory: 'docsEvents', eventAction: 'apixExecute' } | [Event Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/events) |