Trigger the Popup programmatically

If you're using a popup widget you can programmatically open the modal after a user action

This code is an example of how to use the Viral Loops Javascript SDK to open a Viral Loops campaign modal based on a URL parameter.

<form-widget mode="popup"></form-widget>


<script>
// Async function to check if should open Viral Loops campaign modal
async function checkIfShouldOpenModal() {
  // Get campaign by ID
  const campaign = await ViralLoops.getCampaign("your-campaign-id");

  // Check if URL includes thank you parameter
  const urlParams = new URLSearchParams(window.location.search);
  const thankYouParam = urlParams.get("thankyou");
  if (thankYouParam === "true") {
    campaign.openModal();
  }
}

checkIfShouldOpenModal();
</script>

๐Ÿ“˜

If you'd like to have a custom button trigger the popup, you can follow the instructions in the Popup Form Widget Installation