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...)
... View more