Marketo Form Events & Redirection

erikwagner
Level 1

Marketo Form Events & Redirection

We recently launched a new product trial that captures lead information using a Marketo form and then redirects to the product for activation. We want to be able to track conversions in GA, LinkedIn, etc, so I need to decorate the form to capture the submission event.

 

Below is the code that we're using on our test page. Right now, it doesn't appear to work -- it just hangs on submission in perpetuity and no events are sent. Are we doing something wrong? My developer thinks it's something with GTM?

 

<script src="//app-ab43.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_1040"></form>
<script>
 MktoForms2.loadForm("//app-ab43.marketo.com", "290-OJT-747", 1040, function(form) {
    form.addHiddenFields({ previousURI: document.location.href })
    form.onSuccess((values) => {
       window.ga('send', {
        hitType: 'event',
        eventCategory: 'marketo',
        eventAction: 'form-fill',
        eventLabel: 'trialform',
        hitCallback: function(values) {
         document.location.href = `https://monitor.onclusive.com/wait_invite?email=${encodeURIComponent(values.Email)}`;
        }
      });
      return false;
     });
  });
</script>
Tags (1)
1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo Form Events & Redirection

Well, first off, the code you currently have isn't the same as what you posted.  Right now, you have

<script>
setTimeout(() => {
console.log('ga', ga);
ga('send', {
        hitType: 'event',
        eventCategory: 'marketo',
        eventAction: 'form-fill',
        eventLabel: 'trialform'
      });
ga('send', 'pageview', 'virtual page test');

}, 3000)
 MktoForms2.loadForm("//app-ab43.marketo.com", "290-OJT-747", 1040, function(form) {
    form.addHiddenFields({ previousURI: document.location.href })


    form.onSuccess((values) => {
      
      return false;
     });
  });
</script>

 

This code has multiple problems. 

 

First, compatibility. Backticks do not work in any version of IE. Neither do arrow functions. So that code isn't acceptable on a demand gen form — it needs to use standard string concatenation and functions.

 

Next, it has a race condition. Arbitrarily waiting for 3 seconds for ga to exist won't cut it, you have to actually use the event model to trigger only when the global object is available. 

 

(EDIT: I see you've changed the page yet again, this isn't going to be workable if the code keeps changing...)