Google Analytics 4 Measurement Protocol
Learn how to send Hardal analytics data to Google Analytics 4 using the Measurement Protocol
Google Analytics 4 (GA4) Measurement Protocol Integration
Overview
This guide explains how to send your Hardal analytics data directly to Google Analytics 4 (GA4) using the Measurement Protocol. This server-to-server integration enables you to maintain accurate analytics when client-side tracking is limited by ad blockers or privacy controls.
Prerequisites
Before setting up this integration, ensure you have:
-
An active Hardal account with the tracking script installed
-
Access to your Google Analytics 4 property
-
A GA4 data stream created for your website or app
-
API secret and Measurement ID from your GA4 property
-
Basic understanding of HTTP requests and JSON
Setting Up GA4 Measurement Protocol
Obtain your GA4 API credentials
Sign in to Google Analytics
Access your Google Analytics 4 property at analytics.google.com
Navigate to Data Streams
Go to Admin > Data Streams and select your web data stream
Access API secrets
Click on Measurement Protocol API secrets in the stream settings
Create a new secret
Click the Create button to generate a new API secret
Copy credentials
Copy both your Measurement ID (G-XXXXXXXX) and the newly created API Secret
Configuring the Hardal Integration
Access Hardal destinations
Log in to Hardal
Sign in to your Hardal dashboard at app.usehardal.com
Access Marketing Destinations
Navigate to the Marketing Destinations section in the main menu
Add new destination
Click the Add Custom Destination button
Select GA4 template
From the available templates, select “GA4 Measurement Protocol” (or create a custom API connection if not available)
Endpoint Configuration
Configure your GA4 endpoint with the following settings:
Event Mapping
Basic Event Mapping
The integration automatically maps common Hardal events to GA4 events. Here’s how key events are mapped:
Hardal Event | GA4 Event |
---|---|
page_view | page_view |
click | click |
purchase | purchase |
add_to_cart | add_to_cart |
begin_checkout | begin_checkout |
view_item | view_item |
Custom Event Mapping
For custom events, you may need to create a specialized mapping. Here’s an example mapping for an e-commerce purchase event:
Advanced Configuration
Including User Properties
To include user properties with your events, add a user_properties
object to your request format:
Setting Custom Parameters
For advanced use cases, you can include custom parameters with your events:
Event Validation
After setting up your integration, verify that events are being properly received:
-
Send test events through Hardal
-
Check the GA4 DebugView to see if events are appearing
-
Verify events are showing in GA4 reports (may take up to 24 hours)
Best Practices
Performance Considerations
-
Batch multiple events in a single request when possible (up to 25 events)
-
Implement error handling and retry logic for failed requests
-
Use appropriate caching strategies to handle high traffic volumes
Data Quality
-
Include session_id and engagement_time_msec with all events
-
Use consistent parameter naming conventions
-
Avoid sending Personally Identifiable Information (PII)
-
Validate data formats before sending (especially for currency values)
Privacy Compliance
-
Ensure your data collection complies with privacy regulations
-
Honor user consent preferences when applicable
-
Include appropriate disclosures in your privacy policy
-
Consider implementing data filtering for sensitive information
Troubleshooting
Complete Implementation Example
Here’s a complete implementation example showing how to set up a custom destination in Hardal that sends e-commerce purchase events to GA4:
Limitations
Be aware of these GA4 Measurement Protocol limitations:
-
Maximum 25 events per request
-
Maximum 25 parameters per event
-
Maximum 25 user properties per request
-
User property names limited to 24 characters
-
User property values limited to 36 characters
-
Event names limited to 40 characters
-
Parameter names limited to 40 characters
-
Parameter values limited to 100 characters (500 for GA4 360)
-
Maximum request body size of 130KB