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



Show first post

28 replies

My co-worker also figured the window.ub.form.url part that can let you change the form action URL without messing things up which is pretty neat. I’ve yet to see if this flow is good enough but I still worry if I’m tapping into a private API that Unbounce would change tomorrow and end up breaking the scripts.

This, combined with the async hooks could be the nail in the coffin for my woes but it’s quite horrible that these are all undocumented and you have to find it in the community forums.

@Noah or anyone else from the UB team, please pass this feedback and provide a good documentation for all the exposed global APIs we can use from client-side.

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.

Reply