Install widget on a thank you page

Ensure the following:

  1. Disable redirection for the form.
  2. The redirection link must be from the same domain as the form page.

There are two parts to the setup:

  1. Installing the script on the form page.
  2. Installing the script on the thank you page.

On the form page

  1. Paste this script after your form.
<script>

 //Replace formID with your form's ID
 document.querySelector("#formID").addEventListener("submit", (e) => {

  // Collect form field values
  const rhSubmitData = Object.fromEntries(new FormData(e.target).entries());

  // Store data in localstorage because page is going to redirect. Replace routerID.

  localStorage.setItem('rhdata', JSON.stringify(rhSubmitData));
  localStorage.setItem('rhid', 'routerID');

  //Set redirection link to thank you page. Replace with your URL.
  window.location.href = "https://redirect.com";

});
</script>

  1. Replace the following in the aformentioned script:
Find in snippetReplace with
formIDyour form’s ID
routerIDyour router’s ID
redirect.comyour thank-you page URL

On the thank you page

  1. Paste this script in your page’s <body>.

<script type="text/javascript" src="https://app.revenuehero.io/scheduler.min.js"></script>
<script>

//retrieve the data from local storage
var revdata = localStorage.getItem('rhdata');
	if(revdata !== null) {
	var jsonData = JSON.parse(revdata);

//pass the data to RevenueHero and call the scheduler

 	 window.hero = new RevenueHero({ routerId: localStorage.getItem("rhid") })
  	 hero.submit(jsonData).then(function(sessionData) {
     hero.dialog.open(sessionData);

//delete the data from local storage
     localStorage.removeItem("rhdata");
     localStorage.removeItem("rhid");
  });
}
</script>

  1. You’re all set!