Marketo Form GTM Event Listener
Track Marketo form submissions in Google Tag Manager. Capture the Marketo form ID and fire GA4 events, Google Ads conversions, and Meta Pixel on marketo_form_submission.
Event fired
marketo_form_submissionKey variable
formIDMarketo Form
Overview
Marketo (Adobe Marketo Engage) is a B2B marketing automation platform. Its forms render with IDs matching the pattern mktoForm_[ID]. This listener uses polling to detect Marketo forms, attaches submit listeners, validates successful submission, and pushes a marketo_form_submission event to the dataLayer.
Event fired: marketo_form_submission
Variable: formID
Why Use This Listener
Marketo forms render asynchronously via the Marketo Forms 2.0 API. GTM's standard triggers can't reliably detect them. This listener handles async loading by polling for the form element.
Common Use Cases
- Track Marketo "Request Demo" and "Contact Sales" forms as high-intent conversions
- Fire Google Ads B2B conversion actions on Marketo form submission
- Import Marketo form leads into GA4 for multi-touch attribution
- Connect Marketo form fills to offline revenue via GA4 User ID
Installation
<!-- GTM Custom HTML Tag: Marketo Form Listener -->
<script>
(function() {
function attachMarketoListener() {
var forms = document.querySelectorAll('form[id^="mktoForm_"]');
forms.forEach(function(form) {
if (form.dataset.ddListenerAttached) return;
form.dataset.ddListenerAttached = 'true';
form.addEventListener('submit', function() {
var hasErrors = form.querySelector('.mktoError:not([style*="display: none"])');
if (!hasErrors) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'marketo_form_submission',
'formID': form.id.replace('mktoForm_', '')
});
}
});
});
}
// Poll for Marketo form
var checkInterval = setInterval(function() {
if (document.querySelector('form[id^="mktoForm_"]')) {
attachMarketoListener();
clearInterval(checkInterval);
}
}, 500);
// Stop polling after 10s
setTimeout(function() { clearInterval(checkInterval); }, 10000);
})();
</script>Fire on: All Pages (Window Loaded). Polling stops after 10 seconds.
Data Layer Output
{
"event": "marketo_form_submission",
"formID": "1234"
}Trigger Configuration
Trigger Type: Custom Event
Event Name: marketo_form_submission
Variables to Capture
| Variable Name | DL Key | Example |
|---|---|---|
| DLV – Marketo Form ID | formID | "1234" |
GA4 Mapping
| GA4 Event | Parameter | Value |
|---|---|---|
generate_lead | form_id | DLV – Marketo Form ID |
generate_lead | method | "marketo" |
Debugging
| Problem | Cause | Fix |
|---|---|---|
| No event firing | Marketo form loads after 10s timeout | Increase timeout in script |
| Fires on validation error | hasErrors check bypassed | Check CSS class for your Marketo version |
Best Practices
- Test with Marketo's
MktoForms2.whenReady()API as an alternative approach - Use the Marketo form ID (numeric) for Google Ads conversion labels
- Coordinate with the Marketo admin to understand which forms map to which campaigns