Marketo Form Event Listener
How to track Marketo Form Submissions with google tag manager
Measure Marketo form submissions as conversion in your ads platform and your analytics tools (Google Analytics, Heap, Piwik Pro, Mixpanel, Amplitude, etc.)
To implement the conversion tracking, you’ll need Google Tag Manager and the Marketo form event listener javascript code.
To begin, create a custom HTML tag where you’ll paste the event listener code and fire it on pageview or DOM ready (always recommended).
The next step in this implementation is to create a custom event with the event name of [marketo_form_submission], which gets fired on all Marketo form submissions.
To capture the Marketo form ID, you’ll create a dataLayer variable with the key [formID]
The Last, step is to create your marketing tag/pixels, add the appropriate trigger and the event parameters you need for analysis.
<script type="text/javascript"> var pollFormElementsIntervalId; function pollFormElements() { var a = document.querySelectorAll("form[id^='mktoForm_']"); if (a instanceof NodeList) { clearInterval(pollFormElementsIntervalId); for (var b = 0; b < a.length; b++) attachEventListener(a[b]) } } function attachEventListener(a) { a.addEventListener("submit", function(b) { setTimeout(function() { var c = 0 === a.querySelectorAll(".mktoInvalid").length; c && window.dataLayer.push({ event: "marketo_form_submission", formID: a.id }) }, 100) }) } pollFormElementsIntervalId = setInterval(pollFormElements, 500); </script>