Skip to main content

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_lead from 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 _ga cookie, so the lead is still credited to the visit's traffic source. When there is no _ga cookie, 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 same event_id as the lead and is not a second lead. (A generate_lead sent 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 example G-ABC123XYZ.
  • Measurement Protocol API secret: a secret you create for the web data stream.

Both are on the same page in GA4:

  1. In Google Analytics, open Admin.
  2. Under Data collection and modification, open Data streams and choose your website's web stream.
  3. The Measurement ID is at the top of the stream page. Copy it.
  4. 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​

  1. In Studio, open the app (location) and go to Integrations.
  2. Click Add Integration and choose Google Analytics 4.
  3. In Google Analytics 4 Setup, enter the Measurement ID. It must start with G-; a UA-, AW- or GTM- ID won't be accepted.
  4. Enter the API Secret.
  5. 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.

ParameterWhat it holds
lead_idThe lead's id in XAPP AI
event_idAn id for the lead's events, shared with lead_details
lead_sourceWhere it was captured: form-widget, chat-widget or another lead channel
form_placementFor form leads, how the form was opened: side_button, site_button, embedded, auto_open or hosted_page
page_locationThe page the lead was captured on, with only campaign parameters kept (utm_*, gclid, gbraid, wbraid, dclid, fbclid, msclkid)
page_referrerThe page the visitor came from, trimmed the same way
location_idThe app (location) id
location_nameThe app (location) name
session_idThe 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:

ParameterWhat it holds
contact_typeThe kind of contact the AI identified
service_typeThe service asked for
job_typeThe kind of job
urgencyHow urgent the request is
high_value_leadtrue 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:

  1. In Google Analytics, open Admin.
  2. Under Data display, open Events. generate_lead appears here after the first lead is received (this can take up to a day).
  3. In the generate_lead row, 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:

  1. Open Tag Assistant, connect it to your website, and leave that window open.
  2. In the Tag Assistant window, submit a test lead through your form widget.
  3. In DebugView, choose that device. generate_lead appears 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.