> For the complete documentation index, see [llms.txt](https://rudderlabs.gitbook.io/rudderlabs-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rudderlabs.gitbook.io/rudderlabs-1/docs/destinations/analytics/google-analytics-4/setting-up-google-analytics-4-in-rudderstack.md).

# Setting up Google Analytics 4

Step-by-step guide on setting up Google Analytics 4 as a destination in RudderStack.

Before configuring Google Analytics 4 as a destination in RudderStack, verify if the source platform is supported by Google Analytics 4 by referring to the table below:

| **Connection Mode** | **Web**       | **Mobile**    | **Server**    |
| ------------------- | ------------- | ------------- | ------------- |
| **Device Mode**     | **Supported** | **-**         | **-**         |
| **Cloud Mode**      | **Supported** | **Supported** | **Supported** |

To know more about the difference between cloud mode and device mode in RudderStack, read the [RudderStack Connection Modes](https://rudderstack.com/docs/rudderstack-cloud/rudderstack-connection-modes/) guide.

Once you have confirmed that the source platform supports sending events to Google Analytics 4, follow these steps:

1. From your [RudderStack dashboard](https://app.rudderstack.com/), add the source. Then, from the list of destinations, select **Google Analytics 4**.
2. Assign a name to your destination and click on Next.

## Connection settings

To successfully configure Google Analytics 4 as a destination, configure the following settings:

![Google Analytics 4 Connection Settings in RudderStack](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-3cc0d562bb3b8165cce5c328a7060d569308e669%2Fgoogle-analytics-4-connection-settings.png?alt=media)

* **API Secret**: This field is required only for the cloud mode setup where you can enter the API Secret generated through the Google Analytics dashboard. It can be created in the Google Analytics dashboard under **Admin > Data Streams > Choose your stream > Measurement Protocol > Create**.
* **Client Type**: Select the client type as `gtag` or `Firebase` from the dropdown:
  * **`gtag`** - Supported for the cloud and device mode both. If you select `gtag`, enter the below:
    * **Measurement Id**: Enter the Measurement Id which is the identifier for a data stream. It can be found in the Google Analytics dashboard under **Admin > Data Streams > Choose your stream > Measurement ID**.
  * **`Firebase`** - Supported only for the cloud mode. If you select `Firebase`, enter the below:
    * **Firebase App Id**: Enter the Firebase App ID which is the identifier for Firebase app. It can be found in the Firebase dashboard under **Project Settings > General**.

Refer to the [FAQ](#faq) section for more information on how to obtain the API Secret, Measurement Id and Firebase App ID.

### Native SDK

All the settings mentioned below are applicable only for the device mode.

* **Block a Page View Event**: Enable this setting to disable sending `page_view` events on load. However, you can explicitly send a `page_view` event by calling the `page()` API.
* **Extend Page View Property**: Enable this setting to send the following properties along with any other custom property to the `page` call of the RudderStack SDK:
  * `url`
  * `search`

Google Analytics 4 has a limit on the number of unique properties per event name. The default `page_view` event supports the properties mentioned in the [Automatically collected events in Google Analytics 4](https://support.google.com/analytics/answer/9234069?hl=en\&ref_topic=6317484) guide.

* **Send userId to GA**: This setting exhibits the following behavior:
  * If enabled, the user ID is set to the identified visitors and sent as explained in the [Cookies and user identification](https://developers.google.com/tag-platform/devguides/cookies#set_user_id) guide.
  * If disabled, `userId` is not sent and Rudderstack only sends the user traits set as `user_properties` to Google Analytics. The user properties are set on the `gtag` client as explained in the [Set user properties](https://developers.google.com/analytics/devguides/collection/ga4/user-properties?technology=websites) guide.

### Client-side events filtering

![Google Analytics 4 Connection Settings in RudderStack](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-71cb4e1b6eca9f6e6c3b4616c9e5a80bfdd2a7d8%2Fgoogle-analytics-4-connection-settings2.png?alt=media)

This option is applicable only if you're sending events to Google Analytics 4 via the web device mode. Refer to the [Client-side Event Filtering](https://www.rudderstack.com/docs/stream-sources/rudderstack-sdk-integration-guides/event-filtering/) guide for more information on this feature.

### Web SDK settings

![Google Analytics 4 Connection Settings in RudderStack](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-37aaf4349d0889f8c3969d4ee48641dc794fa34e%2Fgoogle-analytics-4-connection-settings3.png?alt=media)

**Use device mode to send events**: Enable this setting to send events via the [RudderStack device mode](https://www.rudderstack.com/docs/rudderstack-cloud/rudderstack-connection-modes/#device-mode).

Finally, click on **Next** to enable Google Analytics 4 as a destination in Rudderstack.

## FAQ

### How do I obtain the Measurement Id?

1. Login to [Google Analytics](https://analytics.google.com/analytics/web/) dashboard.
2. Go to the **Admin** section in the left sidebar.
3. Select the relevant account and property.
4. Click on **Data Streams** and select the stream to get the Measurement Id as shown:

![](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-a6510128e4d4f7bbb5f0a8d13e5d6d47258693db%2Fmeasurement-id.png?alt=media)

### How do I obtain the API Secret?

1. Login to [Google Analytics](https://analytics.google.com/analytics/web/) dashboard.
2. Go to the **Admin** section in the left sidebar.
3. Select the relevant account and property.
4. Click on **Data Streams** and select the stream.
5. Click on **Measurement Protocol API secrets** to get the API Secret as shown:

![](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-4c16f1a5bbf1c361962e01ef7f8546ec4dfddc2e%2Fapi-secret.png?alt=media)

### How do I obtain the Firebase App ID?

1. Login to [Google Analytics](https://analytics.google.com/analytics/web/) dashboard.
2. Go to the **Admin** section in the left sidebar.
3. Select the relevant account and property.
4. Click on **Data Streams** and select the stream to get the **Firebase App Id** as shown: ![](https://876606571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lq5Ea6fHVg3dSxMCgyQ%2Fuploads%2Fgit-blob-4f2f444198d2de4a6a70fec0c9d1eb2f352ecbdf%2Ffirebase-app-id.png?alt=media)

## Contact us

For queries on any of the sections covered in this guide, you can [contact us](mailto:%20docs@rudderstack.com) or start a conversation in our [Slack](https://rudderstack.com/join-rudderstack-slack-community) community.
