How to maintain page redirect functionality while still showing the welcome modal after signup? Answered

Post author
Asaiah Lewis

I implemented the ability for users to get redirected to the same page they signed up on (super cool, thanks for the guide!) But I also want to use the signup welcome modal, but the redirect code & required /?welcome parameter don't work together. Any workarounds?

Comments

8 comments

  • Comment author
    Shane Gauthier

    Hi Asaiah, can you be more specific? Maybe share a Loom of what you are trying to do? Trying to understand exactly what you are trying to implement.

    1
  • Comment author
    Asaiah Lewis

    Hi,

    The code from this guide allows users to stay on the same page they sign up on, instead of redirected. (You create an empty success page & set up memberstack to direct you here & then the custom code will take you back the orgin page). It works great.

    But I also want to use this guide that allows new users to see a welcome modal upon sign up. You have to set a redirect in memberstack with the specific parameter (?welcome). And the custom code you set will check the url for the (?welcome) parameter & only then will display the modal. 

    My issue is that since the first guide redirects you back to your page of orgin, I'm not able to append the (?welcome) parameter to the final redirect. 

    I'm thinking there may be a way to append url parameters in the custom code redirect execution, but I'm no coder.

    Does that make sense?

    1
  • Comment author
    Shane Gauthier
    <script>

    // Get the current URL
    var currentUrl = window.location.href;

    // Append "?welcome" to it
    var updatedUrl = currentUrl + '?welcome';

    // Store the updated URL in localStorage
    localStorage.setItem('locat', updatedUrl);

    </script>


    Try this code above instead of 

    <script>
    // sets the url of the page you're on for redirecting back to it
    localStorage.setItem('locat', location.href);
    </script>


    remember this goes into the Global Site Footer.

    If that doesn't work, get back to me and I will take a deeper look.

    1
  • Comment author
    Asaiah Lewis
    • Edited

    Thank you so much Shane! That code did work (for future buillders, use '?welcome=true'. Forgot to write that down from the demo)

    Do you think there's a way to run this script with two different success pages I set up? Eg. One success page for sign ups that redirects the ?welcome=true & then a 2nd success page for logins that leaves out the ?welcome=true.

    The ?welcome=true is now making the modal pop up for both new users & returning logins.

    0
  • Comment author
    Shane Gauthier

    Yes we could look for a local storage that Memberstack is placing.

    Try this script and see if it works!

    <script>

    // Check if the local storage item 'ms_groups' is not found
    if (localStorage.getItem('ms_groups') === null) {

        // Get the current URL
        var currentUrl = window.location.href;

        // Append "?welcome" to it
        var updatedUrl = currentUrl + '?welcome';

        // Store the updated URL in localStorage
        localStorage.setItem('locat', updatedUrl);

    }

    </script>
    0
  • Comment author
    Shane Gauthier

    This should only run for people who HAVE NOT already signed up.

    0
  • Comment author
    Asaiah Lewis

    Hmm, I understand the local storage concept. But when i replaced to this code, it just redirects me to the home page for both logins & signups. Also, in both instances, Append isn't happening when i look at URL.

    And even if this did work as intended, how would this script identify existing users, now? Would I use both scripts? But if so, wouldn't the 1st script would still apply to both logins & signups.

     In Memberstack, I still have both redirects set to the same success page since there's only one script.

    The header code i have on the success page:

    <script> // redirects back to the page you were just on window.location = localStorage.getItem('locat'); </script>

     

    0
  • Comment author
    Duncan from Memberstack
    • Edited

    🎉 Good news!

    You can now use the attribute data-ms-redirect="current-url" to save the current URL. The next time that visitor goes to sign up or login they will be returned to the page. 

    Here's the full help center article.

    0

Please sign in to leave a comment.