Hope that someone can help me with this. I’m no experienced coder. Client wants to add the following code:
dataLayer.push({“event”: “FormSubmit”});
after successful submitting. I’ve found “Custom” action, but can’t find a way to implement the code. It’s pretty urgent so any help is greatly appreciated.
The bricks/form/custom_action is only able to act on information from the server side after the form is submitted. Javascript won’t work here. What you probably want to do is add your javascript like this to the footer of your page. Or at least in a code block below your form:
(function() {
// put your form element id below
var form = document.getElementById("brxe-mysvdb");
form.onsubmit = function() {
dataLayer.push({"event": "FormSubmit"});
};
})();
@cmstew In Contact Form 7, I use the following code to track the form submit event, I don’t know how to set it in Bricks Form, can you please help to fix this code? Thank you very much!
(function() {
document.querySelectorAll('.brxe-form').forEach(function(form){
form.onsubmit = function(){
dataLayer.push({
'event' : 'brickssuccessfulsubmit',
// Correction: This line had a semi-colon by accident instead of a comma
'Leads-formID' : form.dataset.elementId,
});
};
});
// Correction: This last line was missing before
})();