Unbounce Form GTM Event Listener
Track Unbounce landing page form submissions in Google Tag Manager. Capture form ID, email, name, and phone with pre and post-submit events.
unbouncelanding-pageformsgtmga4ppclead-generation
Unbounce Form
Overview
Unbounce is a landing page builder used heavily in PPC campaigns. It exposes two hooks: window.ub.hooks.beforeFormSubmit (fires before submission with full field data) and window.ub.hooks.afterFormSubmit (fires after confirmed success). This listener uses both hooks to push comprehensive lead data to the GTM dataLayer.
Events fired:
unbounce-form-submission, fires before success with field data (email, name, phone)ub-form-success, fires after confirmed successful submission (use as conversion trigger)
Credit: Richard Makara (RECONFIGURED CEO)
Why Use This Listener
Two-event tracking is powerful:
unbounce-form-submissiongives you field-level data (email, name) for Enhanced Conversions, even before the form fully processesub-form-successis the clean conversion trigger, fire your pixels here
Common Use Cases
- Track PPC landing page conversions
- Capture hashed email for Google Enhanced Conversions
- Fire Meta
Leadevent on form success - Differentiate by form ID when multiple forms exist on a page
Installation
html
<!-- GTM Custom HTML Tag: Unbounce Form Listener -->
<script>
window.ub.hooks.beforeFormSubmit.push(function(args) {
var email = args.formElement.querySelector('input#email');
var name = args.formElement.querySelector('input#name');
var firstName = args.formElement.querySelector('input#first_name');
var lastName = args.formElement.querySelector('input#last_name');
var phoneNumber = args.formElement.querySelector('input#phone_number');
var formId = args.formElement.id;
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'unbounce-form-submission',
'form-id': formId,
'form-email': email ? email.value : '',
'form-name-field': name ? name.value : '',
'form-firstname-field': firstName ? firstName.value : '',
'form-lastname-field': lastName ? lastName.value : '',
'form-phonenumber-field': phoneNumber ? phoneNumber.value : ''
});
});
window.ub.hooks.afterFormSubmit.push(function() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'ub-form-success'
});
});
</script>Fire on: DOM Ready.
Data Layer Output
Pre-Submit (Field Data)
json
{
"event": "unbounce-form-submission",
"form-id": "lp-form-1",
"form-email": "lead@example.com",
"form-name-field": "Jane Smith",
"form-phonenumber-field": "+1234567890"
}Post-Submit (Conversion Signal)
json
{
"event": "ub-form-success"
}Triggers to Create
| Trigger | Event Name | Use For |
|---|---|---|
| CE – Unbounce Pre-Submit | unbounce-form-submission | Capture field data |
| CE – Unbounce Success | ub-form-success | GA4, Google Ads, Meta |
Variables to Capture
| Variable Name | DL Key | Example |
|---|---|---|
| DLV – UB Form ID | form-id | "lp-form-1" |
| DLV – UB Email | form-email | "lead@example.com" |
| DLV – UB First Name | form-firstname-field | "Jane" |
| DLV – UB Phone | form-phonenumber-field | "+1234567890" |
GA4 Mapping
| GA4 Event | Trigger | Parameters |
|---|---|---|
generate_lead | Unbounce Success | form_id, method: "unbounce" |
| Enhanced Conversions | Pre-Submit | email, phone, first_name |
Debugging
| Problem | Cause | Fix |
|---|---|---|
ub is not defined | Unbounce script not loaded | Fire on Window Loaded |
| Field values empty | Field IDs differ | Inspect Unbounce form HTML for actual input IDs |
Best Practices
- Always use
ub-form-successfor conversion counting, pre-submit may have abandons - For privacy compliance, add consent conditions before the PII push
- Input IDs (
#email,#name) vary by Unbounce template, inspect and adjust