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

EnableGoogle 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 - The Tag ID in GA4, also known as the Measurement ID, can be found in Data Streams. Alternatively, you can find it in your GTAG settings. Examples of Tag IDs include GT-XXXXXXXXX, G-XXXXXXXXX, and AW-XXXXXXXXX. For more information on locating the GTAG.js Tag ID, please refer to this guide
    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 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

user_id

String: User ID

userId

client_id
Required

String: Client ID

N/A - Expression

timestamp_micros
Required

Integer: Timestamp in microseconds

N/A - Expression

event.params.gclid

String: Google Click Identifier

N/A - Expression

event.params.dclid

String: Google Display Click Identifier

N/A - Expression

event.params.session_id

Integer: Session ID

context.providers.googleGtag.data.sessionID

event.params.session_number

Integer: Session number

context.providers.googleGtag.data.sessionCount


Event Specific

Page

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

N/A - Expression

event.params.page_referrer

String: The URL of the previous page that led to the current page

N/A - Expression

Products Searched

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

Product List Viewed

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

event.params.item_list_name

String: The name of the item list

properties.item_list_name

event.params.items

Array: List of items viewed

properties.items

Promotion Viewed

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

event.params.creative_name

String: Creative name

properties.creative_name

event.params.creative_slot

String: Creative slot

properties.creative_slot

Promotion Clicked

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

event.params.creative_name

String: Creative name

properties.creative_name

event.params.creative_slot

String: Creative slot

properties.creative_slot

Product Clicked

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - select_item

event.params.items

Array: Items clicked

properties.items

event.params.currency

String: Currency

properties.currency

Product Viewed

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - view_item

event.params.items

Array: Items viewed

properties.items

event.params.currency

String: Currency

properties.currency

event.params.value

Float: Total value

properties.value

Product Added

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - add_to_cart

event.params.items

Array: Items added to cart

properties.items

event.params.currency

String: Currency

properties.currency

event.params.value

Float: Total value

properties.value

Product Removed

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - remove_from_cart

event.params.items

Array: Items removed from cart

properties.items

event.params.currency

String: Currency

properties.currency

event.params.value

Float: Total value

properties.value

Cart Viewed

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - view_cart

event.params.items

Array: Items in cart

properties.items

event.params.currency

String: Currency

properties.currency

event.params.value

Float: Total value

properties.value

Order Completed

Output Key

Description

Expected Input

event.name Required

String: The name of the event

Enrichment - purchase

event.params.affiliation

String: Affiliation or store name

properties.affiliation

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

event.params.value

Float: Total value of the purchase

properties.total

event.params.items

Array: The items in the purchase

N/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.

Attribute

Example

Sync Injector Required?

client_id Required

35009a79-1a05-49d7-b876-2b884d0f825b

Yes

gclid
Recommended

&gclid=CjwKCAjwt-OwBhBnEiwAgwzrUkyN...

Yes

dclid
Recommended

&dclid=CKDdz-fE_IUDFYtTCQkdbyMOPg

Yes

user_id
Recommended

user_12345

No

session_id
Recommended

1595262825000

Yes

session_number
Recommended

3

Yes


Additional GA4 - Measurement Protocol Documentation

Measurement Protocol Guide
Send user provided data