How to pass a signed-in user's email as a URL parameter to an external link in Memberstack?

Post author
Harry Strick

is there a way to catch the email of a signed in user to be on the end of an external link? e.g. site.com/page?[useremail]

Comments

3 comments

  • Comment author
    Chukwudi

    Hi Harry,

    You can achieve that with some Javascript code. Here's a sample that should get that done:

    <script>
    document.addEventListener("DOMContentLoaded", function () {
      window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
        if (member && member.auth && member.auth.email) {
          const userEmail = encodeURIComponent(member.auth.email); // URL-safe
          const externalLink = `https://site.com/page?useremail=${userEmail}`;
          
          // Update the link href dynamically
          const linkElement = document.querySelector("#external-link"); // replace with your link selector
          if (linkElement) {
            linkElement.href = externalLink;
          }
    
          // Optional: automatically redirect the user
          // window.location.href = externalLink;
    
          console.log("User-specific link:", externalLink);
        }
      }).catch(err => console.error("Error fetching Memberstack member:", err));
    });
    </script>
    
    
    
    <a id="external-link" href="#">Go to page</a>
    
    0
  • Comment author
    A J

    Hey Harry Strick, the above code should help you achieve your use-case.
    And if you want to prefill a form with the URL parameter value, you can check this memberscript out.

    0
  • Comment author
    Harry Strick

    would it be possible to do this for a stripe payment link? to automatically enter the user email in the email section (the memberstack native stripe integration doesn't work for multiple subscriptions, trying to find a workaround.

    memberstack does not support multiple subscriptions of the same plan, it only allows one

    if we sell a productized service where, for example, someone can add more than 1 site to the same plan, we need to be able to accept payments, for the CMS collection we can sort via automations, but the only way it seems to allow multiple subscriptions from the same product is via payment link, which is why i'd like to collect the user email

    thanks so much for your help 🙂 tbh i'd love to pay for a consultant/dev if anyone is available for hire

    0

Please sign in to leave a comment.