Hi All,
Our web developers have asked me to insert a script into a form button, on click event. It relates to a data layer regarding GA and tracking.
This is the code:
onclick="dataLayer.push({ 'car_enquiry_type': "'" +vehicleIntendedFor.value+"'" });"
Can this be done and if so where would it be inserted?
Thanks
Matt
Do you actually have a form button as an element other than the Submit button?
Where in the form flow is this supposed to happen? (Hint: is it supposed to be after the form is successfully submitted?)
Hi Mate,
From what I understand, we use marketo forms and the css is modified to accommodate our brand. This is supposed to fire after form submit.
Im wondering if it can be added to the CSS code somehow.
Not sure pondering....
What they probably want is:
MktoForms2.whenReady(function(form){
form.onSubmit(function(form){
dataLayer.push({ car_enquiry_type : "'" + form.getValues().vehicleIntendedFor + "'" });
});
});
Should be aware that if you end up using the Forms 2.0 API in other ways, you'll need to consolidate your custom code in one place.
Mate your a star. I'll run it by them and see if it works. '
I defiantly owe you many beers.
Thanks
Matt
No prob.
Hi Sanford, just a quick one.
Where do you insert the code into a form if there is no associated landing page?
edit: I guessing that we use the embed form function, add the code and supply to the web developer?
Like this:
<script src="//app-sn01.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_1038"></form>
<script>MktoForms2.loadForm("//app-sn01.marketo.com", "413-YFR-526", 1038);</script>
MktoForms2.whenReady(function(form){
form.onSubmit(function(form){
dataLayer.push({ car_enquiry_type : "'" + form.getValues().vehicleIntendedFor + "'" });
});
});
Unless there is another way.
Thanks
With an embedded form, just wrap in
<SCRIPT>
MktoForms2.whenReady...
</SCRIPT>
actually the same way you would with a landing page HTML snippet.
I use whenReady because it works in both environments.