Google Analytics 4, commonly referred to as GA4, is the latest iteration of Google's web analytics platform, designed to provide deeper insights into user behavior across websites and apps. It offers a more holistic approach to analytics by integrating data from various touchpoints, including websites, mobile apps, and other digital platforms. GA4 focuses on user-centric measurement, emphasizing the importance of understanding individual user journeys and interactions.
Product Type: Analytics
Integration Type: Starter Kit & ID Sync
Event Source Type: Web, Mobile Browser, & Mobile App
Event Scope: Full-Funnel Events
- GA4 - Measurement (Recommended): Uses the Measurement Protocol for server-side tracking with structured JSON data
- GA4 - Collect: Uses the Collect endpoint, mimicking browser-based gtag.js behavior
For more information about Google Analytics 4 - Collect, please see here.
| Aspect | GA4 Measurement (Recommended) | GA4 Collect |
|---|
| Endpoint | https://www.google-analytics.com/mp/collect | https://google-analytics.com/g/collect |
| Method | POST | GET |
| Data Format | JSON payload (structured) | URL parameters (flat) |
| Authentication | API_SECRET + MEASUREMENT_ID | MEASUREMENT_ID only |
| Product Data | Structured items array | Encoded strings (pr1, pr2, etc.) |
| Consent Support | Full (ad_user_data, ad_personalization) | Limited |
| Device Object | Full device information | Not available |
| Geolocation | ip_override, user_location (Oct 2024) | Native (_uip) |
| Batch Processing | Events array | Individual events |
| Use Case | Server-side tracking, batch processing | Browser-like behavior, simple setup |
| Release Status | Mature (2022), actively enhanced | Newer (2024) |
Choose GA4 Measurement (Recommended) for: Server-side integrations, structured e-commerce data, consent management, batch event processing, mobile apps
Choose GA4 Collect for: Simple setup without API secrets, debugging (URL-visible parameters), scenarios requiring browser-like behavior simulation
- Structured server-side event tracking via the GA4 Measurement Protocol with full JSON payload support.
- Full consent parameter support (
ad_user_data, ad_personalization) for compliance with Google's consent requirements.
- Batch event processing for efficient delivery of multiple events per request.
- Enhanced geographic and demographic data accuracy via
ip_override and user_location parameters (October 2024).
- Session-level attribution linking for
gclid and dclid via the Google Gtag sync.
- GA4 Measurement vs Collect - GA4 Measurement is the recommended server-side integration — structured JSON payload, full consent parameter support (
ad_user_data, ad_personalization), batch processing, and device/geolocation objects. GA4 Collect mimics browser-based gtag.js behavior with simpler setup (no API secret required) but limited feature support. For most server-side implementations, use Measurement.
- October 2024 — Geographic and Demographic Parameters - GA4 Measurement Protocol added support for optional
user_location and IP address parameters in October 2024, improving demographic and geographic data accuracy. See the Measurement Protocol Geo Info Reference. These parameters do not replace the need for the Google Gtag sync for core identifiers (client_id, session_id, session_number).
- gclid and dclid — Session-Level Attribution -
gclid and dclid are no longer mapped at the event level. These identifiers are handled via session-level linking through the Google Gtag sync. Ensure the sync is configured and deployed for attribution to function correctly.
- Google Gtag Sync Required - The Google Gtag sync is required for collecting
client_id, session_id, and session_number, as well as session-level linking for gclid and dclid attribution. The addition of user_location and IP parameters does not eliminate this requirement.
- API Secret Security - Keep your
API_SECRET private to your organization. If you deploy the Measurement Protocol client-side, rotate api_secrets regularly to avoid excessive spam ingestion into your GA4 property.
Enable Google Ads auto-tagging for Google Ads reporting.
Auto-tagging automatically imports Google Ads data into Analytics. Combining Google Ads data with the rich post-click information provided by Analytics allows you to see what happened on your site after people clicked on your ads. When you enable auto-tagging, a parameter called gclid is added to your landing page URL when a user clicks over to your site from an ad.
- Log in to your Google Analytics account.
- Navigate to the Admin section.
- In the "Property settings" column, expand "Data collection and modification", click on "Data Streams."
- Here, you'll find a list of data streams associated with the property.
- Click on the data stream for which you want to find the measurement ID.
- The measurement ID is displayed at the top of the page (e.g.,
G-XXXXX00000).
- Go to Google Analytics and sign in with your Google account.
- Select the GA4 property for which you want to create the API secret.
- In the bottom-left corner, click on the "Admin" gear icon to open the Admin settings.
- Under the Property column, click on "Data Streams".
- Choose the data stream (Web, iOS, or Android) for which you want to generate the API secret.
- In the Data Stream details, scroll down and find the "Measurement Protocol API secrets" section.
- Click on the "Create" button to generate a new API secret.
- Provide a nickname for your API secret (e.g., "My API Secret").
- Click "Create" to generate the secret.
- The API secret will be displayed. Copy this secret and store it securely.
Security Note: Keep these credentials private to your organization. If you deploy the measurement protocol client-side, you should regularly rotate api_secrets to avoid excessive SPAM.
To gather the client_id, session ID, and session count, you must configure a Google Gtag sync. The sync also handles session-level linking for gclid and dclid attribution.
Both architectures use the same Google Gtag sync configuration and produce identical results. The sync configuration, parameters, and behavior described in the Google Tag Overview apply to both architectures.
Important: The Google Gtag sync is required for collecting client_id, session_id, and session_number, as well as session-level linking for gclid and dclid attribution.
From the integration library, add a Google Analytics 4 integration. Then, fill out the Connection Parameters:
| Connection Parameter | Description |
|---|
API_SECRET | Each data stream has a unique API Secret for sending data via GA4 Measurement Protocol. |
MEASUREMENT_ID | The GA4 measurement ID is a unique identifier assigned to each Google Analytics 4 property, allowing data to be collected and associated with that specific property. |
API_ENDPOINT | The GA4 Measurement Protocol endpoint. Default: https://www.google-analytics.com/mp/collect |
Once you've adjusted the starter kit:
- Go to Pipelines > Select your Pipeline
- Click the Right drop-down > Add Integration
- Select your Google Analytics 4 integration and revision > Deploy
MetaRouter provides all of the event mappings that Google Analytics 4 integrations typically require. You may add custom events, parameters or mappings in accordance with Measurement Protocol's API documentation.
| Output Key | Description | Expected Input |
|---|
event.params.data_source | String: Data source of the event | Enrichment - S2S |
event.params.engagement_time_msec | Integer: Engagement time in milliseconds | Enrichment - 1 |
consent.ad_user_data | String: User data consent | Enrichment - GRANTED |
consent.ad_personalization | String: Personalization consent | Enrichment - GRANTED |
user_agent | String: User agent string | context.userAgent |
device | Object: Device information (mobile only) | Expression - Built from context.device, context.os, and context.screen when context.device.type is present |
user_id | String: User ID | userId |
client_id Required | String: Client ID | Expression - Extracted from GA cookie (_ga), falls back to anonymousId |
timestamp_micros Required | Integer: Timestamp in microseconds | Expression - RFC3339 timestamp converted to microseconds |
event.params.session_id | Integer: Session ID | context.providers.googleGtag.data.sessionID |
event.params.session_number | Integer: Session number | context.providers.googleGtag.data.sessionCount |
ip_override | String: User's IP address for enhanced geolocation accuracy | context.ip |
user_location.city | String: User's city | traits.address.city |
user_location.region_id | String: User's region in ISO format (e.g. US-CA) | Expression - Derived from traits.address.country and traits.address.state |
user_location.country_id | String: User's country code (ISO alpha-2) | Expression - First 2 characters of traits.address.country |
| Output Key | Description | Expected Input |
|---|
ip_override | String: User's IP address for enhanced geolocation accuracy | context.ip |
user_location.city | String: User's city | traits.address.city |
user_location.region_id | String: User's region in ISO format (e.g. US-CA) | Expression - Derived from traits.address.country and traits.address.state |
user_location.country_id | String: User's country code (ISO alpha-2) | Expression - First 2 characters of traits.address.country |
Note: These parameters are optional but recommended for improved geographic and demographic data accuracy in GA4 reporting.
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - page_view |
event.params.page_title | String: The title of the page | properties.title |
event.params.page_location | String: The full URL of the page | Expression - Page URL with query string stripped |
event.params.page_referrer | String: The URL of the previous page | Expression - Referrer URL with query string stripped |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - search |
event.params.search_term | String: Search term used | properties.query |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - view_item_list |
event.params.item_list_id | String: The ID of the item list | properties.list_id |
event.params.item_list_name | String: The name of the item list | properties.category |
event.params.items | Array: List of items viewed | Expression - Products array mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - view_promotion |
event.params.promotion_id | String: Promotion ID | properties.promotion_id |
event.params.promotion_name | String: Promotion name | properties.name |
event.params.creative_name | String: Creative name | properties.creative |
event.params.creative_slot | String: Creative slot | properties.position |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - select_promotion |
event.params.promotion_id | String: Promotion ID | properties.promotion_id |
event.params.promotion_name | String: Promotion name | properties.name |
event.params.creative_name | String: Creative name | properties.creative |
event.params.creative_slot | String: Creative slot | properties.position |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - select_item |
event.params.items | Array: Items clicked | Expression - Product mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - view_item |
event.params.currency | String: Currency | properties.currency |
event.params.value | Float: Total value | properties.value |
event.params.items | Array: Items viewed | Expression - Product mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - add_to_cart |
event.params.currency | String: Currency | properties.currency (default: USD) |
event.params.value | Float: Total value | Expression - Total value calculated via TOTAL_VALUE from product properties |
event.params.items | Array: Items added to cart | Expression - Product mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - remove_from_cart |
event.params.currency | String: Currency | properties.currency (default: USD) |
event.params.value | Float: Total value | Expression - Total value calculated via TOTAL_VALUE from product properties |
event.params.items | Array: Items removed from cart | Expression - Product mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - view_cart |
event.params.currency | String: Currency | properties.currency |
event.params.value | Float: Total value | Expression - Total value calculated via TOTAL_VALUE from products array |
event.params.items | Array: Items in cart | Expression - Products array mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - purchase |
event.params.coupon | String: Coupon code used for a purchase | properties.coupon |
event.params.currency | String: Currency of the purchase | properties.currency |
event.params.shipping | Float: Shipping cost | properties.shipping |
event.params.tax | Float: Tax amount | properties.tax |
event.params.transaction_id Required | String: Transaction ID | properties.order_id |
event.params.value | Float: Total value of the purchase | properties.total |
event.params.items | Array: The items in the purchase | Expression - Products array mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - begin_checkout |
event.params.currency | String: Currency | properties.currency |
event.params.value | Float: Total value | Expression - Total value calculated via TOTAL_VALUE from products array |
event.params.coupon | String: Coupon code | properties.coupon |
event.params.items | Array: Items in checkout | Expression - Products array mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - add_payment_info |
event.params.coupon | String: Coupon code | properties.coupon |
event.params.payment_type | String: Payment method | properties.payment_method |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - add_to_wishlist |
event.params.currency | String: Currency | properties.currency (default: USD) |
event.params.value | Float: Total value | Expression - Total value calculated via TOTAL_VALUE from product properties |
event.params.items | Array: Items added to wishlist | Expression - Product mapped to GA4 item schema |
| Output Key | Description | Expected Input |
|---|
event.name Required | String: The name of the event | Enrichment - refund |
event.params.coupon | String: Coupon code | properties.coupon |
event.params.currency | String: Currency | properties.currency |
event.params.shipping | Float: Shipping cost | properties.shipping |
event.params.tax | Float: Tax amount | properties.tax |
event.params.transaction_id Required | String: Transaction ID | properties.order_id |
event.params.value | Float: Total value | properties.total |
event.params.items | Array: Items refunded | Expression - Products array mapped to GA4 item schema |
These identifiers must be mapped to GA4 - Measurement Protocol in order for successful user matching to occur. Without these IDs, any events sent to GA4 may not be accurately reflected in reporting. For your convenience, required and recommended IDs are mapped as Global parameters to ensure they are added to every event.
| Attribute | Description | Example | Sync Injector Required? |
|---|
client_id Required | Google Analytics client ID | 35009a79-1a05-49d7-b876-2b884d0f825b | Yes |
user_id Recommended | Custom user identifier | user_12345 | No |
session_id Recommended | Session identifier | 1595262825000 | Yes |
session_number Recommended | Session count | 3 | Yes |
The following identifiers are handled via session-level linking through the Google Gtag sync, not as event-level mappings:
| Attribute | Description | Example |
|---|
gclid | Google Click Identifier | CjwKCAjwt-OwBhBnEiwAgwzrUkyN... |
dclid | Google Display Click Identifier | CKDdz-fE_IUDFYtTCQkdbyMOPg |
Measurement Protocol Guide
Send user provided data