Skip to main content

GA4 Measurement Protocol

Send Hardal analytics data directly to Google Analytics 4 using server-to-server integration to bypass client-side tracking limitations.
Make sure to check the partner’s website and API documentation for the most up-to-date information and configurations.

Setup

1

Get GA4 Credentials

Go to Google Analytics → Admin → Data Streams → Select your stream → Measurement Protocol API secrets → Create new secret and copy Measurement ID (G-XXXXXXXX) and API Secret
2

Add Destination

Go to Hardal dashboard → Marketing Destinations → “Add Custom Destination” → Select “GA4 Measurement Protocol” template
3

Configure Endpoint

{
  "endpoint_url": "https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXX&api_secret=YOUR_API_SECRET",
  "request_method": "POST",
  "content_type": "application/json"
}
4

Set Event Format

{
  "client_id": "##user_id##",
  "events": [
    {
      "name": "##event_name##",
      "params": {
        "session_id": "##session_id##",
        "engagement_time_msec": 100,
        "page_location": "##page.url##",
        "page_title": "##page.title##",
        "page_referrer": "##page.referrer##"
      }
    }
  ]
}

Event Mapping

Hardal EventGA4 Event
page_viewpage_view
clickclick
purchasepurchase
add_to_cartadd_to_cart
begin_checkoutbegin_checkout
view_itemview_item

E-commerce Events

Purchase Event:
{
  "client_id": "##user_id##",
  "events": [
    {
      "name": "purchase",
      "params": {
        "transaction_id": "##properties.transaction_id##",
        "value": "##properties.value##",
        "currency": "##properties.currency##",
        "tax": "##properties.tax##",
        "shipping": "##properties.shipping##",
        "items": "##properties.items##",
        "session_id": "##session_id##"
      }
    }
  ]
}

Available Variables

  • ##user_id## - User identifier (used as client_id)
  • ##session_id## - Session identifier
  • ##event_name## - Event name
  • ##page.url## - Current page URL
  • ##page.title## - Page title
  • ##page.referrer## - Referrer URL
  • ##properties.*## - Event properties
  • ##created_at## - Event timestamp
Keep your API secret secure and never expose it in client-side code.