Refactoring Crisp Code to MS2.0 Answered

Post author
John Matias

Hey team can I get a little help refactoring this code for MS2.0?

<script>
MemberStack.onReady.then(function(member) {
    var email = member["email"]
    var name = member["name"]
    if (member.loggedIn) {
      try{
        $crisp.push(["set", "user:email", [email] ])
        $crisp.push(["set", "user:nickname", [name] ])
        profitwell('start', { 'user_email': email });
      } catch(e) {
    }
  }
})
</script>

Comments

3 comments

  • Comment author
    Josh Lopez

    try this:

    window.$memberstackDom.getCurrentMember().then((member) => {
      if (member.data) {
        // do logged in logic here
        const email = member.data.auth.email;
        const name = member.data.customFields["name"];
        try {
          $crisp.push(["set", "user:email", [email]])
          $crisp.push(["set", "user:nickname", [name]])
          profitwell('start', { 'user_email': email });
        } catch (e) {
          console.log(e);
        };
      } else {
        // do logged out logic here
      }
    })
    
    0
  • Comment author
    John Matias

    Thanks, Josh! I'll give it a try.

    0
  • Comment author
    Zack Hakim

    Josh-Lopez

    any chance you can change this to MS 2.0 code?

     

     

    <script>
    MemberStack.onReady.then(function(member) {
    var url = member["profile-url"]
    var els = Array.from(document.querySelectorAll("[profile-url]"))
    for (var el of els) {
    el.href = url
    }
    })
    </script>

    0

Please sign in to leave a comment.