[How to] Run Custom Code/Scripts on Form Submission



Show first post

28 replies

Not sure about the data layer question - it’s just an array of stuff i can push into and it resets on every page load.

But in effect i set up the workflow as follows:

  1. Tag 1: Above script runs on all pages. So both functions get registered with the unbounce hooks.
  2. New Trigger: Custom event: ub-form-success
  3. New data layer variables for fields i care about e.g email => {{Form Submission - Email}} which references the key i set up on the datalayer => ‘form-email’
  4. Tag 2: Triggered on ‘ub-form-success’ and the script just constructs the event properties I need to send to our cdp. afterFormSubmit runs before the page reloads / is redirected so I have enough time to grab what i need from datalayer and send over.

But yeah, :+3: for documentation comment

Hey @Richard_Makara , was wondering if you think I could use your method here to solve my problem

I’m don’t come from a coding background so would love to hear your thoughts.

Badge +1

Hi all,

This line is not compatible with Smart Builder:

var email = args.formElement.querySelector('input#email');

Replace it with this one to use on both Classic and Smart Builder pages:

var email = document.querySelector('input#email, input#emailField'); 

 

Reply