Automatically trigger the popup

Sometimes you want the popup to open automatically on the landing page of your campaign, without the users clicking a button to trigger it. 


That's easy to accomplish: You just have to add the following piece of JS code on the landing page of your campaign (or in all the pages where you want your campaign to live in). Make sure to add this code after the Viral Loops campaign javascript snippet. 

<script>
window.addEventListener('vl_ready', function(e) {
  VL.openModal();
}, false)
</script>

What this does is it waits until the JavaScript of the popup has loaded completely and then fires the VL.openModal() function that opens the popup.


Also, if you still want the popup to open automatically, but you want this to happen after a certain period of time, let's say after 1 second (1000 milliseconds), then you'll have to use the following script:


<script>
window.addEventListener('vl_ready', function(e) {
   setTimeout(function() {
       VL.openModal();
   }, 1000);
}, false);
</script>

Triggering the popup for participants coming from welcome and booster emails 

The welcome and booster emails that your participants receive as part of your campaign contain a button that takes the participant back to the landing page of the campaign where they have to open the popup again and invite their friends.

If you want the popup to open automatically in those cases you can add the following script in your page:

<script>
window.addEventListener("vl_ready", function() {
    function getQueryString(field, url) {
        var href = url ? url : window.location.href;
        var reg = new RegExp("[?&]" + field + "=([^&#]*)", "i");
        var string = reg.exec(href);
        return string ? decodeURIComponent(string[1]) : null;
    }
    if (getQueryString("userCode")) {
        VL.openModal();  
    }
});
</script>

This will open the popup automatically for participants coming from welcome and booster emails (not invite emails though).

We are planning some updates that will open the popup automatically for participants who come from welcome, booster and invite emails but until then you could use the above workaround.


Automatic participation

If you would also like the participant to join automatically when they visit the page, then direct them there using a URL in the form of:

https://www.your-website.com/?firstname=Dimitris&email=dimitris@viral-loops.com&autoTrigger=1&autoDetect=1

Make sure to include the firstname and email parameters in the URL. The Viral Loops javascript snippet will capture these from the URL and add the participant to the campaign. 

  • autoTrigger=1 will automatically trigger the popup after participation (optional)
  • autoDetect=1 will automatically subscribe the participant to the campaign. Don't remove this.

Did this article help you? Let us know! 🙂

Did this answer your question?