To send offline events to GA4 with the Measurement Protocol, you POST JSON to https://www.google-analytics.com/mp/collect with your measurement_id and an api_secret, and you include the client_id the browser had when the person was on the site. If you also include that visit's session_id and send within 24 hours of the session start, GA4 reports the event with the original session's source and medium. Without those two IDs, the event lands on a new or anonymous user and shows up as (not set) or Unassigned.
This is for agency developers and PPC managers who need CRM stages, phone sales, refunds or subscription renewals inside GA4 and want them attributed, not just counted. It covers capturing the IDs on the site, the exact payload, every time window that matters, validation, consent fields, the reasons events end up as Unassigned, and what changes when those events flow on to Google Ads.
What the GA4 Measurement Protocol can and cannot do for offline events
The Measurement Protocol is a plain HTTP API. Your server sends events, GA4 stores them on whatever user the client_id (web) or app_instance_id (app) points to. That is the whole mechanism. It has no access to the browser, no cookies of its own, and no idea where the visitor came from.
What it does well:
- Adds events to an existing user. A lead that becomes qualified in HubSpot three days later can show up on the same GA4 user that submitted the form.
- Joins an existing session. With a valid
session_id sent inside the window, the event inherits that session's attribution.
- Feeds key events to linked ad platforms. Google's use-case docs say GA4 includes Measurement Protocol events in exports to linked advertising products such as Google Ads.
- Feeds audiences. A
close_convert_lead sent by the CRM can drive an audience of customers for exclusion or remarketing.
What it does not do:
- It has no source or medium field. The request body has
client_id, user_id, timestamp_micros, user_properties, user_data, consent, user_location, ip_override, device, validation_behavior and events. Nothing in there says "google / cpc". Attribution only comes from joining a session the tag already recorded.
- It does not tell you about errors. The production endpoint does not return HTTP error codes, even for a malformed event. A broken integration looks exactly like a working one from the server side.
- It cannot send automatic events.
session_start, first_visit and user_engagement are on the reserved list, along with others. Requests using them are not something you can rely on.
- It cannot rescue events with no browser history. A phone lead that never touched the site has no
client_id. You can invent one, but that creates a brand new user with no acquisition data.
Where do the measurement_id and api_secret come from?
The measurement_id is the G- ID of the web data stream, the same one your Google tag uses. The api_secret is created on that same stream: in GA4 go to Admin, then Data streams, open the web stream, and find Measurement Protocol API secrets. Create one per integration (one for the CRM, one for Stripe) so you can revoke one without breaking the other.
Both go in the query string. The secret is private. Google's docs say not to expose it in client-side code, which rules out calling the endpoint from the browser. Keep it in an environment variable on the server, the CRM workflow's secret store, or your server-side GTM container.
POST https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_SECRET
Content-Type: application/json
For EU data collection, Google documents region1.google-analytics.com as the host. The path and parameters stay the same.
How do you get the client_id from the _ga cookie?
You need to capture the ID while the person is still on the site, then carry it through the form into your CRM. Two ways to read it.
Option 1: gtag get (preferred)
The gtag.js reference documents a get command that returns client_id, session_id and session_number for a GA4 target. This is the safest route because you never parse cookie strings yourself.
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
var MEASUREMENT_ID = 'G-XXXXXXXXXX';
function fillField(name, value) {
var inputs = document.querySelectorAll('input[name="' + name + '"]');
for (var i = 0; i < inputs.length; i++) {
if (value) inputs[i].value = String(value);
}
}
gtag('get', MEASUREMENT_ID, 'client_id', function (cid) {
fillField('ga_client_id', cid);
});
gtag('get', MEASUREMENT_ID, 'session_id', function (sid) {
fillField('ga_session_id', sid);
});
</script>
Add two hidden fields, ga_client_id and ga_session_id, to every lead form and map them to CRM properties. If the Google tag is loaded through Tag Manager, the stub above still pushes to the same dataLayer, but test it in the browser console on the live site before you trust it. If the callback never fires, the tag has not loaded, often because consent has not been given yet.
Multi-step forms and forms rendered after page load (popups, embedded iframes, AJAX-loaded steps) need the fill to run after the field exists. Run fillField again when the step renders, or set the values on submit. Forms inside a third-party iframe on another domain cannot read your cookies at all, so the ID has to be passed in through the iframe URL if the vendor supports it.
Option 2: parse the cookie (fallback)
The _ga cookie looks like GA1.1.1234567890.1700000000. The client ID is the last two dot-separated parts: 1234567890.1700000000. Send it in that exact form. Do not send the full cookie value and do not strip the second number.
function readCookie(name) {
var parts = document.cookie.split('; ');
for (var i = 0; i < parts.length; i++) {
var idx = parts[i].indexOf('=');
if (parts[i].slice(0, idx) === name) return decodeURIComponent(parts[i].slice(idx + 1));
}
return null;
}
var ga = readCookie('_ga');
var clientId = ga ? ga.split('.').slice(2).join('.') : null;
The session ID lives in a second cookie named _ga_ plus the stream ID without the G- prefix. Its format changed in 2025 from values starting GS1.1. to values starting GS2.1. with $-separated segments, where the session ID sits in the segment that starts with s. Google does not document this cookie format, and it has already changed once without notice. That is the reason to prefer gtag('get'). If you must parse it, handle both formats and send nothing rather than a wrong number.
How does GA4 attribute Measurement Protocol events to a session?
Google's Measurement Protocol use-case page sets three conditions for an event to appear in reports with the same session attributes as the online visit:
- Include the session_id. Put
session_id in the event's params, using the value from the client-side session. It must be digits only. The reference gives the pattern ^\d+$.
- Send within 24 hours of the session start. Google's own example: a session that started at 11:15 AM Monday needs the request sent before 11:15 AM Tuesday.
- Keep the timestamp inside the session. If you override
timestamp_micros, it has to fall between the session's start and end.
Same client_id as the browser, too, obviously. A matching session_id on a different client is just a number.
Here is the catch most guides skip: CRM stages like "qualified" usually happen days after the visit. You cannot meet the 24-hour session condition for those. That does not make them useless. It means they will not carry session-scoped source and medium in the Traffic acquisition report. They still sit on the right user, so user-scoped dimensions such as first user source still work, and Google Ads export follows a different, longer window (covered below).
The time windows, side by side
| Goal | Window | Needs session_id? |
| Report with the online session's attributes | Within 24 hours of the session start, timestamp inside the session | Yes |
| Join with gtag.js events in general | Within 48 hours of the original client-side event | Recommended |
| Backdate with timestamp_micros | Up to 72 hours in the past | No |
| Use in audiences (web stream) | Within 30 days of the latest online event for that client_id | No |
| Export to linked ad platforms | Within 63 days of the latest online event, and inside the key event's attribution window | No |
The 72-hour figure is a backdating limit, not an attribution window. People mix these up constantly. With the default validation_behavior of RELAXED, an event timestamped more than 72 hours ago is accepted but its timestamp is moved to 72 hours ago. With ENFORCE_RECOMMENDATIONS, the request is rejected. Also note the unit: timestamp_micros is microseconds. A millisecond timestamp is off by a factor of 1,000 and gets clamped or rejected.
A working payload for a CRM qualified lead
Google's recommended lead events are generate_lead, working_lead, qualify_lead, disqualify_lead, close_convert_lead and close_unconvert_lead. Use those names rather than inventing sql_created. GA4's lead reports are built on them. The site sends generate_lead; the CRM sends the rest.
{
"client_id": "1234567890.1700000000",
"user_id": "crm_000482",
"consent": {
"ad_user_data": "GRANTED",
"ad_personalization": "GRANTED"
},
"events": [
{
"name": "qualify_lead",
"params": {
"session_id": "1700000000",
"engagement_time_msec": 100,
"currency": "USD",
"value": 500,
"lead_source": "contact_form"
}
}
]
}
Notes on each field:
- client_id. The stored value from the hidden field, unchanged.
- user_id. Optional. Only send it if the site also sets the same
user_id through the tag, otherwise it does nothing useful. Use an internal ID, never an email or phone number. user_id is also a reserved user property name, so it goes at the top level, not in user_properties.
- session_id. Include it when you have it, even outside the 24-hour window. It costs nothing and helps when the event is fast.
- engagement_time_msec. Google's examples include it on every event, and DebugView needs a positive value. Send a small number like 100.
- value and currency. Send both or neither. A value without currency is a common reason revenue looks empty.
Server code (Node, no dependencies)
const MP_URL = 'https://www.google-analytics.com/mp/collect'
+ '?measurement_id=' + encodeURIComponent(process.env.GA4_MEASUREMENT_ID)
+ '&api_secret=' + encodeURIComponent(process.env.GA4_API_SECRET);
async function sendQualifiedLead(lead) {
if (!lead.ga_client_id) {
console.warn('No client_id for lead ' + lead.id + ', skipping GA4');
return;
}
const params = {
engagement_time_msec: 100,
currency: 'USD',
value: lead.estimated_value || 0
};
if (/^\d+$/.test(lead.ga_session_id || '')) {
params.session_id = lead.ga_session_id;
}
const body = {
client_id: lead.ga_client_id,
events: [{ name: 'qualify_lead', params: params }]
};
const res = await fetch(MP_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
// A 2xx here does NOT mean GA4 accepted the event. Validate separately.
return res.status;
}
The guard at the top matters. Sending with an empty or made-up client_id creates junk users and is one of the main sources of (not set) rows. Skip and log instead.
Refunds, renewals and other backend events
- Refund. Use the recommended
refund event with the original transaction_id, currency and value. Add items for a partial refund. Send it from the payment webhook. If the original purchase has a duplicate problem, fix that first, see GA4 purchase tracking and duplicate transactions.
- Subscription renewal. A renewal months later has no live session. Send it as
purchase or a custom event on the stored client_id and accept that it will not carry session attribution. The Stripe conversion tracking guide covers where to store the IDs on the customer object.
- Closed deal.
close_convert_lead with the real deal value. Mark it as a key event if you want it in Google Ads.
- Phone or walk-in sale with no web visit. Do not send it to GA4. There is no user to attach it to. Use a Google Ads offline import or your CRM reporting instead.
Name things consistently across the site and the CRM. If the site fires generate_lead and the CRM fires Lead Qualified, reports will never line up. Our GA4 key events and naming plan has a template.
How do you test with the /debug/mp/collect validation server?
Swap /mp/collect for /debug/mp/collect and send the same request. The validation server returns a JSON body with a validationMessages array. Each message has a fieldPath, a description and a validationCode. An empty array means the payload structure is fine.
curl -s -X POST "https://www.google-analytics.com/debug/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_SECRET" \
-H "Content-Type: application/json" \
-d '{"client_id":"1234567890.1700000000","events":[{"name":"qualify_lead","params":{"session_id":"1700000000","engagement_time_msec":100}}]}'
Know its limits before you sign off:
- It does not check the api_secret. A wrong secret, or a secret from a different stream, passes validation and then fails silently in production.
- Events sent there never reach reports. It checks shape, not delivery.
- It cannot tell you about attribution. A valid payload with a stale session ID still validates.
A full test has three steps:
- Validate the payload on
/debug/mp/collect until the array is empty.
- Send to production with debug_mode. Add
"debug_mode": true to the event params and a positive engagement_time_msec, then watch DebugView in GA4. Use a real client_id copied from your own browser. Practitioners report that invented IDs with no prior data often do not show up in DebugView at all.
- Check reports after processing. The next day, open an exploration with event name, session source / medium and first user source / medium. Your test event should sit on the same source as your test visit. Remove
debug_mode before going live.
Why do Measurement Protocol events show as (not set) or Unassigned?
Google's own help page gives the core answer: when session-based Measurement Protocol events report as (not set) / (not set), send session_id with a valid value from the client-side event. In practice, it is one of these:
| Cause | What you see | Fix |
| No session_id sent | Session source (not set), channel Unassigned | Capture and send it |
| session_id sent after 24 hours | Same as above for session dimensions | Report on user-scoped dimensions, or send faster |
| Made-up or empty client_id | New users with no acquisition data | Skip events with no stored ID |
| Full cookie value sent as client_id | New users, nothing joins | Send only the last two parts |
| session_id with letters (from GS2 parsing) | Event rejected or unjoined | Send digits only, prefer gtag get |
| Wrong measurement_id for the secret | Nothing at all | Check the secret belongs to that stream |
| Timestamp in milliseconds | Event dated wrong or rejected | Multiply seconds by 1,000,000 |
| Consent banner blocked the tag | No client_id captured for that lead | Expected, do not fake one |
One more source of Unassigned: the client side. If the site loads the Google tag twice, or a plugin reinitializes it, sessions themselves can lose their source before the Measurement Protocol is even involved. Fix the tag before blaming the server. If CRM records themselves show leads as Direct, that is a separate capture problem, covered in CRM leads showing as direct.
Double counting from webhooks
CRM and payment webhooks retry. A HubSpot workflow re-enrolls a contact, Stripe resends an event, a Zapier step reruns. Each retry sends another qualify_lead. Do not expect GA4 to drop the repeats for you. Store a "sent to GA4" flag or the event ID on the record and check it before sending. For lead stages, send each stage once per lead.
Which consent parameters does the Measurement Protocol accept?
The request body takes a consent object with two fields, ad_user_data and ad_personalization. Each is GRANTED or DENIED. The older non_personalized_ads boolean is deprecated in favor of ad_personalization.
Two things to know:
- There is no analytics_storage field. The protocol assumes you are allowed to send the event. If the visitor refused analytics on the site, you should not have a
client_id for them, and you should not send.
- Omitting consent has a default. Google's reference says that if you leave
consent out, GA4 uses the consent settings from the corresponding online interactions for that client. Store the visitor's consent choice with the lead and send it explicitly when you can, so it is visible in your code.
For ads use this matters. Google's Tag Manager help notes that when ad_user_data is denied, exporting click-ID based conversion data to Google Ads is limited. The site side of this is in the Consent Mode v2 implementation guide.
What happens when GA4 imports these events into Google Ads?
If GA4 is linked to Google Ads and you mark qualify_lead or close_convert_lead as a key event, you can import it into Google Ads as a conversion action. Measurement Protocol events are included in those exports when they meet the export window: no later than 63 days after the latest online event for that client_id, and inside the key event's attribution window. A session ID is not required for export.
Things that trip agencies up:
- The ad click has to be on that client_id. Google Ads can only credit a campaign if the GA4 user it lands on came from an ad. A lead from organic search will never show in Ads, which is correct.
- Delays stack. The CRM stage takes days, GA4 processing takes time, and the Ads import adds more. Smart Bidding sees these conversions late. Set expectations with the client.
- Do not count the same stage twice. If you also upload qualified leads to Google Ads directly with a GCLID import, pick one as primary. Two primary actions for the same stage double the signal bidding sees.
- Direct import is often better for Ads. For bidding on lead quality, a native Google Ads offline conversion import from the CRM or enhanced conversions for leads matches on the click or hashed user data, does not depend on the
client_id surviving, and supports longer lag. Use the Measurement Protocol to get CRM stages into GA4 reporting, and a direct import when Ads bidding is the goal.
A setup checklist
- Capture. Hidden
ga_client_id and ga_session_id fields on every form, filled with gtag('get'), mapped to CRM properties.
- Verify capture. Submit five test leads from different browsers and confirm both fields arrive in the CRM. Empty fields here mean nothing downstream will work.
- Create the secret. One
api_secret per integration, stored server-side.
- Use recommended names.
qualify_lead, close_convert_lead, refund.
- Guard the sender. Skip events with no
client_id, validate session_id is digits, send each stage once.
- Validate, then DebugView. Empty
validationMessages, then a visible event in DebugView with your real client ID.
- Mark key events and decide whether Ads gets them through GA4 or a direct import, not both as primary.
- Review weekly at first. Compare the CRM count of qualified leads with the GA4 count. A large gap usually means missing IDs at capture.
Official references worth bookmarking: Send Measurement Protocol events, the Measurement Protocol reference, Validate events and the Measurement Protocol use cases page with the time windows.
Getting it fixed for a client
Most broken Measurement Protocol setups we see are not broken in the server code. The IDs were never captured on the form, or the session ID came from a cookie parser that stopped working in 2025. Checking capture first saves days. If you want a second pair of eyes on a client's GA4 offline events before you report on them, request a free tracking check and we will tell you where the chain breaks.