Google Analytics 4
The Google Analytics 4 integration records every lead your chat and form widgets capture as a generate_lead event in your GA4 property. GA4 credits each lead to the traffic source that brought the visitor, so you can see which campaigns, ads and pages produce leads, and use the event as a conversion.
No names, email addresses or phone numbers are sent to Google.
What it sends, and when
Each lead is sent once, after XAPP AI has read and tagged it, shortly after the lead arrives. The event is dated to when the lead was captured.
- From the page, when your Google tag is there. If your website loads the Google tag (gtag.js or Google Tag Manager) for the same GA4 property, the form widget sends
generate_leadfrom the visitor's browser the moment they submit. - From our server otherwise. Chat leads, and form leads where the Google tag isn't loaded or is blocked, are sent from our server with the Measurement Protocol. The visitor's Google Analytics ID is carried over from your site's
_gacookie, so the lead is still credited to the visit's traffic source. When there is no_gacookie, the lead is still counted but shows as Direct / Unassigned. This includes sites whose cookie banner holds back Google Analytics until the visitor accepts. - Details follow. When the AI has worked out what the lead is about, a second event,
lead_details, carries those details. It has the sameevent_idas the lead and is not a second lead. (Agenerate_leadsent from our server carries the details too; one sent from the browser can't, because it goes out before the lead is analyzed.)
Visitors whose browser sends a Global Privacy Control signal are not sent to Google. Partial leads, where the visitor didn't finish, are not sent.
Before you start
You need, from your GA4 property:
- Measurement ID: starts with
G-, for exampleG-ABC123XYZ. - Measurement Protocol API secret: a secret you create for the web data stream.
Both are on the same page in GA4:
- In Google Analytics, open Admin.
- Under Data collection and modification, open Data streams and choose your website's web stream.
- The Measurement ID is at the top of the stream page. Copy it.
- Open Measurement Protocol API secrets, click Create, give it a name such as
XAPP AI, and copy the Secret value.
Your plan must include integrations. Contact support if Google Analytics 4 isn't offered when you add an integration.
Set it up
- In Studio, open the app (location) and go to Integrations.
- Click Add Integration and choose Google Analytics 4.
- In Google Analytics 4 Setup, enter the Measurement ID. It must start with
G-; aUA-,AW-orGTM-ID won't be accepted. - Enter the API Secret.
- Click Connect. You'll see Google Analytics 4 Connected.
The API secret is stored encrypted and is never shown again. To change it, disconnect and connect again.
Several locations on one website? Enter the same Measurement ID and API secret on each location. Every event carries the page it came from and the location's name, so you can report by page, landing page or location.
Events and parameters
generate_lead
Sent once for every lead.
| Parameter | What it holds |
|---|---|
lead_id | The lead's id in XAPP AI |
event_id | An id for the lead's events, shared with lead_details |
lead_source | Where it was captured: form-widget, chat-widget or another lead channel |
form_placement | For form leads, how the form was opened: side_button, site_button, embedded, auto_open or hosted_page |
page_location | The page the lead was captured on, with only campaign parameters kept (utm_*, gclid, gbraid, wbraid, dclid, fbclid, msclkid) |
page_referrer | The page the visitor came from, trimmed the same way |
location_id | The app (location) id |
location_name | The app (location) name |
session_id | The visitor's GA4 session, when known. For chat leads this is how the lead is credited to the visit's traffic source. |
lead_details
Sent when the lead has been analyzed, with all the generate_lead parameters above plus whichever of these the analysis produced:
| Parameter | What it holds |
|---|---|
contact_type | The kind of contact the AI identified |
service_type | The service asked for |
job_type | The kind of job |
urgency | How urgent the request is |
high_value_lead | true or false, from your high-value lead settings |
No monetary value or currency is sent.
To report on a parameter such as form_placement or location_name, register it in GA4 as a custom dimension: Admin > Data display > Custom definitions > Create custom dimension, scope Event, with the parameter name exactly as above.
Mark the lead as a key event
GA4 counts an event as a conversion once you mark it as a key event:
- In Google Analytics, open Admin.
- Under Data display, open Events.
generate_leadappears here after the first lead is received (this can take up to a day). - In the
generate_leadrow, turn on Mark as key event.
You don't have to wait for the first lead: under Data display > Key events, click New key event and enter generate_lead.
Mark only generate_lead. Don't mark lead_details: it describes the same lead and would count it twice.
Check that it works
Realtime. Submit a test lead through your form or chat widget, then open Reports > Realtime in GA4. generate_lead shows under Event count by Event name shortly after the lead appears in Studio.
DebugView. DebugView (Admin > Data display > DebugView) shows events only from a browser in debug mode:
- Open Tag Assistant, connect it to your website, and leave that window open.
- In the Tag Assistant window, submit a test lead through your form widget.
- In DebugView, choose that device.
generate_leadappears with its parameters when your page loads the Google tag for this property, because then the browser sends it.
Events sent from our server, which is every chat lead, every lead_details and form leads on pages without the Google tag, don't carry the debug flag, so they don't appear in DebugView. Check those in Realtime, or in your reports the next day.
Nothing arrives? Check the Measurement ID matches the property you're looking at. Google accepts events sent with a wrong API secret without an error and then drops them, so if form leads appear but chat leads don't, create a new API secret and reconnect.