AUTOMATION Β· 14 min lezen

Sending GA4 Events from Salesforce with Flow

Send server-side events to Google Analytics 4 via the Measurement Protocol when something meaningful happens in Salesforce. This article explains the asynchronous approach using a Subflow and HTTP Callout, including configuration via Custom Metadata Types (CMDT).

With the GA4 Measurement Protocol you can pass important CRM moments from Salesforce β€” like a new lead, a won opportunity or a closed case β€” server-side to Google Analytics 4. This improves attribution, helps you focus on the right channels and makes your reports more reliable. On this page we show how to set this up safely and scalably using asynchronous Flows, Subflows and CMDT. Salesforce Standard & Custom Objects & Automating with Flow.

What is GA4 Measurement Protocol?

A server-side way to send events to GA4, without a browser or tag manager. Ideal for including CRM signals from Salesforce in marketing and customer insight reports.

What does asynchronous mean in Flow?

Asynchronous means: first save the record, then send the event. This keeps transactions stable and users don't experience delays. This aligns with the Flow best practice of doing callouts after the commit.

Note! Always send events from an Asynchronous Path. This prevents time-outs and incomplete transactions.

Best practice Use one main flow per object and have it start a reusable Subflow. This makes maintenance simple and consistent.

What exactly does Salesforce do here? Salesforce determines when an event is relevant (e.g., stage changes to Closed Won) and adds CRM context to it. GA4 then records the marketing and attribution signal.

Architecture at a glance

Record-Triggered Flow
β†’
Asynchronous Path
β†’
Subflow β†’ HTTP callout β†’ GA4

The result is stored in a simple log for monitoring.

Lead

FlexFit Bikes receives a lead via the web form for 12 e-bikes (Marco Metselaar, GoedBouw BV). Send along: lead source, record ID, organization name, contact name, number of bikes.

Opportunity

The opportunity moves to Closed Won. Send along: record ID, stage/status, amount, currency and account name.

Case

Battery issue is Closed with resolution reason. Send along: record ID, status, resolution reason, time to close and category.

Closed Won event to GA4 β€” in 6 steps

1

Opportunity stage changes to Closed Won.

2

Record-Triggered Flow detects the change and goes through the Decision.

3

Asynchronous Path starts after the commit.

4

Subflow "Send GA4 Event" determines event name and parameters (amount, currency, record ID).

5

HTTP callout to GA4 Measurement Protocol sends the event.

6

Result is logged; on error you'll see status and message.

Subflow "Send GA4 Event" β€” element by element

  1. Define resources: text fields for Measurement ID, API Secret, event name, website/domain, client_id, composed body, response and status code.
  2. Retrieve settings via CMDT: per site/domain the Measurement ID and API Secret are ready, plus a default event name.
  3. Compose event name and parameters per object (Lead/Opportunity/Case) with the most meaningful fields.
  4. Configure HTTP callout: POST to the GA4 endpoint, with Content-Type application/json and query parameters for Measurement ID and API Secret.
  5. Check result: 2xx = OK; otherwise error log with status and response.

Tip for scalability: manage multiple websites or brands with CMDT. You can easily switch Measurement ID or event name without modifying your flows.

Event naming convention

Use short, lowercase names with underscores. Some examples:

CRM momentEvent nameKey parameters
Lead createdlead_createdlead_source, sf_record_id
Opportunity wonopportunity_wonamount, currency, sf_record_id
Case closedcase_closedresolution, time_to_close, sf_record_id

Validation & testing

  • Flow Debug: step by step verify that the Subflow builds the correct values.
  • Use known test payloads and verify in GA4 DebugView that events arrive.
  • Checklist: correct Measurement ID and API Secret, client_id present, consistent event names and 2xx response.

Want to send GA4 events server-side from Salesforce?

We help you set up the integration with asynchronous Flows, HTTP Callouts and CMDT for reliable attribution.