Automatically Open Form When The App Launches

Open the Formyoula setup page and scroll to Mobile Footer - https://app.formyoula.com/setup/account

image

Add the following JavaScript inside the Mobile Footer HTML.

<script>
// Function to launch the form
function open_form(form_id) {
  // Open a new form entry based on the form template id
  formyoula.event_trigger('form:open:new', { form_id: form_id });
}
// Open a form based on the form template id
open_form('609bdde9b4d9ec0020dfb184');
</script>
image

We can also update each user custom attributes to open specific forms for each user.

// Open a new form by providing the form Id
function open_form(form_id) {
  // Check if form_id is provided
  if (!form_id) return;
  // Open new one
  formyoula.event_trigger('form:open:new', { form_id: form_id });
}
// Wait for 3 seconds
setTimeout(function () {
  // Check if localStaorage is set
  if (localStorage.auto_open_form_id) {
    // Open a new form by providing the form Id
    open_form(localStorage.auto_open_form_id);
    // Check if user custom attributes are available
  } else if (window.formyoula.user && window.formyoula.user.Formyoula_User_Attributes) {
    // Set localStorage
    localStorage.auto_open_form_id = window.formyoula.user.Formyoula_User_Attributes.form_id;
    // Open a new form by providing the form Id
    open_form(window.formyoula.user.Formyoula_User_Attributes.form_id);
  }
}, 3000);

For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂