Skip to main content

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.

marketob2bcrmformsgtmga4lead-generationmarketing-automation

Event fired

marketo_form_submission

Key variable

formID

Marketo 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

html
<!-- 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

json
{
  "event": "marketo_form_submission",
  "formID": "1234"
}

Trigger Configuration

Trigger Type: Custom Event Event Name: marketo_form_submission

Variables to Capture

Variable NameDL KeyExample
DLV – Marketo Form IDformID"1234"

GA4 Mapping

GA4 EventParameterValue
generate_leadform_idDLV – Marketo Form ID
generate_leadmethod"marketo"

Debugging

ProblemCauseFix
No event firingMarketo form loads after 10s timeoutIncrease timeout in script
Fires on validation errorhasErrors check bypassedCheck CSS class for your Marketo version

Best Practices

  1. Test with Marketo's MktoForms2.whenReady() API as an alternative approach
  2. Use the Marketo form ID (numeric) for Google Ads conversion labels
  3. Coordinate with the Marketo admin to understand which forms map to which campaigns

Related Listeners