*This page
applies to **Apigee** and **Apigee hybrid**.*


*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*
![](https://fonts.gstatic.com/s/i/googlematerialicons/help/v13/gm_grey-24dp/1x/gm_help_gm_grey_24dp.png)

<br />

Configure Google analytics or your own custom analytics tracking, as described
in the following sections.

## Configuring 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. In the Apigee in Cloud console, go to the **Distribution \> Portals** page.

   [Go to Portals](https://console.cloud.google.com/apigee/portals)
2. Click your portal.

3. Click **Settings** in the navigation menu.

4. Click the **Custom Scripts** tab.

5. Under **Google Analytics**, enter your Google Analytics tracking ID.

6. Click **Save**.

## Configuring 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 [Adding custom scripts](https://docs.cloud.google.com/apigee/docs/api-platform/publish/portal/custom-scripts.md.txt).

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 Views](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 Measurement](https://developers.google.com/analytics/devguides/collection/analyticsjs/events) |