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.

MetaRouter has two integrations for GA4. The GA4 - Collect integration uses the collect endpoint for data and measurement, and it is the recommended integration for GA4. The GA4 - Measurement integration uses Measurement Protocol. For more information about Google Analytics 4- Collect, please see here.


Google Analytics 4 - Collect Endpoint vs Measurement Protocol

Collect Endpoint:

  • More data accuracy in
    • Age demographic
    • Page count
    • Session start events
  • Cannot collect screen resolution data

Measurement Protocol:

  • Can collect screen resolution data
  • More data on device category

Getting Started - From Your GA4 Account

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. Ex, “G-XXXXX00000”.

Obtain your API Secret

  1. Sign in to Google Analytics:
  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.
    • Provide a nickname for your API secret (e.g., "My API Secret").
  8. Once you have provided a nickname, click "Create" to generate the secret.
    • The API secret will be displayed. Copy this secret and store it securely, as it will be required for authenticating requests to the GA4 Measurement Protocol.

We recommend that you keep these private to your organization. If you deploy the measurement protocol client-side, you should regularly rotate api_secrets to avoid excessive SPAM.


Getting Started - From Your MetaRouter Account

Adding a Google Analytics 4 integration.

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.

Adding a Google Gtag Sync

To gather the cidgclid (Google click ID) value, dclid (Display click ID) value, session ID, and session count, you must add a Google Gtag sync.

  1. From the Pipelines page, find the pipeline associated with the web property you’d like to add a sync to. Hover over the three dot dropdown and select “Build AJS File.”
  2. In the Identity Syncs section, select the Google Gtag sync.
  3. Fill out the following fields:
    1. GTAG.js Tag ID - You can find more information on GTAG.js Tag ID here.
    2. Destination IDs - Allows the sync to connect and direct events to the correct Google product. For Google Ads, the destination ID is the same as the conversion tracking ID, for example AW-98765.
    3. Floodlight Advertiser ID Object - The Floodlight Advertiser ID. This is not required for the Google Ads integration, but it is used for other Google integrations such as Campaign Manager.
    4. Cookie Lifetime (in days) - 45 days default
    5. Fire on Re-sync - Re-syncs for an updated identifier when an Identify call is made.
    6. Send MetaRouterSync to GA4 - Sends a MetaRouterSync event to GA4 when the sync is loaded on the page.
    7. Enable Google Consent Mode - If enabled, consent categories 'ad _storage, 'ad_user_data', 'ad _personalization', 'analytics_storage' will be sent to Google when user is opt-in or opt -out
    8. Advanced Consent Mode Type (when consent mode is enabled) - If consent mode is enabled, the consent mode will be set to advanced' when this is on, and 'basic' when this is off
  4. Scroll down and click the Save and Build File button.
  5. Deploy your AJS file to propagate changes to your web property.

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

Output KeyDescriptionExpected Input
event.params.data_sourceString: Data source of the eventEnrichment - S2S
event.params.engagement_time_msecInteger: Engagement time in millisecondsEnrichment - 1
user_idString: User IDuserId
client_id
Required
String: Client IDN/A - Expression
timestamp_micros
Required
Integer: Timestamp in microsecondsN/A - Expression
event.params.gclidString: Google Click IdentifierN/A - Expression
event.params.dclidString: Google Display Click IdentifierN/A - Expression
event.params.session_idInteger: Session IDcontext.providers.googleGtag.data.sessionID
event.params.session_numberInteger: Session numbercontext.providers.googleGtag.data.sessionCount

Event Specific

Page

Output KeyDescriptionExpected Input
event.name
Required
String: 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 pageN/A - Expression
event.params.page_referrerString: The URL of the previous page that led to the current pageN/A - Expression

Products Searched

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - search
event.params.search_termString: Search term usedproperties.search_term

Product List Viewed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - view_item_list
event.params.item_list_idString: The ID of the item listproperties.item_list_id
event.params.item_list_nameString: The name of the item listproperties.item_list_name
event.params.itemsArray: List of items viewedproperties.items

Promotion Viewed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - view_promotion
event.params.promotion_idString: Promotion IDproperties.promotion_id
event.params.promotion_nameString: Promotion nameproperties.promotion_name
event.params.creative_nameString: Creative nameproperties.creative_name
event.params.creative_slotString: Creative slotproperties.creative_slot

Promotion Clicked

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - select_promotion
event.params.promotion_idString: Promotion IDproperties.promotion_id
event.params.promotion_nameString: Promotion nameproperties.promotion_name
event.params.creative_nameString: Creative nameproperties.creative_name
event.params.creative_slotString: Creative slotproperties.creative_slot

Product Clicked

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - select_item
event.params.itemsArray: Items clickedproperties.items
event.params.currencyString: Currencyproperties.currency

Product Viewed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - view_item
event.params.itemsArray: Items viewedproperties.items
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueproperties.value

Product Added

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - add_to_cart
event.params.itemsArray: Items added to cartproperties.items
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueproperties.value

Product Removed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - remove_from_cart
event.params.itemsArray: Items removed from cartproperties.items
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueproperties.value

Cart Viewed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - view_cart
event.params.itemsArray: Items in cartproperties.items
event.params.currencyString: Currencyproperties.currency
event.params.valueFloat: Total valueproperties.value

Order Completed

Output KeyDescriptionExpected Input
event.name
Required
String: The name of the eventEnrichment - purchase
event.params.affiliationString: Affiliation or store nameproperties.affiliation
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
Required
String: Transaction IDproperties.checkout_id
event.params.valueFloat: Total value of the purchaseproperties.total
event.params.itemsArray: The items in the purchaseN/A - Expression

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.

AttributeExampleSync Injector Required?
client_id
Required
35009a79-1a05-49d7-b876-2b884d0f825bYes
gclid
Recommended
&gclid=CjwKCAjwt-OwBhBnEiwAgwzrUkyN...Yes
dclid
Recommended
&dclid=CKDdz-fE_IUDFYtTCQkdbyMOPgYes
user_id
Recommended
user_12345No
session_id
Recommended
1595262825000Yes
session_number
Recommended
3Yes

Additional GA4 - Measurement Protocol Documentation

Measurement Protocol Guide
Send user provided data