Google Analytics 4 - Measurement

What Is Google Analytics 4 - Measurement?

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 Protocol vs Collect Endpoint

MetaRouter has two integrations for GA4:

  • 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.

AspectGA4 Measurement (Recommended)GA4 Collect
Endpointhttps://www.google-analytics.com/mp/collecthttps://google-analytics.com/g/collect
MethodPOSTGET
Data FormatJSON payload (structured)URL parameters (flat)
AuthenticationAPI_SECRET + MEASUREMENT_IDMEASUREMENT_ID only
Product DataStructured items arrayEncoded strings (pr1, pr2, etc.)
Consent SupportFull (ad_user_data, ad_personalization)Limited
Device ObjectFull device informationNot available
Geolocationip_override, user_location (Oct 2024)Native (_uip)
Batch ProcessingEvents arrayIndividual events
Use CaseServer-side tracking, batch processingBrowser-like behavior, simple setup
Release StatusMature (2022), actively enhancedNewer (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


Capabilities

  • 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.

Considerations

  • 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.

Getting Started - From Your GA4 Account

Enable Google Ads Auto-Tagging

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.

Obtain Your Measurement ID

  1. Log in to your Google Analytics account.
  2. Navigate to the Admin section.
  3. In the "Property settings" column, expand "Data collection and modification", click on "Data Streams."
  4. Here, you'll find a list of data streams associated with the property.
  5. Click on the data stream for which you want to find the measurement ID.
  6. The measurement ID is displayed at the top of the page (e.g., G-XXXXX00000).

Obtain Your API Secret

  1. Go to Google Analytics and sign in with your Google account.
  2. Select the GA4 property for which you want to create the API secret.
  3. In the bottom-left corner, click on the "Admin" gear icon to open the Admin settings.
  4. Under the Property column, click on "Data Streams".
  5. Choose the data stream (Web, iOS, or Android) for which you want to generate the API secret.
  6. In the Data Stream details, scroll down and find the "Measurement Protocol API secrets" section.
  7. Click on the "Create" button to generate a new API secret.
  8. Provide a nickname for your API secret (e.g., "My API Secret").
  9. Click "Create" to generate the secret.
  10. 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.


Adding a Google Analytics 4 Integration

Google Tag Sync (ID Sync Configuration)

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.

ArchitectureDescription
GA4 Sync - DecoupledGA4 as a separate sync under parent Google Tag Settings
Google Tag Sync - Coupled (Legacy)GA4 bundled with CM360/Google Ads in single Google Gtag sync

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.

Google Analytics 4 - Starter Kit

From the integration library, add a Google Analytics 4 integration. Then, fill out the Connection Parameters:

Connection ParameterDescription
API_SECRETEach data stream has a unique API Secret for sending data via GA4 Measurement Protocol.
MEASUREMENT_IDThe 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_ENDPOINTThe GA4 Measurement Protocol endpoint. Default: https://www.google-analytics.com/mp/collect

Add Integration to Pipeline

Once you've adjusted the starter kit:

  1. Go to Pipelines > Select your Pipeline
  2. Click the Right drop-down > Add Integration
  3. Select your Google Analytics 4 integration and revision > Deploy

Event Mappings

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.

Global Mappings

Output KeyDescriptionExpected Input
event.params.data_sourceString: Data source of the eventEnrichment - S2S
event.params.engagement_time_msecInteger: Engagement time in millisecondsEnrichment - 1
consent.ad_user_dataString: User data consentEnrichment - GRANTED
consent.ad_personalizationString: Personalization consentEnrichment - GRANTED
user_agentString: User agent stringcontext.userAgent
deviceObject: Device information (mobile only)Expression - Built from context.device, context.os, and context.screen when context.device.type is present
user_idString: User IDuserId
client_id RequiredString: Client IDExpression - Extracted from GA cookie (_ga), falls back to anonymousId
timestamp_micros RequiredInteger: Timestamp in microsecondsExpression - RFC3339 timestamp converted to microseconds
event.params.session_idInteger: Session IDcontext.providers.googleGtag.data.sessionID
event.params.session_numberInteger: Session numbercontext.providers.googleGtag.data.sessionCount
ip_overrideString: User's IP address for enhanced geolocation accuracycontext.ip
user_location.cityString: User's citytraits.address.city
user_location.region_idString: User's region in ISO format (e.g. US-CA)Expression - Derived from traits.address.country and traits.address.state
user_location.country_idString: User's country code (ISO alpha-2)Expression - First 2 characters of traits.address.country

Enhanced Geographic/Demographic Parameters (October 2024)

Output KeyDescriptionExpected Input
ip_overrideString: User's IP address for enhanced geolocation accuracycontext.ip
user_location.cityString: User's citytraits.address.city
user_location.region_idString: User's region in ISO format (e.g. US-CA)Expression - Derived from traits.address.country and traits.address.state
user_location.country_idString: 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.

Event Specific

Page

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - page_view
event.params.page_titleString: The title of the pageproperties.title
event.params.page_locationString: The full URL of the pageExpression - Page URL with query string stripped
event.params.page_referrerString: The URL of the previous pageExpression - Referrer URL with query string stripped

Products Searched

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - search
event.params.search_termString: Search term usedproperties.query

Product List Viewed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - view_item_list
event.params.item_list_idString: The ID of the item listproperties.list_id
event.params.item_list_nameString: The name of the item listproperties.category
event.params.itemsArray: List of items viewedExpression - Products array mapped to GA4 item schema

Promotion Viewed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - view_promotion
event.params.promotion_idString: Promotion IDproperties.promotion_id
event.params.promotion_nameString: Promotion nameproperties.name
event.params.creative_nameString: Creative nameproperties.creative
event.params.creative_slotString: Creative slotproperties.position

Promotion Clicked

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - select_promotion
event.params.promotion_idString: Promotion IDproperties.promotion_id
event.params.promotion_nameString: Promotion nameproperties.name
event.params.creative_nameString: Creative nameproperties.creative
event.params.creative_slotString: Creative slotproperties.position

Product Clicked

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - select_item
event.params.itemsArray: Items clickedExpression - Product mapped to GA4 item schema

Product Viewed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - view_item
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueproperties.value
event.params.itemsArray: Items viewedExpression - Product mapped to GA4 item schema

Product Added

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - add_to_cart
event.params.currencyString: Currencyproperties.currency (default: USD)
event.params.valueFloat: Total valueExpression - Total value calculated via TOTAL_VALUE from product properties
event.params.itemsArray: Items added to cartExpression - Product mapped to GA4 item schema

Product Removed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - remove_from_cart
event.params.currencyString: Currencyproperties.currency (default: USD)
event.params.valueFloat: Total valueExpression - Total value calculated via TOTAL_VALUE from product properties
event.params.itemsArray: Items removed from cartExpression - Product mapped to GA4 item schema

Cart Viewed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - view_cart
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueExpression - Total value calculated via TOTAL_VALUE from products array
event.params.itemsArray: Items in cartExpression - Products array mapped to GA4 item schema

Order Completed

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - purchase
event.params.couponString: Coupon code used for a purchaseproperties.coupon
event.params.currencyString: Currency of the purchaseproperties.currency
event.params.shippingFloat: Shipping costproperties.shipping
event.params.taxFloat: Tax amountproperties.tax
event.params.transaction_id RequiredString: Transaction IDproperties.order_id
event.params.valueFloat: Total value of the purchaseproperties.total
event.params.itemsArray: The items in the purchaseExpression - Products array mapped to GA4 item schema

Checkout Started

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - begin_checkout
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueExpression - Total value calculated via TOTAL_VALUE from products array
event.params.couponString: Coupon codeproperties.coupon
event.params.itemsArray: Items in checkoutExpression - Products array mapped to GA4 item schema

Payment Info Entered

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - add_payment_info
event.params.couponString: Coupon codeproperties.coupon
event.params.payment_typeString: Payment methodproperties.payment_method

Product Added to Wishlist

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - add_to_wishlist
event.params.currencyString: Currencyproperties.currency (default: USD)
event.params.valueFloat: Total valueExpression - Total value calculated via TOTAL_VALUE from product properties
event.params.itemsArray: Items added to wishlistExpression - Product mapped to GA4 item schema

Order Refunded

Output KeyDescriptionExpected Input
event.name RequiredString: The name of the eventEnrichment - refund
event.params.couponString: Coupon codeproperties.coupon
event.params.currencyString: Currencyproperties.currency
event.params.shippingFloat: Shipping costproperties.shipping
event.params.taxFloat: Tax amountproperties.tax
event.params.transaction_id RequiredString: Transaction IDproperties.order_id
event.params.valueFloat: Total valueproperties.total
event.params.itemsArray: Items refundedExpression - Products array mapped to GA4 item schema

Required & Recommended Identifiers

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.

AttributeDescriptionExampleSync Injector Required?
client_id RequiredGoogle Analytics client ID35009a79-1a05-49d7-b876-2b884d0f825bYes
user_id RecommendedCustom user identifieruser_12345No
session_id RecommendedSession identifier1595262825000Yes
session_number RecommendedSession count3Yes

Session-Level Attribution (via Gtag Sync)

The following identifiers are handled via session-level linking through the Google Gtag sync, not as event-level mappings:

AttributeDescriptionExample
gclidGoogle Click IdentifierCjwKCAjwt-OwBhBnEiwAgwzrUkyN...
dclidGoogle Display Click IdentifierCKDdz-fE_IUDFYtTCQkdbyMOPg

Additional GA4 - Measurement Protocol Documentation

Measurement Protocol Guide
Send user provided data