Automation
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).
- Reading time
- 3 min
- Published
- Updated
With the GA4 Measurement Protocol you can pass important CRM moments from Salesforce, such as a new lead, a won opportunity or a closed case, server-side to Google Analytics 4. That improves attribution, helps you focus on the right channels and makes your reports more reliable. This page shows how to set it up safely and at scale with asynchronous flows, subflows and CMDT. If those parts are new to you, read about standard and custom objects and automating with Salesforce Flow first.
What is the GA4 Measurement Protocol?
A server-side way to send events to GA4, without a browser or tag manager. It lets you include CRM signals from Salesforce in your marketing and customer reports. Technically it is an integration between Salesforce and another system, which you build here with Flow instead of code.
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.
What does asynchronous mean in Flow?
Asynchronous means the record is saved first and the event is sent afterwards. Transactions stay stable and users don't notice any delay. This matches the Flow guideline to make callouts after the commit.
Always send events from an Asynchronous Path. This prevents time-outs and incomplete transactions.
Architecture at a glance
- A record-triggered flow picks up the change on the record.
- An asynchronous path starts after the record is saved.
- A subflow makes the HTTP callout to GA4.
The result is stored in a simple log for monitoring.
Use one main flow per object and have it start a reusable subflow. That keeps maintenance simple and consistent. How CRM Force sets up flows like these is described under process automation in Salesforce.
Which moments do you send?
Lead
A bike shop receives a lead through the web form for 12 e-bikes from a construction company. Send along: lead source, record ID, organization name, contact name and number of bikes.
Opportunity
The opportunity moves to Closed Won. Send along: record ID, stage/status, amount, currency and account name.
Case
A case about a battery problem moves to Closed, with a resolution reason. Send along: record ID, status, resolution reason, time to close and category.
A Closed Won event to GA4 in six steps
- Opportunity stage changes to Closed Won.
- Record-Triggered Flow detects the change and goes through the Decision.
- Asynchronous Path starts after the commit.
- Subflow "Send GA4 Event" determines event name and parameters (amount, currency, record ID).
- HTTP callout to GA4 Measurement Protocol sends the event.
- Result is logged; on error you'll see status and message.
Subflow "Send GA4 Event", element by element
- Define resources: text fields for Measurement ID, API Secret, event name, website/domain, client_id, composed body, response and status code.
- Retrieve settings via CMDT: per site/domain the Measurement ID and API Secret are ready, plus a default event name.
- Compose event name and parameters per object (Lead/Opportunity/Case) with the most meaningful fields.
- Configure HTTP callout: POST to the GA4 endpoint, with Content-Type application/json and query parameters for Measurement ID and API Secret.
- Check result: 2xx = OK; otherwise error log with status and response.
Manage multiple websites or brands with CMDT. You can then switch the Measurement ID or event name without changing your flows.
How to name your events
Use short, lowercase names with underscores. Some examples:
| CRM moment | Event name | Key parameters |
|---|---|---|
| Lead created | lead_created | lead_source, sf_record_id |
| Opportunity won | opportunity_won | amount, currency, sf_record_id |
| Case closed | case_closed | resolution, time_to_close, sf_record_id |
Validating and 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.
Schedule an integration session